SQLite-Net-Pcl in Xamarin.Forms - sqlite

I am trying to learn SQLite and its usage from Xamarin.Forms. I found that it is recommended to install Sqlite-net-pcl as NuGet package and make use of it to create, open, modify a database. Up to that point everything is fine. However, I am struggling to find more details about Sqlite-net-pcl on the web. It seems, a comprehensive documentation is not available for this library. And this reality brought some questions to my mind which I believe I could get answer from Stackoverflow seniors:
1-If there is no documentation of a library which you are trying to use, what is the best way to learn it quickly? Trial&Error? In that case full class hierarchy would be needed, I think.
2-As I understood, Sqlite-net-pcl is a partial implementation of Sqlite. For instance, in the documentation of Sqlite, it is said, Foreign key is supported but should be enabled. But, I couldnt find this attribute in Sqlite-net-Pcl when I used the ObjectBrowser tool of VisualStudio.
3-Considering, SQLite have better support, If I want to use SQLite directly in xamarin.forms(c#) instead of its derived versions(Sqlite-net-pcl) how can I achieve this?

It is preferable to use SQLite-net libraries. They are simply a wrapper around SQLite flow. You have everything that you need there. Also, if you want to use an ORM, you can also use EntityFrameworkCore via Microsoft.EntityFrameworkCore.Sqlite
Like it is said in the GitHub repository:
SQLite-net is an open source, minimal library to allow .NET, .NET Core, and Mono applications to store data in SQLite 3 databases. It was first designed to work with Xamarin.iOS, but has since grown up to work on all the platforms (Xamarin.*, .NET, UWP, Azure, etc.).
About the Foreign Key - there isn't any constraints. You can use it freely without any "enabling".
There are some other options like Microsoft.Data.SQLite & System.Data.SQLite, but I haven't tried them with Xamarin and, if they work, I don't think that they will have better support for Mono, like the one that you have with SQLite-net. The latter is also updated constantly.
Here is the official tutorial from Microsoft about using sqlite-net-pcl
If you want to use an ORM, you can follow this article from the official docs on how to setup the SQLite libraries, together with EFCore packages, migrations, etc.
Should you choose to use EFCore, please consider the Migration Limitations.

Related

SQLite support in Dart command-line application?

I need to manage (SELECT, INSERT, UPDATE, etc.) a simple SQLite database through Dart code, but all the SQLite connector libraries I could find are very outdated. I've searched for a solution and haven't seen anything compatible with Dart 2. Can anyone think of an alternative way to do this?
Note: The application and database will eventually be migrated server-side
with Azure.
Note: I am fairly new to working with SQL and RDBMS.
Thanks!
The sqlite package should provide what your need. It is pretty up-to-date including null-safety and recently updated.

Is it possible to use pure functionality of sqlite-net-pcl and Akavache using it in same project?

In Akavache docs said that it's powered by SQLite.
And from what I heard Akavache is quite nice tool for the key-value storage and sometimes you just don't want to store some cached data into SQL.
Also, usually in mobile apps you also require some data stored in SQL-manner.
In that case it requires two db approaches to be used through the app: SQL and Non-SQL. So, as long as Akavache is still based on SQLite, is there any way to use both: SQLite and Akavache, which uses the sam SQLite (files)?
This is referred in context of Xamarin .NET Standard projects.
Any hints?

Monaca implementation of SQLite - Native via Cordova or Deprecated Web SQL?

So basically like the title says, does Monaca implement local storage database as SQLite using the native implementation via Cordova's sqlite plugin or does it rely on the deprecated use of Web SQL standard?
The Monaca docs here:
http://docs.monaca.mobi/cur/en/sampleapp/tips/storage/#creating-a-database-sqlite
Show that it is SQLite using the deprecated Web SQL standard: window.openDatabase
I would assume Monaca would actually be using Cordova implementation of native SQLite via the plugin but I cannot find it in the plugin manager nor do the docs support the implementation syntax of: window.sqlitePlugin.openDatabase
Either way, what would be the best practice use of SQLite in an app? My fear is to use what is documented (I think deprecated) and then next version have to recode everything when the Cordova plugin implements SQLite in native already.
Thanks!
XPost from here: https://community.onsen.io/topic/216/monaca-implementation-of-sqlite-native-via-cordova-or-deprecated-web-sql/2
#munsterlander this is a very good question! I actually didn’t know that Web SQL was deprecated. At the moment, Monaca includes just Web SQL plugin but the native Cordova plugin can be imported with a developer or higher plan and should work without any issue.
We will discuss about integrating the new plugin in Monaca but I cannot say when it will happen.
I don’t think you will have any issue with Web SQL but, of course, it’s better to use the native plugin.

How do you setup Mvvmcross SQLite plugin to be tested?

I'm quite new to mvvmcross and I'm working on an app that uses SQLite plugin as "backend" for the model. (WinRT and WP/8 only at the moment but porting it to Droid and IOS when firts two platforms work ok).
I would like to setup some tests using NUnit and VS2012 but having some difficulties to find examples on how to initialize the framework and the plugin in the SetupFixture class/setup for the test.
Can someone who already have done this point me in the right direction ?
Thank you very much for your time and help
I generally don't test at the SQLite interface level itself.
Instead, I generally wrap the use of SQLite inside very simple repositories. Each of these repositories provides an interface. Each of the repositories and SQLite itself is assumed to be a known good components - so it not tested. And this allows me to then test other code using Mocks for these repositories, rather than trying to mock or use SQLite itself.
If you want to test at the SQLite level:
You could write a ISQLiteConnection test implementation
Or you could write something that used one of the SQLite on Windows plugins for testing

Will using dblinq to SQLite in a Windows Store app pass store validation?

I've been trying to figure out how to get a decent LINQ to something working for ORM database access in a Windows Store app.
All I've found is SQLite and the sqlite-net NuGet package. The latter sucks a bit, as I don't get any .dbml like structure which resolves relationships and provides navigation properties for easy querying (no manual joins needed then).
I was wondering:
Does dblinq in comnbination with SQLite offer this?
Will using this pass Windows Store validation?
Thank you !
Update: Some links I used in my research:
The famous Tim Heuer post on SQLite and Windows 8: http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx
DBlinq: http://code.google.com/p/dblinq2007/
sqlite-net: http://code.google.com/p/sqlite-net/
Interesting discussion stating ADO.NET is not possible: http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/e9cdd75d-03e4-4577-988e-4c02a52e3f50
I'm not familiar with dblinq but by looking at the sqlite tests in the project, it seems the library is offering what you're looking for, i.e. navigation properties for relationships between different tables.
Since dblinq is a .NET library, using it shouldn't make the store validation fail. There is another problem though: you can't use such a .NET library in a Windows Store application, only Windows Store class libraries and portable class libraries are allowed. Since the source for the library is available, you can try compiling it as a Windows Store class library, but I'm afraid there are going to be some classes missing that dblinq is depending on which might make it difficult to port.

Resources