@capacitor-community/sqlite
Capacitor community plugin for Native and Electron SQLite Databases. For Native, databases could be encrypted with SQLCipher
The following methods have been developed to allow connections to existing sqlite databases created by other plugins without the SQLite.db extension.
Those connections will then access databases in Read-Only mode.
This method allows to get the path of the database giving the folder path and the database name.
The folder path can be any folder under
Applications,LibraryorDocumentsfor iOSdatabasesorfilesfor Android
...
this.sqlitePlugin = CapacitorSQLite;
this.sqlite = new SQLiteConnection(this.sqlitePlugin);
...
let directory: string;
if(this.platform === "ios") directory = "Applications/Files/Databases"
if(this.platform === "android" ) directory = "files/databases";
const databasePath = (await this.sqlite.getNCDatabasePath(directory,"testncdb.db")).path;This method checks if a database path exists prior to create a connection
...
const isNCDbExists = (await this.sqlite.isNCDatabase(databasePath)).result;
...This method checks if a non-conformed connection exists
...
const isConn = (await this.sqlite.isNCConnection(databasePath)).result;
...This method create a Read-Only connection for a given database path
...
db = await this.sqlite.createNCConnection(databasePath, 1);
...This method close a Read-Only connection for a given database path
...
db = await this.sqlite.closeNCConnection(databasePath, 1);
...This method retrieve a Read-Only connection for a given database path
...
db = await this.sqlite.retrieveNCConnection(databasePath);
...Have a look at testncdbspage component in
angular-sqlite-app-starter
