Okay.
So the last time we're here, we're discussing setting up a database.
But before I jump into setting up a database, I want us to understand all of our storage options and
when we would use them and what would be the best tool for which situation.
So I'm in the main page of XAML file, and I'm just going to use here to kind of depict some of the
stuff.
We're not really going to do any hard audience.
You can just follow along and we'll just basically be having something of a discussion, right?
So the first one would be preferences.
So Preferences provides a built in key value peer storage mechanism for us in our app.
So the key value period, similar to what we saw earlier with the dictionary when we had to pass in
the string as the parameter name and the object as the data to be passed over.
That's a key value here.
So in our MIUI app, we actually have the ability to call on.
Um, uh, property called preferences.
Our classical preference is more like a static class that is always present in pretty much every page
that you create.
One scenario and on up you can hit the preferences.
You can check if it contains a key.
So a key would be a string and a key has to be unique.
So you either you're going to try an adult that already exists and gets an error, or you have to override
the value that went with effect key at a certain point, right?
So you can clear all the keys, you can get a particular key, right?
You can set a key and you can remove a key.
So an example of this would be maybe like if somebody has log in, you put in some log in system and
you want to check if the person is currently logged in or not.
Right.
Um, or rather on the log in screen when they would have said save details and you want to know, did
they save the details or not?
You could save preferences because it's their phone, right?
It's their mobile app.
So you're saving the preference from the mobile app selection so you could easily just see a set.
What's the key?
He could say save details and then you would just see what the what they selected.
But let's just pretend that they said true.
See?
So some other point.
You may need to make a decision.
You need to retrieve.
What did they say?
You could then save our details.
Saved is equal to preference.
Not yet.
And then we look for that key.
Right.
That gets takes.
String key as well as a default value if it doesn't exist.
So the default value would probably be like falls.
So if it doesn't exist, then assume that it wasn't saved.
So that's preferences.
That's option.
That's an option.
Key value pair, very simple, unintuitive way of storing data.
So that's basically how preferences work.
Now the next option that you would have would be the file system.
So if you wanted to store well in anything like a text file or some file to the phone's system, then
you'd want to use the file helper.
So let's say that we had well, we have a list of cars rights of our cars would be equal to or let me
actually do that over here in the.
They view models in sorority house, a representation of cars on this side.
So let's say that we have this list of cars that we actually wanted to store it on the file system.
Right.
So we could actually say something like string file name.
Is equal to.
And let's just take her list.
Right.
And let's make it.
That text file could also be a Jason file.
Probably better as a Jason card Karlis thought Jason and then we would save are serialized serialized
list is equal to then we could use our Jason Serialize or class, which would just include the missing
using reference to using system that takes that.
Jason So we just serialize this object that serialize cars.
So just that's into Jason object and then I can see file dots, right?
All text the file name and or serialized list.
Right.
So that's pretty much how we would do that.
So it would just go ahead and store that to the file system.
And of course we could retrieve it by just seeing a file that read or text and then we give it the file
name.
That we want to retrieve and read.
And of course, this would be var raw text and then we could easily be serialized back into of cars
from text.
We could just serialize that back into our object list.
So just serialize.
And of course you can use the async if we need to into a list of car.
Right.
There we go.
So yeah, we can always convert between one from Jason, but at the end of the day, we would want to
write our save our text file to the system.
So at that point, we could see a string pass.
Is equal to.
And we see a file system.
Dot's app directory.
Now that gives us a directory for wherever we are.
We could also create like a folder in our documents, and this would probably be more for like an iOS
system.
So you could say a string folder is equal to and it would access environments that get folder path.
And then we see an environment that special folder dots and then we can look at the different ones.
So if you wanted it in documents, you could just see my documents, right?
We also see that there are other options.
So you'd want to choose the one that is best for your situation.
And so that is how we would actually store to the file system.
And retrieving is fairly simple.
Now a third option would be if we were to use sequel light.
So Sequel Light is truly built using C++, but it has our upper a few wrappers around it and a few ways
to interact with it.
Right.
So SQLite is, as the name suggests, it's a very light skill database that can actually sit on the
system that it is created on, right.
So in this case, our mobile app is on our mobile phone.
We can create a sequel database.
I will sit on the phone and we can connect to it and carry out relational database operations.
So I'm not going to demo it here.
I just wanted to show you other storage options.
But when we come back, we'll just go straight into the sequel, right?
Database setup.