Tables and values
Define a SQLite schema and understand the values returned to JavaScript.
Use db.execute() or db.executeAsync() to define tables with SQL and read their rows. A table organizes records into named columns. Its schema can add constraints such as PRIMARY KEY and NOT NULL. SQLite has five storage classes: NULL, INTEGER, REAL, TEXT, and BLOB. A column's declared type influences conversion, but does not generally enforce one storage class. See SQLite's datatype guide.
Create a table and read its rows
Nitro SQLite does not define tables through a separate schema API. Send SQL to the connection:
import { open } from 'react-native-nitro-sqlite'
const db = open({ name: 'notes.sqlite' })
await db.executeAsync(`
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY,
body TEXT NOT NULL
)
`)
await db.executeAsync('INSERT INTO notes (body) VALUES (?)', ['Buy milk'])
const { rows } = await db.executeAsync<{ id: number; body: string }>(
'SELECT id, body FROM notes',
)
console.log(rows._array)
db.close()Values returned to JavaScript
The ? placeholder binds a value separately from the SQL text. The TypeScript row type describes what your code expects; it does not check the schema or convert returned values. SQLite integers and real numbers arrive as JavaScript numbers, blobs as ArrayBuffer, and nulls as null. SQLite has no separate Boolean storage class, so a bound boolean is stored as an integer and read back as a number. See parameters and results for supported values and result shapes.