new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle · SQLite · all subjects

drivers/op-sqlite

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

OP-SQLite: what it is and low-level API

OP-SQLite embeds the latest version of SQLite and provides a low-level API to execute SQL queries. It is documented at https://github.com/OP-Engineering/op-sqlite.

OP-SQLite installation packages

To use Drizzle with OP-SQLite, install drizzle-orm@rc, @op-engineering/op-sqlite, and drizzle-kit@rc as a dev dependency.

OP-SQLite basic connection example

To connect to OP-SQLite with Drizzle: ```ts import { drizzle } from "drizzle-orm/op-sqlite"; import { open } from '@op-engineering/op-sqlite'; const opsqlite = open({ name: 'myDB', }); const db = drizzle(opsqlite); await db.select().from(users); ```

OP-SQLite requires SQL migrations bundled as strings in app

OP SQLite requires SQL migration files to be bundled into the app as strings. Drizzle Kit migrations work with OP-SQLite, and you must configure babel to inline import .sql files.

OP-SQLite babel configuration for SQL inlining

Install babel-plugin-inline-import and configure babel.config.js to inline .sql files: ```js module.exports = { presets: ['module:@react-native/babel-preset'], plugins: [ [ 'inline-import', { extensions: ['.sql'], }, ], ], }; ```

OP-SQLite metro configuration for SQL files

Configure metro.config.js to recognize .sql files as source extensions: ```js const { getDefaultConfig } = require('@react-native/metro-config'); const config = getDefaultConfig(__dirname); config.resolver.sourceExts.push('sql'); module.exports = config; ```

OP-SQLite drizzle.config.ts settings

Set dialect to 'sqlite' and driver to 'expo' in drizzle.config.ts for OP-SQLite: ```ts import { defineConfig } from 'drizzle-kit'; export default defineConfig({ schema: './db/schema.ts', out: './drizzle', dialect: 'sqlite', driver: 'expo', // <--- very important }); ```

OP-SQLite migration generation command

After configuring babel.config.js, metro.config.js, and drizzle.config.ts, generate migrations using: npx drizzle-kit generate

OP-SQLite migrations import and useMigrations hook

Import the migrations.js file from ./drizzle folder and run migrations using the useMigrations hook: ```ts import { drizzle } from "drizzle-orm/op-sqlite"; import { open } from '@op-engineering/op-sqlite'; import { useMigrations } from 'drizzle-orm/op-sqlite/migrator'; import migrations from './drizzle/migrations'; const opsqliteDb = open({ name: 'myDB', }); const db = drizzle(opsqliteDb); export default function App() { const { success, error } = useMigrations(db, migrations); if (error) { return ( <View> <Text>Migration error: {error.message}</Text> </View> ); } if (!success) { return ( <View> <Text>Migration is in progress...</Text> </View> ); } return ...your application component; } ```

useMigrations hook return value for OP-SQLite

The useMigrations hook returns an object with success (boolean) and error (object with message property) properties. success is false while migration is in progress, true when complete, and error is set if migration fails.

Give your agent this brain