MvvmCross Async SQLite - sqlite

I'm starting to rebuild my app to MvvmCross, but I hit a small roadblock. It seems the community plugin for SQLite doesn't support async connection and querying. WinRT requires data access and other long-running operations to be performed asynchrnously, so this seems like an issue (although I think it is safe to say, that normal operations won't take that long to make this matter). I just wanted to ask, if asynchronous support is somehow possible to add and if this feature will be somehow added in future releases.
Thank you all very much!

Don't use the mvvmcross sqlite plugin. Instead use the PCL compatible "sqlite.net pcl". It has both sync and async versions.
github:
https://github.com/oysteinkrog/SQLite.Net-PCL
nuget:
http://www.nuget.org/packages/SQLite.Net-PCL/

The cg+sql branch of my fork contains provisions to use Async in mvvmcross-sqlite
https://github.com/loqu8/mvvmcross-sqlite/tree/cg+sql
Take a look and see if it works for you. It is based on sqlite-net Async.

Please look at TODOs in MvvmCross Sqlite-Net (https://github.com/MvvmCross/MvvmCross-SQLite) readme file. The first one:
add Async - #Praeclarum and #Jarroda have already done the 'hard work'
- we just need to work out how to include it - do we switch to Profile78? Do we drop WP7.5? Do we hack in AsyncBridge somehow?
So it seems that we will get Async support some day and will get even more fun from using MvvmCross! :-)
For now it seems that the only solution is to create low-level data access interface with save/load/find methods and implement it in platform-specific projects.

Related

SQLite-Net-Pcl in Xamarin.Forms

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.

PlugIn vs Dependency service in Xamarin.forms

hi I read some msdn tutorial on Xamarin form but there is no mention of PlugIn. I am a bit confused as to which one to use. Dependency service is used to call the platform Specific Api such as TextToSpeech in iOS and Android. But there are Plugin for Camera, Toast, Location and others. It seems this approach is better.
I need some confirmation and understanding to clear this confusion.
1.Is PlugIn an alternative to Dependency service?
for Example , I dont have to use Dependency service for location in iOS and Android if there is a Location-Plugin for Xamarin.forms.
your confirmation will help me on this matter.
Thanks
The DependencyService is a method that is built into the Xamarin.Forms library to provide you with a way to implement platform-specific code. More information can be found in the documentation: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/
The plugins, now bundled as Xamarin.Essentials (but of course there are much more), actually might use this DependencyService or at least work in a very similar way.
There really is not one answer to choose one or the other. If there is a plugin that does what you need and you feel comfortable using it, then do! If you need something different, you might want to write something of your own.
Always have a good look at the state of the code for a plugin: is it actively maintained? Is it built by someone you would trust, etc.

What storage type do I use now since websql is deprecated?

WebSQL is deprecated now and IndexedDB wasn't implemented to cordova yet. So, what storage type you are using, guys?
I think to use a Native SQLite Android Plugin, but I don't know if is the only and best way.
I suggest you to keep using WebSQL for the moment.
you should build a separated js wrapper to your db, so it will be easy to replace when time comes.
but for the moment- it works and supported by the mobile browsers, and threfore you have nothing to worry about.
you can read this discussion:
https://groups.google.com/forum/#!topic/persistencejs/KYSWQ1H8hL0
also, keep in mind that if you intend to use plugin for native storage, you will not be able to use Phonegap Build, so you may want to consider it.

Cordova/Phonegap ORM?

Are there any ORM javascript projects compatible with Cordova, like ORMLite? I did a google search, github search, searched here, and couldn't find any.
If not, maybe it's time to start one.
This old but I stumbled upon it so others might too... what ended up working for me was using the Cordova SQLite plugin for a db with no size limit and the Persistence.js ORM to work with it.
This question is old, but there is also Persistence.js which I actually ended up using. It has it's own drawbacks, but every ORM does.
It would actually use the HTML5 storage on the phone. This is limited to 5mb per the specification, but obviously individual vendors may not enforce or follow this limit.
Yes there is an Open Source Framework, known as Siminov Hybrid, it provides ORM for both Android Native (Java) and Web (JavScript). It is easily configurable which works for both Native and Web at same time.
Works with Phonegap and later it will be support on other frameworks also.
http://siminov.github.io/android-hybrid
I do not know why there is no official ORM for sqlite with cordova though it is very required !
Anyway as time of writing this , you have the below option :
1- typeorm with angularjs2 ( they promised to provide support for sqlite )
2- ionic2-orm it is a fork of the previous point , however it look like there is no support till now
3-ionic2-orm2 which is a fork of the previous point also ( duh.. ) you can access it on this one https://github.com/sidneycorreia/ionic-orm
4- the best option up to this point is pouchdb check this one https://pouchdb.com/

What is the future of the Sys.require, ASP.NET AJAX loader script?

Does anyone know if this script will continue to have a future or is it DOA and being replaced by another component? I use its functionality a lot and would like to know if there is a better alternative or what the future holds for it...
To clarify, I'm talking about the async loader features in start.js.
None of the ASP.NET Ajax Library (not to be confused with ASP.NET AJAX) was officially released and development on it ceased before it was complete. You shouldn't use it. I've wrote an article on the subject.
The same team at Microsoft has produced a new script loader, DeferJS, which is the next logical evolution of Sys.require. You can find the latest version of it here: https://github.com/BorisMoore/JsDefer
There's not going to be any further development on sys.require, but the existing scripts and services will not disappear. Microsoft has taken considerable measures to maintain backwards compatibility with its older technologies, so there's no reason to think that what you have working now will suddenly stop working at some point in the near future.
Microsoft seems to be going in the direction of integrating with the open source jQuery library. Here's a blog post about it: http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx. jQuery is very powerful and flexible, and has both built in support as well as a plethora of plugins for AJAX.
There's also RequireJS (http://requirejs.org/), which is quite mature, and somewhat easier to use. It's not from Mircosoft, but it may be worth a look.
May be you can try this
it is an extensible resource loader, and it does dependencies tracking.

Resources