Code2Gether-Discord / EasyList

A beginner console app to learn general programming stuff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement data persistence

18-F-cali opened this issue · comments

We could we json as data structure and store it in files ?

commented

Maybe use a sqlite database?

Maybe use a sqlite database?

we are trying to keep it as simple as possible so would prolly be best avoiding sql. i think startin with json is great, or something like MongoDb or even LiteDb

commented

Maybe use a sqlite database?

we are trying to keep it as simple as possible so would prolly be best avoiding sql. i think startin with json is great, or something like MongoDb or even LiteDb

Oh yup, in that case I think Mongo is a good idea.

No idea how to work with databases
how about we do file persistence first and then db persistence ?

commented

Would probably be more work to roll your own file reading and loading than just wiring up entity framework with mongodb

Cool, Will check it out then.
Any recommendation to learn more about it?

Cool, Will check it out then.
Any recommendation to learn more about it?

Mongodb has free courses on their site. Kniw tim corey also has 1 about it

commented

MongoDb does not actually support EF directly. But I still think Mongo even on it's own is a good option.
Here's a document that can help someone get started: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-5.0&tabs=visual-studio
If this isn't worked out, can maybe have a call sometime this week and run through it.

As discussed lets use liteDB

while going through docs I found litedb does not support Datetimeoffset:

but Stack overflowsuggets to convert store the time as a timestamp which is a long. So store DateTimeOffset.ToUnixTimeSeconds() when you store the data and DateTimeOffset.FromUnixTimeSeconds() when you retrieve it.

And I didn't fully understand the second suggestion.

There is also this suggestion

mapper.RegisterType<DateTime>(
    value => value.ToString("o", CultureInfo.InvariantCulture),
    bson => DateTime.ParseExact(bson, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind));
mapper.RegisterType<DateTimeOffset>(
    value => value.ToString("o", CultureInfo.InvariantCulture),
    bson => DateTimeOffset.ParseExact(bson, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind));

using (var db = new LiteDatabase("instance.db", mapper))
{
    ...
}