import type { Client, ResultSet } from '@libsql/client'; import type { DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm'; import type { DrizzleD1Database } from 'drizzle-orm/d1'; import type { LibSQLDatabase } from 'drizzle-orm/libsql'; import type { AnySQLiteColumn, SQLiteColumn, SQLiteInsertOnConflictDoUpdateConfig, SQLiteTableWithColumns, SQLiteTransactionConfig } from 'drizzle-orm/sqlite-core'; import type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw'; import type { Payload, PayloadRequest } from 'payload'; import type { Operators } from '../queries/operatorMap.js'; import type { BuildQueryJoinAliases, DrizzleAdapter } from '../types.js'; import type { extendDrizzleTable } from '../utilities/extendDrizzleTable.js'; type SQLiteSchema = { relations: Record; tables: Record>; }; type SQLiteSchemaHookArgs = { extendTable: typeof extendDrizzleTable; schema: SQLiteSchema; }; export type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise | SQLiteSchema; export type BaseSQLiteArgs = { /** * Transform the schema after it's built. * You can use it to customize the schema with features that aren't supported by Payload. * Examples may include: composite indices, generated columns, vectors */ afterSchemaInit?: SQLiteSchemaHook[]; /** * Enable this flag if you want to thread your own ID to create operation data, for example: * ```ts * // doc created with id 1 * const doc = await payload.create({ collection: 'posts', data: {id: 1, title: "my title"}}) * ``` */ allowIDOnCreate?: boolean; /** * Enable [AUTOINCREMENT](https://www.sqlite.org/autoinc.html) for Primary Keys. * This ensures that the same ID cannot be reused from previously deleted rows. */ autoIncrement?: boolean; /** * Transform the schema before it's built. * You can use it to preserve an existing database schema and if there are any collissions Payload will override them. * To generate Drizzle schema from the database, see [Drizzle Kit introspection](https://orm.drizzle.team/kit-docs/commands#introspect--pull) */ beforeSchemaInit?: SQLiteSchemaHook[]; /** * Store blocks as JSON column instead of storing them in a relational structure. */ blocksAsJSON?: boolean; /** Generated schema from payload generate:db-schema file path */ generateSchemaOutputFile?: string; idType?: 'number' | 'uuid'; localesSuffix?: string; logger?: DrizzleConfig['logger']; migrationDir?: string; prodMigrations?: { down: (args: MigrateDownArgs) => Promise; name: string; up: (args: MigrateUpArgs) => Promise; }[]; push?: boolean; relationshipsSuffix?: string; schemaName?: string; transactionOptions?: false | SQLiteTransactionConfig; versionsSuffix?: string; }; export type GenericColumns = { [x: string]: AnySQLiteColumn; }; export type GenericTable = SQLiteTableWithColumns<{ columns: GenericColumns; dialect: string; name: string; schema: string; }>; export type GenericRelation = Relations>>; export type CountDistinct = (args: { column?: SQLiteColumn; db: LibSQLDatabase; joins: BuildQueryJoinAliases; tableName: string; where: SQL; }) => Promise; export type DeleteWhere = (args: { db: LibSQLDatabase; tableName: string; where: SQL; }) => Promise; export type DropDatabase = (args: { adapter: BaseSQLiteAdapter; }) => Promise; export type Execute = (args: { db?: DrizzleD1Database | LibSQLDatabase; drizzle?: DrizzleD1Database | LibSQLDatabase; raw?: string; sql?: SQL; }) => SQLiteRaw> | SQLiteRaw; export type Insert = (args: { db: LibSQLDatabase; onConflictDoUpdate?: SQLiteInsertOnConflictDoUpdateConfig; tableName: string; values: Record | Record[]; }) => Promise[]>; type SQLiteDrizzleAdapter = Omit; export interface GeneratedDatabaseSchema { schemaUntyped: Record; } type ResolveSchemaType = 'schema' extends keyof T ? T['schema'] : GeneratedDatabaseSchema['schemaUntyped']; type Drizzle = { $client: Client; } & LibSQLDatabase>; export type BaseSQLiteAdapter = { afterSchemaInit: SQLiteSchemaHook[]; autoIncrement: boolean; beforeSchemaInit: SQLiteSchemaHook[]; client: Client; countDistinct: CountDistinct; defaultDrizzleSnapshot: any; deleteWhere: DeleteWhere; dropDatabase: DropDatabase; execute: Execute; /** * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name * Used for returning properly formed errors from unique fields */ fieldConstraints: Record>; idType: BaseSQLiteArgs['idType']; initializing: Promise; insert: Insert; localesSuffix?: string; logger: DrizzleConfig['logger']; operators: Operators; prodMigrations?: { down: (args: MigrateDownArgs) => Promise; name: string; up: (args: MigrateUpArgs) => Promise; }[]; push: boolean; rejectInitializing: () => void; relations: Record; relationshipsSuffix?: string; resolveInitializing: () => void; schema: Record; schemaName?: BaseSQLiteArgs['schemaName']; tableNameMap: Map; tables: Record; transactionOptions: SQLiteTransactionConfig; versionsSuffix?: string; } & SQLiteDrizzleAdapter; export type IDType = 'integer' | 'numeric' | 'text'; export type MigrateUpArgs = { /** * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction. * @example * ```ts * import { type MigrateUpArgs, sql } from '@payloadcms/db-sqlite' * * export async function up({ db, payload, req }: MigrateUpArgs): Promise { * const { rows: posts } = await db.run(sql`SELECT * FROM posts`) * } * ``` */ db: Drizzle; /** * The Payload instance that you can use to execute Local API methods * To use the current transaction you must pass `req` to arguments * @example * ```ts * import { type MigrateUpArgs } from '@payloadcms/db-sqlite' * * export async function up({ db, payload, req }: MigrateUpArgs): Promise { * const posts = await payload.find({ collection: 'posts', req }) * } * ``` */ payload: Payload; /** * The `PayloadRequest` object that contains the current transaction */ req: PayloadRequest; }; export type MigrateDownArgs = { /** * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction. * @example * ```ts * import { type MigrateDownArgs, sql } from '@payloadcms/db-sqlite' * * export async function down({ db, payload, req }: MigrateDownArgs): Promise { * const { rows: posts } = await db.run(sql`SELECT * FROM posts`) * } * ``` */ db: Drizzle; /** * The Payload instance that you can use to execute Local API methods * To use the current transaction you must pass `req` to arguments * @example * ```ts * import { type MigrateDownArgs } from '@payloadcms/db-sqlite' * * export async function down({ db, payload, req }: MigrateDownArgs): Promise { * const posts = await payload.find({ collection: 'posts', req }) * } * ``` */ payload: Payload; /** * The `PayloadRequest` object that contains the current transaction */ req: PayloadRequest; }; export {}; //# sourceMappingURL=types.d.ts.map