The current SQLite plugin is just a stupid wrapper around @praeclarum's SQLite plugin and registration with IoC through the bootstrap files. Is it really worth having this?
Sounds like overhead to me.
Doesn't the same happen with the Json plugin and Newtonsoft.Json?
I vote to nuke it. It's just as easy to use the three other forks of praeclarum's library than it is to use this plugin.
We could add some documentation on the website how to use the normal library with MvvmCross.
@nmilcoff sure. However, since the JSON plugin is used a lot of places in MvvmCross, and if we just hardcoded usage of Newtonsoft.Json you wouldn't be able to swap it out with another JSON provider if you wanted.
The case is a bit different with the SQLite plugin.
i lean towards nuke it
Is someone have documentation ?
martijn00 commented on Dec 12, 2016
Thanks
@Jerome2606 what more specifically are you looking for?
Something like:
To use sqlite-net-pcl in your MvvmCross solution:
1) Register a singleton in your App.cs:
Mvx.LazyConstructAndRegisterSingleton<IAppSQLiteConnection>(() =>
{
return new AppSqLiteConnection(Mvx.Resolve<IFileAccessService>());
});
2) Create a base class for your SqliteConnection:
````
public class AppSqLiteConnection: IAppSqLiteConnection
{
internal readonly SQLiteAsyncConnection Connection;
private readonly IFileAccessService _fileAccessService;
public SqliteConnectionEx(IFileAccessService fileAccessService)
{
_fileAccessService = fileAccessService;
string dbpath = GetDatabasePath();
Connection = new SQLiteAsyncConnection(dbpath);
// Create tables
Connection.CreateTableAsync<Log>();
Connection.CreateTableAsync<Category>();
}
public string GetDatabasePath()
{
return _fileAccessService.GetLocalFilePath(string.Empty, Utility.Constants.LocalDatabaseName);
}
...
}
````
3) The fileAccessService is simply an platform specific implementation to get local path of the database
Check here for more information: https://forums.xamarin.com/discussion/34498/environment-getfolderpath-not-exists-cross-plataform
Free to you to make a BaseLocalRepository that inject the IAppSqLiteConnection in constructor and make basic method to query data using generic like:
````
public class BaseLocalRepository
where TEntity : BaseModel
{
protected readonly IAppSQLiteConnection AppSqLiteConnection;
public BaseLocalRepository(IAppSQLiteConnection sqliteConnection)
{
AppSqLiteConnection = sqliteConnection;
}
...
}
````
Bonus:
With sqlite-net-pcl package you can install:
SQLiteNetExtensions by TwinCoders package (Version 2.0.0-alpha2 min) to make query with Children (like include in EF):
https://bitbucket.org/twincoders/sqlite-net-extensions
I can rewrite this cleanly if you want
We could add some documentation on the website how to use the normal library with MvvmCross.
Hi @martijn00 we are using mvvmcross 4.4 and trying to update to 6. We have still mvvm sqlite plugin but couldn't see any documentation about how to replace this plugin. We are having difficulties while replacing with sqlite-net-pcl, it would be awesome if you publish a mini post about it on your site. Thanks!
@Jerome2606
Thanks for the post. Could you please rewrite this more clearly like in steps?
@onurhazar just use SQLitePCL-net directly in your code. Not much else to it. There is no need to abstract this code.
@onurhazar What do you want me to explain more than in my post ? Actually there are already the different steps. Are you stuck with some part of the code ? What are you missing ?
@onurhazar just use SQLitePCL-net directly in your code. Not much else to it. There is no need to abstract this code.
Ok I got your point, will replace it thanks.
@Jerome2606
It would be great if we have mvvm sample fully shows how database operations are done with sqlite-net-pcl package.
@onurhazar you are welcome to make one once you've figured it out :)
Most helpful comment
@nmilcoff sure. However, since the JSON plugin is used a lot of places in MvvmCross, and if we just hardcoded usage of Newtonsoft.Json you wouldn't be able to swap it out with another JSON provider if you wanted.
The case is a bit different with the SQLite plugin.