Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Function

sqliteTable

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.

How it works

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.

Syntax

sqliteTable(name, columns)

Parameters

NameTypeDescription
namestringThe SQL table name.
columnsSQLite column definition objectAn object mapping column keys to SQLite column builders; the table must contain at least one column.

Returns

A typed SQLite table object containing the declared columns, constraints, and metadata used by Drizzle queries, migrations, and type inference.

Key points

  • Use sqliteTable to express the SQLite schema directly in TypeScript.
  • Import sqliteTable together with SQLite column builders from drizzle-orm/sqlite-core.
  • The declaration can serve as the source of truth for queries and migration generation.
  • Column object keys are the default names Drizzle uses in database queries.

Common mistakes

  • The column map cannot be empty; define at least one column.
  • Use the dialect-specific SQLite table API rather than expecting a database-agnostic table constructor.
  • SQLite schemas cannot be used to partition these table declarations across namespaces.

Example: Define a SQLite table

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.

When to use it

Declare SQLite tables

Define application persistence models in a TypeScript-first schema.

Support migrations

Generate or manage schema changes from the codebase schema.

Infer row models

Keep query results and insert payloads type-safe.

Customize table names

Avoid naming collisions in a shared database.

Interview questions

QWhat does sqliteTable do?

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.

QWhat do the arguments to sqliteTable represent?

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').

QHow can TypeScript models be inferred from a SQLite table?

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.

  • integer
  • text
  • sqliteTableCreator
  • InferSelectModel
  • InferInsertModel
  • $inferSelect
  • $inferInsert

Source: Schema - Drizzle ORM. Checked 2026-10-16.