Knex.js dialect for Expo SQLite
npm install @expo/knex-expo-sqlite-dialectKnex.js dialect for Expo SQLite
1. Install the package
yarn add @expo/knex-expo-sqlite-dialect
2. Add babel preset to the babel.config.js
``diff`
--- 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',
],
};
};
3. Add the custom dialect for knex constructor
`ts
import ExpoSQLiteDialect from '@expo/knex-expo-sqlite-dialect';
import Knex from 'knex';
const knex = Knex({
client: ExpoSQLiteDialect,
connection: {
filename: 'MyDB.db',
},
});
`
The main package
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.
The example app replicated from the with-sqlite` example with Knex.js integration.