Last active
March 29, 2020 20:05
-
-
Save infinitbility/33d5d129601871c1d9d9cad9824c5f57 to your computer and use it in GitHub Desktop.
Create Table on React Native SQLite Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import SQLite from 'react-native-sqlite-storage'; | |
export default class SQLiteScreen extends React.Component { | |
constructor() { | |
super(); | |
SQLite.DEBUG = true; | |
} | |
/** | |
* Execute sql queries | |
* | |
* @param sql | |
* @param params | |
* | |
* @returns {resolve} results | |
*/ | |
ExecuteQuery = (sql, params = []) => new Promise((resolve, reject) => { | |
db.transaction((trans) => { | |
trans.executeSql(sql, params, (trans, results) => { | |
resolve(results); | |
}, | |
(error) => { | |
reject(error); | |
}); | |
}); | |
}); | |
// Create Table | |
async CreateTable() { | |
let Table = await this.executeQuery("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY NOT NULL, first_name VARCHAR(16), last_name VARCHAR(16), is_deleted INTEGER)",[]); | |
console.log(Table); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment