Closed themronion closed 4 years ago
I wrote this library (at the suggest of my boss) after issues we had using LIteDB in Xamarin apps and using MVVM.
So I was thinking of taking something outsource that matches that description and adding LiteDb.Async functionality as an example of how to do it.
If you or anyone reading this comment knows of such a project that would be great.
@mlockett42 okay i will keep that in mind, if something will come up i will let u know! By the way. Off the topic. I am currently struggling to use LiteDB v 5 in my xamarin app. Maybe it would be cool to add at least a "how to use in Xamarin.Forms" in the ReadMe for Xamarin developers, cause i think mostly them will use this amaznig lib. For example, i have now problems. Can u help me out a bit? The log file never gets deleted - i guess i need to dispose somewhere but i can't figure out how to do it correctly. Here is my code - App.cs -
public static UserDatabase database;
public static UserDatabase Database
{
get
{
if (database == null)
database = new UserDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Users.db"));
return database;
}
}
my class
public class UserDatabase
{
LiteCollectionAsync<User> _usersCollection;
public UserDatabase(string connectionString)
{
var db = new LiteDatabaseAsync(connectionString);
_usersCollection = db.GetCollection<User>();
}
public Task<IEnumerable<User>> GetUsers()
{
return _usersCollection.FindAllAsync();
}
public Task<bool> SaveUser(User user)
{
return _usersCollection.UpsertAsync(user);
}
public Task<User> GetUser(int id)
{
return _usersCollection.FindByIdAsync(id);
}
public async Task<int> GetUsersCount()
{
var users = await GetUsers();
return users.ToArray().Length;
}
}
usage -
var allUsers = await App.Database.GetUsers();
Sorry for the off topic again, but can u guide to the right direction please? Really wanna use LiteDB but this log file problem bothers me
The log you mention is LiteDb's internal log file?
I will have a look at some of our other code tomorrow.
I am suspicious that keeping the _usersCollection around forever might be a problem I think the code we have at work would throw it away each time after using it.
Yeap, their log file. Thanks!
How big does the log file get? How many records are you putting in it?
Well it is small at the beginning. But after each operation with the db (even if i have 1 user in my collection) it grows linearly. I've read on the LiteDB topics that i need to call db.Dispose every time so that all the file connections are closed but in my architecture i cant figure out how to do it
I saw the answer from the LiteDb developers about this issue over there
https://github.com/mbdavid/LiteDB/issues/1837#issuecomment-705777582
The checkpointsize property is warpped by LibteDb.Async in version 0.0.4 and available to use. I suspect you will need to make 1000's of writes to the database for it to kick in
Ah, i see now) i thought 1000 is for 1000 kb, not for 1000 operations. My bad) i will try to decrease the checkpoint size, thanks again!
Checkpoint and Checkpointsize are now exposed in v0.0.5
Hey, finally there is async support for this amazing library! I will check it out in the nearest future. Meanwhile it would be quite cool and useful for everyone else to see the advantages of using your wrapper, not just regular LiteDB. I recommend u to put a sample out there in the Readme that demonstrates the async pros (hopefully no cons) of your wrapper - that way we, developers, can really see the advantages! Thanks!