Declare SQLite tables
Define application persistence models in a TypeScript-first schema.
Drizzle ORM · Function
sqliteTable declares a SQLite table schema in TypeScript from a table name and column definitions. The resulting typed table object is used for Drizzle queries, migrations, constraints, and inferred models.
sqliteTable declares a SQLite table in TypeScript by pairing its database name with a non-empty column definition object. Column builders specify types and constraints, while the resulting table object supplies typed schema metadata for queries and model inference.
sqliteTable(name, columns)| Name | Type | Description |
|---|---|---|
name | string | The SQL table name. |
columns | SQLite column definition object | An object mapping column keys to SQLite column builders; the table must contain at least one column. |
A typed SQLite table object containing the declared columns, constraints, and metadata used by Drizzle queries, migrations, and type inference.
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
export const users = sqliteTable("users", {
id: integer().primaryKey({ autoIncrement: true }),
name: text().notNull(),
age: integer().notNull(),
email: text().notNull().unique(),
});
type User = typeof users.$inferSelect;
type NewUser = typeof users.$inferInsert;This declaration creates a SQLite table schema with constrained columns and exposes inferred select and insert TypeScript models.
Define application persistence models in a TypeScript-first schema.
Generate or manage schema changes from the codebase schema.
Keep query results and insert payloads type-safe.
Avoid naming collisions in a shared database.
sqliteTable is the SQLite-specific schema declaration function imported from drizzle-orm/sqlite-core. It takes a table name and a column definition object, producing a typed table object used by Drizzle.
Follow-up: Why is the dialect-specific import significant? Drizzle has no common table object, so the declaration must match the database dialect in use.
The first argument is the database table name, and the second maps TypeScript property names to SQLite column builders. Builders such as integer() and text() describe columns, while methods such as primaryKey(), notNull(), and unique() add constraints.
Follow-up: How are database column names customized? Pass the desired SQL column name to a builder, such as integer('user_id').
The returned table object carries schema information for queries and type inference. Drizzle exposes inferred models through properties such as $inferSelect and $inferInsert, and equivalent InferSelectModel and InferInsertModel helpers are documented.
Follow-up: What is the distinction between the two inferred models? Select inference represents returned rows, while insert inference represents values accepted for insertion.
integertextsqliteTableCreatorInferSelectModelInferInsertModel$inferSelect$inferInsert