Skip to content

Latest commit

 

History

History
120 lines (89 loc) · 4.42 KB

File metadata and controls

120 lines (89 loc) · 4.42 KB

BlackBerry-Dynamics-for-React-Native-SQLite-Storage

BlackBerry-Dynamics-for-React-Native-SQLite-Storage secures SQLite database management and is based on the react-native-sqlite-storage (v6.0.1) 3rd party module.

The JavaScript API of this module remains the same however the SQLite database is created in the Dynamics secure container and is managed by secure SQLite API.

For more details please refer to com.good.gd.database package on Android and sqlite3enc Dynamics runtime feature on iOS.

Supportability

React Native

  • 0.66.x (deprecated)
  • 0.67.x (deprecated)
  • 0.68.x (deprecated)
  • 0.69.x (deprecated)
  • 0.70.x
  • 0.71.x
  • 0.72.x

Platforms

  • iOS
  • Android

Preconditions

BlackBerry-Dynamics-for-React-Native-SQLite-Storage is dependent on BlackBerry-Dynamics-for-React-Native-Base module.

Please install BlackBerry-Dynamics-for-React-Native-Base first.

Installation

$ yarn add <path>/modules/BlackBerry-Dynamics-for-React-Native-SQLite-Storage
iOS
$ cd ios
$ pod install
$ cd ..
$ npx react-native run-ios
Android
$ npx react-native run-android

Usage

import {openDatabase} from 'BlackBerry-Dynamics-for-React-Native-SQLite-Storage';

// ...

const db = openDatabase({ name: 'RNTestDatabase.db' }, () => {
  console.log('Database is succesfully opened!')
}, () => { 
  console.log('Error in opening database!')
});

// ...

db.transaction(tx => {
  tx.executeSql(`SELECT name FROM sqlite_master WHERE type="table" AND name="Users";`, [], (tx, result) => {
    if (result.rows.length === 0) {
      tx.executeSql('DROP TABLE IF EXISTS Users', []);
    }

    tx.executeSql(
      'CREATE TABLE IF NOT EXISTS Users (id INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(20), phone INT(10), address VARCHAR(255))',
      []
    );

  });
}, error => {
  console.log('Transaction error: ', error);
}, () => {
  console.log('Transaction for initialization users table is succesfully finished!');
})

// ...

Importing pre-populated DB

Importing pre-populated DB as described here is now supported.

You can import an existing - pre-populated database file into your application. Depending on your instructions in openDatabase call, the module will look at different places to locate your pre-populated database file.

NOTE: all the cases below are covered in SampleApplications/SQLite sample app. Also, there are useful scripts that allow to copy and link DB files.

createFromLocation : 1

If your folder is called www and data file is named the same as the dbName - testDB in this example:

import {openDatabase} from 'BlackBerry-Dynamics-for-React-Native-SQLite-Storage';

const db = openDatabase({name : "testDB", createFromLocation : 1}, okCallback,errorCallback);

createFromLocation : "~data/<db_path>"

In case if your folder is called data rather than www or your file name does not match the name of the DB, for example, DB is named testDB but the file is mydbfile.sqlite which is located in a data subdirectory of www.

import {openDatabase} from 'BlackBerry-Dynamics-for-React-Native-SQLite-Storage';

const db = openDatabase({name : "testDB", createFromLocation : "~data/mydbfile.sqlite"}, okCallback,errorCallback);

createFromLocation : "/data/<db_path>" (Android only)

This option in supported on Android only and is not supported on iOS for now

If your folder is not in application bundle but in app sandbox i.e. downloaded from some remote location. In this case the source file is located in data subdirectory of Documents location (iOS) or FilesDir (Android).

import {openDatabase} from 'BlackBerry-Dynamics-for-React-Native-SQLite-Storage';

const db = openDatabase({name : "testDB", createFromLocation : "/data/mydbfile.sqlite"}, okCallback,errorCallback);

Uninstallation

$ cd <appFolder>
$ yarn remove BlackBerry-Dynamics-for-React-Native-SQLite-Storage
iOS
$ cd ios
$ pod install
$ cd ..

Known issues

WAL is not supported

Write-Ahead Logging is not supported.