UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

89 lines (88 loc) 3.96 kB
import { EnvironmentVariables } from "../runtime/types.mjs"; import { DatabaseConfig, DatabaseConnection, ExternalMigrationFn, InferredTable, KyselyDB } from "./types.mjs"; import { ColumnDataType, ColumnDefinitionBuilder } from "kysely"; import { Migration } from "kysely/migration"; import { jsonArrayFrom } from "kysely/helpers/sqlite"; //#region src/libs/db/adapter-base.d.ts declare abstract class DatabaseAdapter { adapter: string; private externalMigrations; constructor(adapter: string); /** * Returns the list of migration names that cannot be rolled back. * If migrate:rollback attempts to rollback a core migration, it will exit the process. * * For the initial release, all of these migrations are required to be run. There is no * valid version prior to this release, and as such you should never be able to rollback * the database to a previous version. */ readonly protectedMigrations: string[]; /** * Creates an initialized live connection for the supplied runtime environment. */ abstract connect(env?: EnvironmentVariables): DatabaseConnection | Promise<DatabaseConnection>; /** * Return your Kysely DB's adapters jsonArrayFrom helper that aggregates a subquery into a JSON array */ abstract get jsonArrayFrom(): typeof jsonArrayFrom; /** * Configure the features your DB supports, default values and fallback data types */ abstract get config(): DatabaseConfig; /** * Infers the database schema using the supplied connection or transaction. */ abstract inferSchema(db: KyselyDB): Promise<InferredTable[]>; /** * Drops all tables in the database */ abstract dropAllTables(connection: DatabaseConnection): Promise<void>; /** * Handles formatting of certain values based on the columns data type. This is used specifically for default values */ abstract formatDefaultValue(type: ColumnDataType, value: unknown): unknown; /** * Handles formatting of certain values based on the columns data type * - booleans are returned as either a boolean or 1/0 depending on adapter support * - json is stringified */ formatInsertValue<T>(type: ColumnDataType, value: unknown): T; /** * A helper for returning supported column data types */ getDataType(type: keyof DatabaseConfig["dataTypes"], ...args: unknown[]): ColumnDataType; /** * A helper for extending a column definition based on auto increment support */ primaryKeyColumnBuilder(col: ColumnDefinitionBuilder): ColumnDefinitionBuilder; /** * A helper for feature support */ supports(key: keyof DatabaseConfig["support"]): boolean; /** * A helper for accessing the config default values */ getDefault<T extends keyof DatabaseConfig["defaults"], K extends keyof DatabaseConfig["defaults"][T] | undefined = undefined>(type: T, key?: K): K extends keyof DatabaseConfig["defaults"][T] ? DatabaseConfig["defaults"][T][K] : DatabaseConfig["defaults"][T]; /** * Registers external (plugin/project) migrations, replacing any previously * registered set. These are merged with the core migrations. */ registerExternalMigrations(migrations: Record<string, ExternalMigrationFn>): void; /** * Runs all migrations that have not been ran yet. This doesnt include the generated migrations for collections */ migrateToLatest(connection: DatabaseConnection): Promise<void>; /** * Checks if there are any pending migrations that need to be executed */ needsMigration(db: KyselyDB): Promise<boolean>; /** * Returns the migrations for the database, including any registered external migrations. * Core names must always use a zero-padded numeric prefix - external names start with a * 13 digit timestamp so they can never clash and always sort (and run) after core migrations. */ get migrations(): Record<string, Migration>; } //#endregion export { DatabaseAdapter as default }; //# sourceMappingURL=adapter-base.d.mts.map