GithubHelp home page GithubHelp logo

palerdot / react-native-sqlite-storage-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andpor/react-native-sqlite-storage-examples

0.0 3.0 0.0 92 KB

Examples for

Home Page: https://github.com/andpor/react-native-sqlite-storage

License: MIT License

JavaScript 37.64% Python 13.95% Java 11.38% Objective-C 37.02%

react-native-sqlite-storage-examples's Introduction

react-native-sqlite-storage-examples

Examples

// import
import SQLite from 'react-native-sqlite-storage'
// init db
let db = SQLite.openDatabase({name: 'test.db', createFromLocation : "~example.db", location: 'Library'}, successCB, errorCB)
// sample execution
db.transaction((tx) => {
  tx.executeSql('SELECT * FROM test', [], (tx, results) => {
      console.log("Query completed");

      // Get rows with Web SQL Database spec compliance.

      var len = results.rows.length;
      for (let i = 0; i < len; i++) {
        let row = results.rows.item(i);
        console.log(`Record: ${row.name}`);
        this.setState({record: row});
      }
    });
});

Promise based example

import SQLite from 'react-native-sqlite-storage';
SQLite.DEBUG(true);
SQLite.enablePromise(true);

let db;

// 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 query
db.executeSql('SELECT 1 FROM Version LIMIT 1')
  .then(() => {})
  .catch(error => {})
// performing transactions
db.transaction('transaction query')
  .then((tx) => {})
  .catch(error => {})

react-native-sqlite-storage-examples's People

Contributors

andpor avatar palerdot avatar itinance avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.