// importimportSQLitefrom'react-native-sqlite-storage'// init dbletdb=SQLite.openDatabase({name: 'test.db',createFromLocation : "~example.db",location: 'Library'},successCB,errorCB)// sample executiondb.transaction((tx)=>{tx.executeSql('SELECT * FROM test',[],(tx,results)=>{console.log("Query completed");// Get rows with Web SQL Database spec compliance.varlen=results.rows.length;for(leti=0;i<len;i++){letrow=results.rows.item(i);console.log(`Record: ${row.name}`);this.setState({record: row});}});});
Promise based example
importSQLitefrom'react-native-sqlite-storage';SQLite.DEBUG(true);SQLite.enablePromise(true);letdb;// echo test to check for db?SQLite.echoTest().then(()=>{// success; OPENING db?SQLite.openDatabase({name : "test5.db",createFromLocation : "~/db/andrew.db"}).then((DB)=>{db=DB;}).catch((error)=>{console.log(error);});}).catch(error=>{// error in handling db});// now db has the dqlite db handle// perform normal querydb.executeSql('SELECT 1 FROM Version LIMIT 1').then(()=>{}).catch(error=>{})// performing transactionsdb.transaction('transaction query').then((tx)=>{}).catch(error=>{})