Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
214 lines
8.0 KiB
Plaintext
214 lines
8.0 KiB
Plaintext
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<string, GenericRelation>;
|
|
tables: Record<string, SQLiteTableWithColumns<any>>;
|
|
};
|
|
type SQLiteSchemaHookArgs = {
|
|
extendTable: typeof extendDrizzleTable;
|
|
schema: SQLiteSchema;
|
|
};
|
|
export type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise<SQLiteSchema> | 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<void>;
|
|
name: string;
|
|
up: (args: MigrateUpArgs) => Promise<void>;
|
|
}[];
|
|
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<string, Record<string, Relation<string>>>;
|
|
export type CountDistinct = (args: {
|
|
column?: SQLiteColumn<any>;
|
|
db: LibSQLDatabase;
|
|
joins: BuildQueryJoinAliases;
|
|
tableName: string;
|
|
where: SQL;
|
|
}) => Promise<number>;
|
|
export type DeleteWhere = (args: {
|
|
db: LibSQLDatabase;
|
|
tableName: string;
|
|
where: SQL;
|
|
}) => Promise<void>;
|
|
export type DropDatabase = (args: {
|
|
adapter: BaseSQLiteAdapter;
|
|
}) => Promise<void>;
|
|
export type Execute<T> = (args: {
|
|
db?: DrizzleD1Database | LibSQLDatabase;
|
|
drizzle?: DrizzleD1Database | LibSQLDatabase;
|
|
raw?: string;
|
|
sql?: SQL<unknown>;
|
|
}) => SQLiteRaw<Promise<T>> | SQLiteRaw<ResultSet>;
|
|
export type Insert = (args: {
|
|
db: LibSQLDatabase;
|
|
onConflictDoUpdate?: SQLiteInsertOnConflictDoUpdateConfig<any>;
|
|
tableName: string;
|
|
values: Record<string, unknown> | Record<string, unknown>[];
|
|
}) => Promise<Record<string, unknown>[]>;
|
|
type SQLiteDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'idType' | 'insert' | 'operators' | 'relations'>;
|
|
export interface GeneratedDatabaseSchema {
|
|
schemaUntyped: Record<string, unknown>;
|
|
}
|
|
type ResolveSchemaType<T> = 'schema' extends keyof T ? T['schema'] : GeneratedDatabaseSchema['schemaUntyped'];
|
|
type Drizzle = {
|
|
$client: Client;
|
|
} & LibSQLDatabase<ResolveSchemaType<GeneratedDatabaseSchema>>;
|
|
export type BaseSQLiteAdapter = {
|
|
afterSchemaInit: SQLiteSchemaHook[];
|
|
autoIncrement: boolean;
|
|
beforeSchemaInit: SQLiteSchemaHook[];
|
|
client: Client;
|
|
countDistinct: CountDistinct;
|
|
defaultDrizzleSnapshot: any;
|
|
deleteWhere: DeleteWhere;
|
|
dropDatabase: DropDatabase;
|
|
execute: Execute<unknown>;
|
|
/**
|
|
* 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<string, Record<string, string>>;
|
|
idType: BaseSQLiteArgs['idType'];
|
|
initializing: Promise<void>;
|
|
insert: Insert;
|
|
localesSuffix?: string;
|
|
logger: DrizzleConfig['logger'];
|
|
operators: Operators;
|
|
prodMigrations?: {
|
|
down: (args: MigrateDownArgs) => Promise<void>;
|
|
name: string;
|
|
up: (args: MigrateUpArgs) => Promise<void>;
|
|
}[];
|
|
push: boolean;
|
|
rejectInitializing: () => void;
|
|
relations: Record<string, GenericRelation>;
|
|
relationshipsSuffix?: string;
|
|
resolveInitializing: () => void;
|
|
schema: Record<string, GenericRelation | GenericTable>;
|
|
schemaName?: BaseSQLiteArgs['schemaName'];
|
|
tableNameMap: Map<string, string>;
|
|
tables: Record<string, GenericTable>;
|
|
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<void> {
|
|
* 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<void> {
|
|
* 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<void> {
|
|
* 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<void> {
|
|
* 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 |