react-native-ppr-database
v1.0.1
Published
Support PPR Database
Downloads
1
Readme
react-native-ppr-database
Require:
- "react-native": "*",
- "react-native-sqlite-storage": "*"
BaseDatabase
Inside the class's methods, this.database
is initialized and used to exectutel SQL actions. You should use this field too.
We have already table KeyValue
to manage database version. You should read the source code to reference.
Method
| Method|Parameter|Description |
| -- | -- | -- |
| constructor
| name: string, currentDBVersion: number
| Initialize the database informations includes database name and database version |
| openDatabase
| void
| Open the database and validate the database version, re-create all tables in database if the database version changed |
| createTables
| tx: SQLitePluginTransaction
| Create all tables in the database |
| dropTables
| tx: SQLitePluginTransaction
| Drop all tables in the database |
| initializeDatabase
| void
| Call dropTables
, then call createTables
. This method is called if openDatabase
detect the database version changed |
Usage
import BaseDatabase, { SQLQueryCreator } from "react-native-ppr-database";
// * table schema template *
// you should use this template if you want to use SQLQueryCreator
const Animal = {
name: "Animal",
primaryKey: "id",
properties: {
"id": "text",
"name": "text"
}
};
// inherit from Database to modify
class DerivedDatabase extends BaseDatabase {
// create more tables in `createTables` method.
createTables(tx) {
super.createTables(tx);
tx.executeSql(SQLQueryCreator.createTable(Animal));
}
// drop more tables in `dropTables` method.
dropTables(tx) {
super.dropTables(tx);
tx.executeSql(SQLQueryCreator.dropTable(Animal));
}
}