Where is the sqlite data stored when using Ionic SqlStorage? - sqlite

I'm just curious about the default key-value usage.
import {Storage, SqlStorage } from 'ionic-angular';
let storage = new Storage(SqlStorage);
storage.set(key, value);
storage.get(key).then((value) => { ... });
Where can I find the sqlite file(s)?
I assume I will be able to read/write outside of the app; is that true? Honestly I'm only interested for debugging reasons, so it would be okay if I can only have read access, and only after the app is closed. And I particularly interested on my desktop during development (as opposed to on a device). Do I have to use the backup file option and specify my own path for the database in order to do that?

the documentation states it is stored to WebSQL unless you have installed the SQLite Plugin
First few lines of the documentation...
http://ionicframework.com/docs/v2/api/platform/storage/SqlStorage/

The default database file name within the app storage folder will be '__ionicstorage' per the source here:
https://github.com/driftyco/ionic/blob/f477aa2391922a399acde23bf50ff095b12a287d/src/storage/sql.ts

Related

realm export objects to JSON

Are realm database files platform independent ? For example, if I copy a realm database file from an iOS device to an Android device, will it work ? I am not able to find this from the docs. I cannot use realm platform for file synchronisation though.
Also, in case the file is not cross-platform, if I want to export the data and import it into JSON, what will be the code for the export ? I can find the import code as mentioned in https://realm.io/docs/swift/latest/#json But I cannot find any way to export the contents of a realm database to JSON (Kotlin/Java and Swift are the languages that I care, if it matters).
I have got an answer from the realm forums. The .realm file can be moved across platforms and it is expected to work. Also, there is no native way to export a realm database to JSON as of now (January 2018) as JSON cannot handle cycles, while realm can.
Forum discussion url: https://forums.realm.io/t/realm-export-import-and-cross-platform-nature-of-the-realm-file/

How to access public download folder in every platform in Xamarin.Forms

I need to create a backup service so I intend to save the SQLite database file on each platform. The saved file should be available after the uninstall of the app.
I intend to use the Downloads folder (which should be available on every platform).
I have created an interface and use the following code per platform:
Interface:
public interface IBackupService
{
string GetDownloadPath();
}
Android:
public string GetDownloadPath()
{
return Android.OS.Environment.DirectoryDownloads;
}
UWP:
public string GetDownloadPath()
{
return Windows.Storage.KnownFolders.???????;
}
What should I do about that? Is there a public library that I could use?
There does not seem to be a general downloads folder as per this documentation on KnownFolders. So your assumption on the Downloads folder being on every platform doesn't seem to be correct.
If we dive in a bit further we get to the DocumentsLibrary which seems the obvious choice for this kind of purpose, but it is not. Microsoft says:
The Documents library is not intended for general use. For more info,
see App capability declarations. Also, see the following blog post.
Dealing with Documents: How (not) to use the documentsLibrary capability in Windows Store apps
The paragraph after that seems to describe what we have to do then;
If your app has to create and update files that only your app uses,
consider using the app's local folder. Get the app's local folder from
the Windows.Storage.ApplicationData.Current.LocalFolder property.
So, as I can extract from your question you only want to use storage for your app, so the Windows.Storage.ApplicationData.Current.LocalFolder seems to be the right choice according to Microsoft.

Database backup Azure Resource Manager

Is there a way in Azure Resource manager to take a copy of an existing database? Currently I know there is a database import option, which points to a bacpac file in Blob Storage and creates a new database from that file, but the process to create the file is a manual one at this point. With that, what is the current process to create bacpacs and put them in Blob storage in an automated way through ARM?
There is a way to specify the createMode of your database in the ARM template. This is very undocumented stuff but I found this in the REST api documentation and then just tried in the ARM template.
You can specify the properties "createMode" and "sourceDatabaseId".
I am not using this functionality because the sourceDatabaseId needs to be in the same subscription which was not the case with me. So i export the bacpac manually and then use an ARM template to import the bacpac (which also is undocumented but I commented the ARM template used here: https://azure.microsoft.com/en-us/documentation/articles/sql-database-import/)

With MvvmCross what is the preferred way to copy a prefilled SQLite Database

I am modifying the N-10-KittensDb sample solution.
I See how to create a SQLite database, but I wish to use an existing database. I am guessing that I need to copy the database to the proper UI data folder. Maybe it is done within the Core project? And if so how is the correct path injected into the running Exec? As the Core can be used across many UI's? What method is called to see if the database exists or needs to be copied?
Sample from DataService:
public DataService(ISQLiteConnectionFactory factory)
{
const string file = "Cats.sldb";
var connection = factory.Create(file);
connection.CreateTable<Kitten>();
}
I believe the paths are different for Android vs Phone vs Touch vs Wpf?
Please direct me to a sample piece of code that uses the Cirrious.MvvmCross.Plugins.Sqlite for Phone or Wpf.
Thank you
Dan
Each platform by default creates a database in a folder location appropriate for the platform - e.g. Touch uses:
public ISQLiteConnection Create(string address)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return new SQLiteConnection(Path.Combine(path, address));
}
from https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/Sqlite/Cirrious.MvvmCross.Plugins.Sqlite.Touch/MvxTouchSQLiteConnectionFactory.cs#L18
To read/write files, MvvmCross does bundle a File plugin - this also operates by default in platform specific locations - but the two may not match perfectly - e.g. see:
protected override string FullPath(string path)
{
if (path.StartsWith(ResScheme))
return path.Substring(ResScheme.Length);
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), path);
}
from https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/File/Cirrious.MvvmCross.Plugins.File.Touch/MvxTouchFileStore.cs#L22
Because of this mismatch, in order to share the same database-specific copy code across platforms you may find it easier to just inject your own platform specific copy on each platform - for more on injecting platform specific services, see http://slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html

Clarification on web2py apps sharing a single database

Sorry, I'm a little unclear on the web2py manual explanation.
as an example, given app1 and app2
I want to have app2 share the database I have built in app1
So do I change the app2/models/db.py file to show: db = DAL('sqlite://storage.sqlite',migrate='false') ?
and include all other myModel.py files in app2/models directory as well?
if the database is in app1/databases/ how does app2 know how to find the correct database file?
This Thread begins to answer the question but I'm still unclear on how to define where the shared database lives.
Note, DAL(..., migrate=False) just sets the default value of migrate for each table -- it will not have any effect on the migration status of tables whose define_table() calls include their own explicit migrate argument. If you want to completely disable migrations for an entire db connection (regardless of the individual define_table() calls), instead use:
DAL(..., migrate_enabled=False)
Also, to share model definitions between applications, rather than simply copying the model files, you could put the definitions in functions or classes within modules and then import the modules. Another option is to use auto_import:
DAL(..., auto_import=True)
Note, auto_import will import the field names and types, but it will not include DAL-specific attributes, such as validators and defaults, so its usage is somewhat limited.
I can't test this right now but the answer should be:
you can override the folder in the DAL:
So both apps should point to the same file.
(see the docs and this thread).
.
db = DAL('sqlite://storage.sqlite',folder='path/to/app/databases')
yes, should need the model files in both apps too, otherwise the apps won't know how to access the db.

Resources