Skip to content

Instantly share code, notes, and snippets.

@infinitbility
Last active March 29, 2020 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinitbility/33d5d129601871c1d9d9cad9824c5f57 to your computer and use it in GitHub Desktop.
Save infinitbility/33d5d129601871c1d9d9cad9824c5f57 to your computer and use it in GitHub Desktop.
Create Table on React Native SQLite Storage
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