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/expo-sqlite

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

Drizzle Expo SQLite driver installation

Install drizzle-orm, expo-sqlite, and drizzle-kit using npm: drizzle-orm@rc, expo-sqlite@next, and drizzle-kit@rc as dev dependency.

Initialize Drizzle with Expo SQLite

Import drizzle from 'drizzle-orm/expo-sqlite' and openDatabaseSync from 'expo-sqlite'. Call openDatabaseSync('db.db') to open the database, then call drizzle(expo) to initialize the Drizzle ORM instance.

Expo SQLite Live Queries with useLiveQuery hook

Import useLiveQuery from 'drizzle-orm/expo-sqlite'. When opening the database with openDatabaseSync, pass { enableChangeListener: true } option to enable change listeners. Wrap any Drizzle query with useLiveQuery to make it reactive; the component will re-render automatically when data changes.

Live Queries example in Expo SQLite

Example showing useLiveQuery hook usage: import { useLiveQuery, drizzle } from 'drizzle-orm/expo-sqlite'; const expo = openDatabaseSync('db.db', { enableChangeListener: true }); const db = drizzle(expo); const App = () => { const { data } = useLiveQuery(db.select().from(schema.users)); return <Text>{JSON.stringify(data)}</Text>; };

Babel plugin for Expo SQLite migrations

Install babel-plugin-inline-import to bundle SQL migration files as strings into the app bundle.

Configure babel.config.js for Expo SQLite migrations

In babel.config.js, add the inline-import plugin with configuration: plugins: [["inline-import", { "extensions": [".sql"] }]]

Configure metro.config.js for Expo SQLite migrations

In metro.config.js, add 'sql' to the resolver sourceExts array: config.resolver.sourceExts.push('sql')

Drizzle Kit config for Expo SQLite

Set dialect: 'sqlite' and driver: 'expo' in drizzle.config.ts when using Expo SQLite.

Generate Expo SQLite migrations with Drizzle Kit

After creating schema and drizzle.config.ts, run: npx drizzle-kit generate

Apply Expo SQLite migrations with useMigrations hook

Import useMigrations from 'drizzle-orm/expo-sqlite/migrator' and migrations from './drizzle/migrations'. Call useMigrations(db, migrations) in useEffect or at app startup to run migrations. It returns an object with success and error properties.

Expo SQLite migration example

Example showing useMigrations hook usage: import { useMigrations } from 'drizzle-orm/expo-sqlite/migrator'; import migrations from './drizzle/migrations'; const { success, error } = useMigrations(db, migrations); if (error) return error message; if (!success) return in-progress message; otherwise render app component.

Drizzle Expo SQLite capabilities

Drizzle ORM provides native ORM driver for Expo SQLite, Drizzle Kit support for migration generation and bundling, Drizzle Studio dev tools plugin to browse on-device database, and Live Queries functionality.

React Native SQLite driver recommendation

Use Expo SQLite to run Drizzle ORM with React Native apps. The popular react-native-sqlite-storage library does not support the new Hermes JavaScript runtime, which is the standard out-of-the-box runtime for React Native and Expo.

applying Expo SQLite migrations with drizzle-kit migrate

To apply migrations at runtime in Expo SQLite using Drizzle Kit, first generate migrations with drizzle-kit generate, then run drizzle-kit migrate with the appropriate SQLite dialect and database connection configured in drizzle.config.ts.

Give your agent this brain