UNPKG

2.99 kBJavaScriptView Raw
1"use strict";
2/*
3 * @adonisjs/lucid
4 *
5 * (c) Harminder Virk <virk@adonisjs.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10Object.defineProperty(exports, "__esModule", { value: true });
11exports.SqliteDialect = void 0;
12class SqliteDialect {
13 constructor(client) {
14 Object.defineProperty(this, "client", {
15 enumerable: true,
16 configurable: true,
17 writable: true,
18 value: client
19 });
20 Object.defineProperty(this, "name", {
21 enumerable: true,
22 configurable: true,
23 writable: true,
24 value: 'sqlite3'
25 });
26 Object.defineProperty(this, "supportsAdvisoryLocks", {
27 enumerable: true,
28 configurable: true,
29 writable: true,
30 value: false
31 });
32 /**
33 * Reference to the database version. Knex.js fetches the version after
34 * the first database query, so it will be set to undefined initially
35 */
36 Object.defineProperty(this, "version", {
37 enumerable: true,
38 configurable: true,
39 writable: true,
40 value: this.client.getReadClient()['context']['client'].version
41 });
42 /**
43 * The default format for datetime column. The date formats is
44 * valid for luxon date parsing library
45 */
46 Object.defineProperty(this, "dateTimeFormat", {
47 enumerable: true,
48 configurable: true,
49 writable: true,
50 value: 'yyyy-MM-dd HH:mm:ss'
51 });
52 }
53 /**
54 * Returns an array of table names
55 */
56 async getAllTables() {
57 const tables = await this.client
58 .query()
59 .from('sqlite_master')
60 .select('name as table_name')
61 .where('type', 'table')
62 .whereNot('name', 'like', 'sqlite_%')
63 .orderBy('name', 'asc');
64 return tables.map(({ table_name }) => table_name);
65 }
66 /**
67 * Truncate SQLITE tables
68 */
69 async truncate(table, _) {
70 return this.client.knexQuery().table(table).truncate();
71 }
72 /**
73 * Drop all tables inside the database
74 */
75 async dropAllTables() {
76 await this.client.rawQuery('PRAGMA writable_schema = 1;');
77 await this.client.rawQuery(`delete from sqlite_master where type in ('table', 'index', 'trigger');`);
78 await this.client.rawQuery('PRAGMA writable_schema = 0;');
79 await this.client.rawQuery('VACUUM;');
80 }
81 /**
82 * Attempts to add advisory lock to the database and
83 * returns it's status.
84 */
85 getAdvisoryLock() {
86 throw new Error("Sqlite doesn't support advisory locks");
87 }
88 /**
89 * Releases the advisory lock
90 */
91 releaseAdvisoryLock() {
92 throw new Error("Sqlite doesn't support advisory locks");
93 }
94}
95exports.SqliteDialect = SqliteDialect;