GithubHelp home page GithubHelp logo

revskill10 / react-native-sqlite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from almost/react-native-sqlite

0.0 1.0 0.0 65 KB

SQLite3 bindings for React Native

License: MIT License

Objective-C 83.01% JavaScript 16.99%

react-native-sqlite's Introduction

react-native-sqlite

A binding for sqlite3 for React Native. Allows a database to be oppened and for SQL queries to be run on it.

Really early version right now, the API might change and I'm still figuring out the best way to do things with React Native.

Written by Thomas Parslow (almostobsolete.net and tomparslow.co.uk) as part of Active Inbox (activeinboxhq.com).

Installation

Install using npm with npm install --save react-native-sqlite

You then need to add the Objective C part to your XCode project. Drag AIBSQLite.xcodeproj from the node_modules/react-native-sqlite into your XCode project then click on the your project in XCode, goto Build Phases then Link Binary With Libraries and add libAIBSQLite.a.

Make sure you don't have the AIBSQLite project open seperately in XCode otherwise it won't work.

Usage

var sqlite = require('./react-native-sqlite');
sqlite.open("filename.sqlite", function (error, database) {
  if (error) {
    console.log("Failed to open database:", error);
    return;
  }
  var sql = "SELECT a, b FROM table WHERE field=? AND otherfield=?";
  var params = ["somestring", 99];
  database.executeSQL(sql, params, rowCallback, completeCallback);
  function rowCallback(rowData) {
    console.log("Got row data:", rowData);
  }
  function completeCallback(error) {
    if (error) {
      console.log("Failed to execute query:", error);
      return
    }
    console.log("Query complete!");
    database.close(function (error) {
      if (error) {
        console.log("Failed to close database:", error);
        return
      }
    });
  }
});

Know Issues

  • I'm using events on RCTDeviceEventEmitter to pass back rows from queries, is this the best way to do it?
  • Doesn't supporting reading of BLOB fields right now. I'm not entirely sure what would be the best way to pass back binary data. Maybe Base64?
  • Database needs to be closed manually. I'm not sure how I could do this automatically.

Feedback Welcome!

Feedback, questions, suggestions and most of all Pull Requests are very welcome. This is an early version and I want to figure out the best way to continue it.

I'm also available for freelance work!

I'm @almostobsolete on Twitter my email is [email protected] and you can find me on the web at tomparslow.co.uk and almostobsolete.net

react-native-sqlite's People

Contributors

almost avatar

Watchers

 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.