The officially supported SQLite database adapter for PayloadCMS with Drizzle ORM integration.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive configuration options for the SQLite adapter, enabling fine-grained control over database behavior, schema generation, and integration with Payload's features.
Creates a configured SQLite database adapter for PayloadCMS.
/**
* Creates a SQLite database adapter for PayloadCMS
* @param args - Configuration options for the adapter
* @returns DatabaseAdapterObj with SQLite-specific functionality
*/
function sqliteAdapter(args: SQLiteAdapterArgs): DatabaseAdapterObj<SQLiteAdapter>;Usage Examples:
import { sqliteAdapter } from '@payloadcms/db-sqlite';
// Basic configuration
const adapter = sqliteAdapter({
client: {
url: './payload.db',
},
});
// Advanced configuration with UUID IDs
const advancedAdapter = sqliteAdapter({
client: {
url: process.env.DATABASE_URL,
authToken: process.env.DATABASE_AUTH_TOKEN, // For Turso/LibSQL
},
idType: 'uuid',
allowIDOnCreate: true,
autoIncrement: true,
blocksAsJSON: true,
localesSuffix: '_locale',
relationshipsSuffix: '_rel',
versionsSuffix: '_version',
});Configure the LibSQL client connection settings.
interface ClientConfig {
/** Database URL - file path for local SQLite, connection string for remote */
url: string;
/** Authentication token for remote LibSQL databases (Turso) */
authToken?: string;
/** Additional client configuration options */
[key: string]: any;
}Usage Examples:
// Local SQLite file
const localConfig = {
client: {
url: './data/payload.db',
},
};
// Turso (LibSQL) remote database
const tursoConfig = {
client: {
url: 'libsql://your-database.turso.io',
authToken: process.env.TURSO_AUTH_TOKEN,
},
};
// In-memory database (development/testing)
const memoryConfig = {
client: {
url: ':memory:',
},
};Configure how primary keys are generated and managed.
/**
* ID type configuration options
* @typedef {'number' | 'uuid'} IDType
*/
interface IDConfiguration {
/** Primary key type - 'number' for integers, 'uuid' for UUID strings */
idType?: 'number' | 'uuid';
/** Allow custom ID specification during document creation */
allowIDOnCreate?: boolean;
/** Enable AUTOINCREMENT for integer IDs to prevent reuse */
autoIncrement?: boolean;
}Usage Examples:
// Numeric IDs with auto-increment (default)
const numericIds = sqliteAdapter({
client: { url: './payload.db' },
idType: 'number',
autoIncrement: true,
});
// UUID IDs with custom ID support
const uuidIds = sqliteAdapter({
client: { url: './payload.db' },
idType: 'uuid',
allowIDOnCreate: true,
});Configure schema generation and table naming conventions.
interface SchemaConfiguration {
/** Store blocks as JSON columns instead of normalized tables */
blocksAsJSON?: boolean;
/** Custom suffix for locale tables (default: '_locales') */
localesSuffix?: string;
/** Custom suffix for relationship tables (default: '_rels') */
relationshipsSuffix?: string;
/** Custom suffix for version tables (default: '_v') */
versionsSuffix?: string;
/** Schema name for namespaced databases */
schemaName?: string;
/** Output file path for generated schema code */
generateSchemaOutputFile?: string;
}Usage Examples:
const customSchema = sqliteAdapter({
client: { url: './payload.db' },
blocksAsJSON: true, // Store complex blocks as JSON
localesSuffix: '_translations',
relationshipsSuffix: '_relationships',
versionsSuffix: '_versions',
generateSchemaOutputFile: './src/db/schema.ts',
});Configure SQLite transaction behavior and isolation levels.
interface TransactionConfiguration {
/** Transaction options - false to disable, object for configuration */
transactionOptions?: false | SQLiteTransactionConfig;
}
interface SQLiteTransactionConfig {
/** Transaction mode */
mode?: 'deferred' | 'immediate' | 'exclusive';
/** Additional transaction options */
[key: string]: any;
}Usage Examples:
// Default transactions
const defaultTx = sqliteAdapter({
client: { url: './payload.db' },
// transactionOptions not specified - uses defaults
});
// Disabled transactions
const noTx = sqliteAdapter({
client: { url: './payload.db' },
transactionOptions: false,
});
// Custom transaction mode
const customTx = sqliteAdapter({
client: { url: './payload.db' },
transactionOptions: {
mode: 'immediate',
},
});Transform the database schema before and after Payload's schema generation.
type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise<SQLiteSchema> | SQLiteSchema;
interface SQLiteSchemaHookArgs {
/** Function to extend existing table definitions */
extendTable: typeof extendDrizzleTable;
/** Current schema state with tables and relations */
schema: SQLiteSchema;
}
interface SQLiteSchema {
/** Database relations */
relations: Record<string, GenericRelation>;
/** Database tables */
tables: Record<string, SQLiteTableWithColumns<any>>;
}
interface SchemaHookConfiguration {
/** Hooks executed before Payload's schema generation */
beforeSchemaInit?: SQLiteSchemaHook[];
/** Hooks executed after Payload's schema generation */
afterSchemaInit?: SQLiteSchemaHook[];
}Usage Examples:
const withHooks = sqliteAdapter({
client: { url: './payload.db' },
beforeSchemaInit: [
// Add custom tables before Payload generates its schema
({ schema, extendTable }) => {
return {
...schema,
tables: {
...schema.tables,
customTable: sqliteTable('custom', {
id: integer('id').primaryKey(),
data: text('data'),
}),
},
};
},
],
afterSchemaInit: [
// Modify Payload tables after generation
({ schema, extendTable }) => {
const usersTable = schema.tables.users;
if (usersTable) {
// Add custom column to users table
return extendTable(usersTable, {
customField: text('custom_field'),
});
}
return schema;
},
],
});Configuration options for development workflows and debugging.
interface DevelopmentConfiguration {
/** Drizzle ORM logger for SQL query debugging */
logger?: DrizzleConfig['logger'];
/** Enable schema push mode for development */
push?: boolean;
}Usage Examples:
// Development configuration with logging
const devAdapter = sqliteAdapter({
client: { url: './payload.db' },
logger: true, // Log all SQL queries
push: true, // Enable schema push mode
});
// Custom logger
const customLogger = sqliteAdapter({
client: { url: './payload.db' },
logger: {
logQuery: (query, params) => {
console.log('SQL:', query);
console.log('Params:', params);
},
},
});Install with Tessl CLI
npx tessl i tessl/npm-payloadcms--db-sqlite