1.2.1 • Published 2 years ago

knex-react-native-sqlite v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

knex-react-native-sqlite

This package provides a SQLite3 (via react-native-sqlite-storage) dialect for knex in React Native projects.

This package is inspired by react-native-knex. Instead of modifying knex directly a browser and React Native-friendly build is generated using webpack. Knex is then imported from this build then exported along with the dialect allowing everything to work harmoniously with React Native.

Installation

npm install knex-react-native-sqlite

or

yarn add knex-react-native-sqlite

Usage

Import like below then use knex as normal.

import { knex, RNSqliteDialect } from 'knex-react-native-sqlite';

// configure you knex db instance
const db = knex({
  client: RNSqliteDialect,
  connection: {
    name: 'dbname.db',
    location: 'default',
    // any other settings to pass to openDatabase from react-native-sqlite-storage
  }
});

(async () => {
  if (! await db.schema.hasTable('user')) {
    await db.schema.createTable('user', table => {
      table.increments('id').primary();
      table.string('name', 50).notNullable();
      table.int('age').notNullable().defaultTo(0);
    });
  }
  
  await db('user').insert({
    name: 'Bob Doe',
    age: 25,
  });
  
  await db('user').orderBy('name');
})();
1.2.1

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago