C
C#10mo ago
Mekasu0124

✅ 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
mg
mg10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
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.
mg
mg10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
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
mg
mg10mo ago
Again, the only difference between a cloud database and what you have now is a different connection string and database provider
Mekasu0124
Mekasu0124OP10mo ago
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
mg
mg10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
oh?
mg
mg10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
do you have any suggestions? this sounds like a good idea do you know of one?
mg
mg10mo ago
Azure has like a $5 MS SQL offering The one you write i.e. make an ASP.NET Core app
Mekasu0124
Mekasu0124OP10mo ago
not avalonia?
mg
mg10mo ago
isn't avalonia for native apps
Mekasu0124
Mekasu0124OP10mo ago
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
mg
mg10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
right. The website will be at a later date and I'll be using JS with FastAPI to build that
mg
mg10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
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
mg
mg10mo ago
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
Jimmacle
Jimmacle10mo ago
sqlite has very few features compared to server-based relational databases
Mekasu0124
Mekasu0124OP10mo ago
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 databases
I'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 application
mg
mg10mo ago
relational 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
Mekasu0124
Mekasu0124OP10mo ago
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 that
mg
mg10mo ago
store the database somewhere else like 🥁 the cloud where "the cloud" is just another computer that you control
Mekasu0124
Mekasu0124OP10mo ago
that would mean port forwarding and such for my desktop
mg
mg10mo ago
and you leaving your desktop on 24/7 for your users to access which is why you should pay a cloud provider
Mekasu0124
Mekasu0124OP10mo ago
yea I don't wanna do that
mg
mg10mo ago
if you're a student you can get free azure credits
Mekasu0124
Mekasu0124OP10mo ago
right. I'll just have to wait for that. I'm broke lol I am a student
mg
mg10mo ago
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
Anu6is
Anu6is10mo ago
Oracle cloud has a free tier
Mekasu0124
Mekasu0124OP10mo ago
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
mg
mg10mo ago
if you have a .edu email or some other documentation that you're a student you should be able to get it
Mekasu0124
Mekasu0124OP10mo ago
I have a .edu
Jimmacle
Jimmacle10mo ago
worst case cheap VPSes are like 5 bucks a month and you can run anything you want on them
Mekasu0124
Mekasu0124OP10mo ago
I don't know what those are sadly
Jimmacle
Jimmacle10mo ago
a cloud virtual machine
mg
mg10mo ago
if you google VPS it will tell you :when:
Kouhai
Kouhai10mo ago
If you want an absolutly free option, use a free oracle cloud vps with supabase/firebase database
Mekasu0124
Mekasu0124OP10mo ago
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?
Jimmacle
Jimmacle10mo ago
what is "stuff" and why would you do it in python instead of C#?
Mekasu0124
Mekasu0124OP10mo ago
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.
Jimmacle
Jimmacle10mo ago
python interop will probably be more painful than just doing it in C# unless you do a python backend and c# frontend
Mekasu0124
Mekasu0124OP10mo ago
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
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
return $"{FirstName} {LastName}";
}
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
return $"{FirstName} {LastName}";
}
?
Kouhai
Kouhai10mo ago
public string FullName => $"{FirstName} {LastName}"
public string FullName => $"{FirstName} {LastName}"
Mekasu0124
Mekasu0124OP10mo ago
ah tyvm what if I'm wanting to call one model inside of another? like
public class Student
{
public int Id {get;set;}
...
public Parent PrimaryParentOne ________________ // primary parent like mom
public Parent PrimaryParentTwo ________________ // other primary parent like data
public Parent ApprovedPickupList<List<string, bool>> // a list of names and booleans like Glenda, True
public class Student
{
public int Id {get;set;}
...
public Parent PrimaryParentOne ________________ // primary parent like mom
public Parent PrimaryParentTwo ________________ // other primary parent like data
public Parent ApprovedPickupList<List<string, bool>> // a list of names and booleans like Glenda, True
Kouhai
Kouhai10mo ago
What do you mean call one model inside another?
Mekasu0124
Mekasu0124OP10mo ago
so like would it be
public class ParentModel {}
public class StudentModel
{
public int Id { get; set; }
...
public ParentModel PrimaryParentOne { get; set; }
public ParentModel PrimaryParentTwo { get; set; }
public List<ParentModel> ApprovedAlternatePickup { get; set;}
}
public class ParentModel {}
public class StudentModel
{
public int Id { get; set; }
...
public ParentModel PrimaryParentOne { get; set; }
public ParentModel PrimaryParentTwo { get; set; }
public List<ParentModel> ApprovedAlternatePickup { get; set;}
}
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
Kouhai
Kouhai10mo ago
I would just pass the ParentModels to the StudentModel via the constructor
Mekasu0124
Mekasu0124OP10mo ago
how 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
Kouhai
Kouhai10mo ago
public class StudentModel
{
public ParentModel PrimaryParentOne { get; }
public ParentModel PrimaryParentTwo { get; }
public StudentModel(ParentModel primaryParentOne, ParentModel primaryParentTwo)
{
PrimaryParentOne = primaryParentOne;
PrimaryParentTwo = primaryParentTwo;
}
}
public class StudentModel
{
public ParentModel PrimaryParentOne { get; }
public ParentModel PrimaryParentTwo { get; }
public StudentModel(ParentModel primaryParentOne, ParentModel primaryParentTwo)
{
PrimaryParentOne = primaryParentOne;
PrimaryParentTwo = primaryParentTwo;
}
}
Jimmacle
Jimmacle10mo ago
i think the confusion is "calling" means something very specific as in calling a method
Mekasu0124
Mekasu0124OP10mo ago
ok my fault. wrong terms
namespace GradeBook.Models;
public class StudentModel
{
public ParentModel primaryParentOne { get; }
public ParentModel primaryParentTwo { get; }
public List<ParentModel> alternatePickup { get; }

public StudentModel(
ParentModel primaryParentOne,
ParentModel primaryParentTwo,
List<ParentModel> alternatePickup)
{
ParentModel PrimaryParentOne = primaryParentOne;
ParentModel PrimaryParentTwo = primaryParentTwo;
List<ParentModel> AlternatePickup = alternatePickup; // <- expects a } here

public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string AlternateName { get; set; }
public string PhysicalAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string AlternatePhysicalAddress { get; set; }
public string AlternateCity { get; set; }
public string AlternateState { get; set; }
public string AlternateCounty { get; set; }
public string AlternateCountry { get; set; }
public string PrimaryNumber { get; set; }
public string SecondaryNumber { get; set; }
public string AlternateNumber { get; set; }
public string FullName => $"{FirstName} {MiddleName} {LastName}";
}
} // <- Type or namespace definintion, or end-of-file expected
namespace GradeBook.Models;
public class StudentModel
{
public ParentModel primaryParentOne { get; }
public ParentModel primaryParentTwo { get; }
public List<ParentModel> alternatePickup { get; }

public StudentModel(
ParentModel primaryParentOne,
ParentModel primaryParentTwo,
List<ParentModel> alternatePickup)
{
ParentModel PrimaryParentOne = primaryParentOne;
ParentModel PrimaryParentTwo = primaryParentTwo;
List<ParentModel> AlternatePickup = alternatePickup; // <- expects a } here

public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string AlternateName { get; set; }
public string PhysicalAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string AlternatePhysicalAddress { get; set; }
public string AlternateCity { get; set; }
public string AlternateState { get; set; }
public string AlternateCounty { get; set; }
public string AlternateCountry { get; set; }
public string PrimaryNumber { get; set; }
public string SecondaryNumber { get; set; }
public string AlternateNumber { get; set; }
public string FullName => $"{FirstName} {MiddleName} {LastName}";
}
} // <- Type or namespace definintion, or end-of-file expected
I'm not understanding what I'm doing wrong
Kouhai
Kouhai10mo ago
You didn't close the scope of your constructor, you're missing } as the IDE showed
Jimmacle
Jimmacle10mo ago
alternatively, you did but you tried to declare properties inside the constructor which isn't valid
Mekasu0124
Mekasu0124OP10mo ago
public class StudentModel
{
public StudentModel(ParentModel primaryParentOne, ParentModel primaryParentTwo, List<ParentModel> alternatePickup)
{
ParentModel PrimaryParentOne = primaryParentOne;
ParentModel PrimaryParentTwo = primaryParentTwo;
List<ParentModel> AlternatePickup = alternatePickup;
}

public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string AlternateName { get; set; }
public string PhysicalAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string AlternatePhysicalAddress { get; set; }
public string AlternateCity { get; set; }
public string AlternateState { get; set; }
public string AlternateCounty { get; set; }
public string AlternateCountry { get; set; }
public string PrimaryNumber { get; set; }
public string SecondaryNumber { get; set; }
public string AlternateNumber { get; set; }
public string FullName => $"{FirstName} {MiddleName} {LastName}";
public ParentModel primaryParentOne { get; }
public ParentModel primaryParentTwo { get; }
public List<ParentModel> alternatePickup { get; }
}
public class StudentModel
{
public StudentModel(ParentModel primaryParentOne, ParentModel primaryParentTwo, List<ParentModel> alternatePickup)
{
ParentModel PrimaryParentOne = primaryParentOne;
ParentModel PrimaryParentTwo = primaryParentTwo;
List<ParentModel> AlternatePickup = alternatePickup;
}

public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string AlternateName { get; set; }
public string PhysicalAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string AlternatePhysicalAddress { get; set; }
public string AlternateCity { get; set; }
public string AlternateState { get; set; }
public string AlternateCounty { get; set; }
public string AlternateCountry { get; set; }
public string PrimaryNumber { get; set; }
public string SecondaryNumber { get; set; }
public string AlternateNumber { get; set; }
public string FullName => $"{FirstName} {MiddleName} {LastName}";
public ParentModel primaryParentOne { get; }
public ParentModel primaryParentTwo { get; }
public List<ParentModel> alternatePickup { get; }
}
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?
Jimmacle
Jimmacle10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
What do you mean?
Jimmacle
Jimmacle10mo ago
public ParentModel primaryParentOne { get; }
public ParentModel primaryParentTwo { get; }
public List<ParentModel> alternatePickup { get; }
public ParentModel primaryParentOne { get; }
public ParentModel primaryParentTwo { get; }
public List<ParentModel> alternatePickup { get; }
you aren't assigning these in your constructor i'm guessing that's an error
Mekasu0124
Mekasu0124OP10mo ago
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
Jimmacle
Jimmacle10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
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
Jimmacle
Jimmacle10mo ago
you defined them, you didn't give them any value
Mekasu0124
Mekasu0124OP10mo ago
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
Jimmacle
Jimmacle10mo ago
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
Mekasu0124
Mekasu0124OP10mo ago
ok thanks
Want results from more Discord servers?
Add your server