expo / knex-expo-sqlite-dialect

Knex.js dialect for Expo SQLite
12 stars 2 forks source link

@expo/knex-expo-sqlite-dialect

Knex.js dialect for Expo SQLite

Installation

  1. Install the package

yarn add @expo/knex-expo-sqlite-dialect

  1. Add babel preset to the babel.config.js
--- a/babel.config.js
+++ b/babel.config.js
@@ -3,6 +3,7 @@ module.exports = function (api) {
   return {
     presets: [
       'babel-preset-expo',
+      'module:@expo/knex-expo-sqlite-dialect/babel-preset',
     ],
   };
 };
  1. Add the custom dialect for knex constructor
import ExpoSQLiteDialect from '@expo/knex-expo-sqlite-dialect';
import Knex from 'knex';

const knex = Knex({
  client: ExpoSQLiteDialect,
  connection: {
    filename: 'MyDB.db',
  },
});

Components

packages/knex-expo-sqlite-dialect

The main package

babel-preset

Since Knex.js is developed on Node.js runtime, some of Node.js dependencies are not available on React Native. The Babel preset uses the babel-plugin-module-resolver plugin to alias these Node.js modules to other supported modules.

apps/example

The example app replicated from the with-sqlite example with Knex.js integration.