UNPKG

@adonisjs/lucid

Version:

SQL ORM built on top of Active Record pattern

68 lines (67 loc) • 2.35 kB
import type { ConnectionConfig } from '../types/database.js'; /** * Database administrator performs database level operations like creating * or dropping a database. * * Since the database in question may not exist yet, we cannot use the * regular lucid connections that are bound to the database defined * inside the config file. Instead, we create a standalone knex * connection to the maintenance database of the dialect and * delegate the dialect specific bits to the dialect * "administration" implementation. */ export declare class DatabaseAdministrator { #private; constructor(config: ConnectionConfig); /** * A boolean to know if the connection uses a file backed * database like sqlite or libsql */ private usesFileDatabase; /** * Returns the connection node after giving preference to the * write replica connection (when replicas are in use) */ private resolveConnectionNode; /** * Returns the path to the database file for file backed databases */ private fileDatabasePath; /** * Returns the connection node pointing to the maintenance database * of the dialect. "CREATE DATABASE" and "DROP DATABASE" queries * cannot run over a connection attached to the database in * question */ private getMaintenanceConnection; /** * Lazily instantiates the knex connection to the maintenance * database. For file backed databases, the connection points * to the database file itself */ private getClient; /** * Returns the database name (the file path for file backed databases) * resolved from the connection config */ get databaseName(): string; /** * Returns a boolean to know if the database already exists */ databaseExists(): Promise<boolean>; /** * Creates the database. For file backed databases, the database * file is created (alongside missing intermediate directories) */ createDatabase(): Promise<void>; /** * Drops the database. For file backed databases, the database * file is removed from the disk */ dropDatabase(): Promise<void>; /** * Closes the connection to the maintenance database. The instance * cannot be used after calling this method */ disconnect(): Promise<void>; }