✅ Online Database: How To Use?
I normally (and always have) use SQLite(C#) and SQLite3(Python) and I have a function in my
app.axaml.cs
or main.py
file that checks if the database exists in the server folder and if not then create it and it's there in the server folder for the application to use when it needs. I've been listening to a couple of different programming podcast, and I'm feeling the urge to start the migration to online databases like MongoDB etc. My only problem is:
1. I don't know anything about them, including but not limited to how to use them
2. What is the best one, or at least top 3 I should look at (free please)
The other major part that confuses me that goes along with the how to use them
part; When using an online database, do you just have one database, and then all of your applications/websites/mobile apps server side all query the same database and just uses trigger words to dictate to the database on what to do with the information? I mean I could create an engine that does that based off trigger words, but I'd rather not lol I'm hoping that you create a new database for each application, but yea. I'm thinking about migrating and I thought best to ask here first. Thanks.66 Replies
Why are you feeling that urge
The databases you're describing can still run on your server, they just run as their own process
You can have them hosted/managed by a cloud provider like Azure or AWS, but that's going to cost money
I'm wanting to learn some cloud computing. Like when the user exits the application, it takes all of the information the user has, or will have, entered and saved and then upload it to the database (which is in the cloud?) and I can stop having to deal with a physical database.
Sure, you can go buy a $5/mo MS SQL database from Azure, but you'll likely find not a whole lot of difference between that and your current SQLite solution, at least from your code's perspective
You'll basically be changing a connection string and modifying any queries that are supported by one database but not the other
Don't get me wrong, as your app scales you'll certainly want to have a dedicated database instead of SQLite
But the only differences will be where that database is running and which database it is, whether you go with MS SQL or Postgres or something else
Although you mentioned MongoDB, which is an entirely different kind of database
So in that case there would be a significant difference in how your data is actually represented, but you probably don't need MongoDB
I'm not really sure. I just wanted to learn how to take what a user has done within the application and then post it to cloud storage? (or an online database) and that way I can have a little saving loading screen and then the application closes, or can also have it store to a local database if there is no internet connection and then when there is internet connection again and the user opens the application, then it can transfer the latest information to the online database (or cloud storage?) while the user uses the app
Again, the only difference between a cloud database and what you have now is a different connection string and database provider
it's for the purpose of if the user ever uninstalls the app, or changes computers, they can log back into the application and continue with their latest saved information
Having a local database to save to if there's no connection and then synchronizing it is certainly a worthwhile project
But there are a lot of considerations with that
oh?
That sounds like a good use case
So 1. understand that the process of "send a query to a database" doesn't change much if the database is hosted elsewhere and 2. no one is going to host a database for you for free
For cheap, yes, but not for free
Although you also need to consider the security implications of having an application you release to users directly access your database
Realistically you'll probably want a web API that they make authenticate to and make requests to and then that web API queries the database
do you have any suggestions?
this sounds like a good idea do you know of one?
Azure has like a $5 MS SQL offering
The one you write
i.e. make an ASP.NET Core app
not avalonia?
isn't avalonia for native apps
I thought they were cross-platform? I'm writing desktop applications primarily but my quesiton also applies to building my own website too but that's another language at another date
native as in it runs on the user's device as a desktop/mobile application
not a web application
ASP.NET Core is for building web applications
e.g. a REST API that your desktop application talks to
right. The website will be at a later date and I'll be using JS with FastAPI to build that
you can use FastAPI for this too
I just suggested ASP.NET Core because that's what I use and it's the C# server
But yeah, you can use whatever you want to build the web API
oh. ok. so to do what I'm wanting to do actually goes beyond just a change in database language. It's also learning that databases language, then learning authentication and cookies lol what else am I missing xD
Well the good news is it'll still be SQL
There just might be feature differences between databases. AFAIK if you're going from sqlite to something like sql server you shouldn't run into anything that's unsupported?
But yeah, your app's entire architecture is changing now
sqlite has very few features compared to server-based relational databases
oh lovely xD I wonder if I just don't make it like I normally do with a physical server that's created on run time, and then have a File > Export As option in the menu bar and they can export it in various formats to somewhere on their computer
... server-based relational databasesI've been listening to this podcast series on Talk Python To Me and they do a lot of
"relational vs something else"
databases and I'm so confused on what that means
given the context of your entire message, I believe I'm safe in assuming that relational = physical database in the server folder of the applicationrelational and non-relational has to do with how the data is represented and stored
SQLite and other SQL databases are relational, whereas MongoDB is not
I'd google around though, I couldn't tell you the details
oh that just lead me to another question. With the databases being created on runtime and stored locally on the users system, if they ever go into the files of the application, they'll see the
main.db
file in there and if they're a programmer, then they'll be able to open that sucker up in the a database viewer lol how do I prevent thatstore the database somewhere else
like
🥁
the cloud
where "the cloud" is just another computer that you control
that would mean port forwarding and such for my desktop
and you leaving your desktop on 24/7 for your users to access
which is why you should pay a cloud provider
yea I don't wanna do that
if you're a student you can get free azure credits
right. I'll just have to wait for that. I'm broke lol
I am a student
students get tons of free shit
look into the github student pack
you can also get a $5 VPS from linode and run whatever you want on it
Oracle cloud has a free tier
I dunno lol this looks all official and shit haha I mean yea, I'm a student. I go to the University of Phoenix online for Computer Science focusing in Cyber Security and Software Development lol
if you have a .edu email or some other documentation that you're a student you should be able to get it
I have a .edu
worst case cheap VPSes are like 5 bucks a month
and you can run anything you want on them
I don't know what those are sadly
a cloud virtual machine
if you google VPS it will tell you :when:
If you want an absolutly free option, use a free oracle cloud vps with supabase/firebase database
i'll def look into it
stupid question. If I write my database stuff in a python file, can I use it in C# code?
what is "stuff"
and why would you do it in python instead of C#?
because I use python for my back ends on websites that I doodle around with. Idk. I don't know how to do a backend stuff in any other language. I know how to work with a relative database in C# but that's about it and that's a struggle sometimes.
python interop will probably be more painful than just doing it in C#
unless you do a python backend and c# frontend
this is what I meant. My fault. I'm likely doing a FastAPI for the backend so I'll be doing my database stuff in python, but is it a pain to call a python function into a c# class?
well nevermind that.
It would be done through an api call in c#
I'm not entirely sure on how to google this, but I'm wanting to get the first and last name on the same string as one returned item. I can't remember how to do it but I think it's something like
?
ah tyvm
what if I'm wanting to call one model inside of another? like
What do you mean call one model inside another?
so like would it be
and then when I call the StudentModel in other code, I'll get both parent information and the list of approved alternate adults to pick the child up, right?
more specifically when I map data that is returned from the database when that screen loads
I would just pass the
ParentModel
s to the StudentModel
via the constructorhow do you mean?
the common link between the two is that both the parents id's will also match the students id number so that they can be called off the same value
i think the confusion is "calling" means something very specific
as in calling a method
ok my fault. wrong terms
I'm not understanding what I'm doing wrong
You didn't close the scope of your constructor, you're missing
}
as the IDE showedalternatively, you did but you tried to declare properties inside the constructor which isn't valid
oh ok so it's supposed to be like this I believe. Also, question. When I call the student model and want to access the variables inside like
PrimaryParentOne
how would I do that with it being inside of a nested code block?you should test it and see if it works the way you expect
you shouldn't be defining variables in the constructor at all, you should be assigning values to your properties
What do you mean?
you aren't assigning these in your constructor
i'm guessing that's an error
I honestly wasn’t sure what to do with them. I’ve never done this before.
What I mean is I’ve worked with models before, but not like this
this is just how classes work, if you want to assign values to their properties you have to actually assign the properties
same as you would with fields
https://pastebin.com/Mye9JVH0
this is my current code with that model. What do I need to fix because I'm not understanding how I don't have them assigned
I thought I assigned them at the bottom
you defined them, you didn't give them any value
oh. well them um. So what's supposed to happen is when the database is queried for the student, it's going to return all of the students information which will have two parent models, a list of parent models, and two staff objects inside. When I go to display the information on the screen, I'll be calling those models to put to the values from the database. I believe what I was trying to do was to make it to where I only needed to call the student model and give it access to those models as well for display
but I don't think I need to do that anyways because I'll be calling the models in the database file anyways so I should probably just build the student model by itself
what does "calling a model" mean?
you can't call objects
this code also doesn't seem to have anything to do with a database or specific ORM, they look like plain C# classes
i would start by learning how to write normal C# classes with properties and then move on to more complex subjects like working with databases
ok thanks