UNPKG

@adonisjs/lucid

Version:

SQL ORM built on top of Active Record pattern

153 lines (152 loc) 4.76 kB
"use strict"; /* * @adonisjs/lucid * * (c) Harminder Virk <virk@adonisjs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseSqliteDialect = void 0; class BaseSqliteDialect { constructor(client, config) { Object.defineProperty(this, "client", { enumerable: true, configurable: true, writable: true, value: client }); Object.defineProperty(this, "config", { enumerable: true, configurable: true, writable: true, value: config }); Object.defineProperty(this, "supportsAdvisoryLocks", { enumerable: true, configurable: true, writable: true, value: false }); Object.defineProperty(this, "supportsViews", { enumerable: true, configurable: true, writable: true, value: true }); Object.defineProperty(this, "supportsTypes", { enumerable: true, configurable: true, writable: true, value: false }); Object.defineProperty(this, "supportsReturningStatement", { enumerable: true, configurable: true, writable: true, value: false }); /** * Reference to the database version. Knex.js fetches the version after * the first database query, so it will be set to undefined initially */ Object.defineProperty(this, "version", { enumerable: true, configurable: true, writable: true, value: this.client.getReadClient()['context']['client'].version }); /** * The default format for datetime column. The date formats is * valid for luxon date parsing library */ Object.defineProperty(this, "dateTimeFormat", { enumerable: true, configurable: true, writable: true, value: 'yyyy-MM-dd HH:mm:ss' }); } /** * Returns an array of table names */ async getAllTables() { const tables = await this.client .query() .from('sqlite_master') .select('name as table_name') .where('type', 'table') .whereNot('name', 'like', 'sqlite_%') .orderBy('name', 'asc'); return tables.map(({ table_name }) => table_name); } /** * Returns an array of all views names */ async getAllViews() { const tables = await this.client .query() .from('sqlite_master') .select('name as table_name') .where('type', 'view') .whereNot('name', 'like', 'sqlite_%') .orderBy('name', 'asc'); return tables.map(({ table_name }) => table_name); } /** * Returns an array of all types names */ async getAllTypes() { throw new Error("Sqlite doesn't support types"); } /** * Truncate SQLITE tables */ async truncate(table) { return this.client.knexQuery().table(table).truncate(); } /** * Drop all tables inside the database */ async dropAllTables() { await this.client.rawQuery('PRAGMA writable_schema = 1;'); await this.client .knexQuery() .delete() .from('sqlite_master') .whereIn('type', ['table', 'index', 'trigger']) .whereNotIn('name', this.config.wipe?.ignoreTables || []); await this.client.rawQuery('PRAGMA writable_schema = 0;'); await this.client.rawQuery('VACUUM;'); } /** * Drop all views inside the database */ async dropAllViews() { await this.client.rawQuery('PRAGMA writable_schema = 1;'); await this.client.rawQuery(`delete from sqlite_schema where type = 'view';`); await this.client.rawQuery('PRAGMA writable_schema = 0;'); await this.client.rawQuery('VACUUM;'); } /** * Drop all custom types inside the database */ async dropAllTypes() { throw new Error("Sqlite doesn't support types"); } /** * Attempts to add advisory lock to the database and * returns it's status. */ getAdvisoryLock() { throw new Error("Sqlite doesn't support advisory locks"); } /** * Releases the advisory lock */ releaseAdvisoryLock() { throw new Error("Sqlite doesn't support advisory locks"); } } exports.BaseSqliteDialect = BaseSqliteDialect;