Skip to content

Commit 0d871b0

Browse files
authored
implement getFormatter() method (#109)
* implement getFormatter() method * 2.9.3
1 parent ec4b7c2 commit 0d871b0

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@themost/sqlite",
3-
"version": "2.9.2",
3+
"version": "2.9.3",
44
"description": "MOST Web Framework SQLite Adapter",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/SqliteAdapter.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
// MOST Web Framework Codename Zero Gravity Copyright (c) 2017-2022, THEMOST LP
33
import { DataAdapterBase, DataAdapterIndexes, DataAdapterMigration, DataAdapterTable, DataAdapterView } from '@themost/common';
4-
import { QueryExpression } from '@themost/query';
4+
import { QueryExpression, SqlFormatter } from '@themost/query';
55
import {AsyncSeriesEventEmitter} from '@themost/events';
66

77
export declare class SqliteAdapter implements DataAdapterBase {
@@ -32,4 +32,5 @@ export declare class SqliteAdapter implements DataAdapterBase {
3232
table(table: string): DataAdapterTable;
3333
view(view: string): DataAdapterView;
3434
indexes(table: string): DataAdapterIndexes;
35+
getFormatter(): SqlFormatter;
3536
}

src/SqliteAdapter.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class SqliteAdapter {
570570
return (async function() {
571571
// prepare to rename existing table and create a new one
572572
const renamed = '__' + migration.appliesTo + '_' + new Date().getTime().toString() + '__';
573-
const formatter = new SqliteFormatter();
573+
const formatter = self.getFormatter();
574574
const renameTable = formatter.escapeName(renamed);
575575
const table = formatter.escapeName(migration.appliesTo);
576576
const existingFields = await self.table(migration.appliesTo).columnsAsync();
@@ -613,7 +613,7 @@ class SqliteAdapter {
613613
});
614614
}
615615
else {
616-
const formatter = new SqliteFormatter();
616+
const formatter = self.getFormatter();
617617
migration.add.forEach(function (x) {
618618
//search for columns
619619
expressions.push(sprintf('ALTER TABLE %s ADD COLUMN %s %s', formatter.escapeName(migration.appliesTo), formatter.escapeName(x.name), self.formatType(x)));
@@ -956,8 +956,8 @@ class SqliteAdapter {
956956
return callback();
957957
}
958958
// generate SQL statement
959-
const formatter = new SqliteFormatter();
960-
const escapedTable = new SqliteFormatter().escapeName(name);
959+
const formatter = self.getFormatter();
960+
const escapedTable = formatter.escapeName(name);
961961
const sql = fields.map((field) => {
962962
const escapedField = formatter.escapeName(field.name);
963963
return sprintf('ALTER TABLE %s ADD COLUMN %s %s', escapedTable, escapedField, self.formatType(field));
@@ -1065,7 +1065,7 @@ class SqliteAdapter {
10651065
}
10661066
try {
10671067
let sql = sprintf('CREATE VIEW `%s` AS ', name);
1068-
const formatter = new SqliteFormatter();
1068+
const formatter = self.getFormatter();
10691069
sql += formatter.format(q);
10701070
self.execute(sql, undefined, tr);
10711071
}
@@ -1138,7 +1138,7 @@ class SqliteAdapter {
11381138
}
11391139
else {
11401140
//format query expression or any object that may act as query expression
1141-
const formatter = new SqliteFormatter();
1141+
const formatter = this.getFormatter();
11421142
sql = formatter.format(query);
11431143
}
11441144
//validate sql statement
@@ -1305,7 +1305,7 @@ class SqliteAdapter {
13051305
}
13061306

13071307
indexes(table) {
1308-
const self = this, formatter = new SqliteFormatter();
1308+
const self = this, formatter = this.getFormatter();
13091309
return {
13101310
list: function (callback) {
13111311
const this1 = this;
@@ -1432,7 +1432,7 @@ class SqliteAdapter {
14321432
if (!exists) {
14331433
return callback();
14341434
}
1435-
const formatter = new SqliteFormatter();
1435+
const formatter = self.getFormatter();
14361436
self.execute(sprintf('DROP INDEX %s', formatter.escapeName(name)), [], callback);
14371437
});
14381438
},
@@ -1448,6 +1448,10 @@ class SqliteAdapter {
14481448
}
14491449
};
14501450
}
1451+
1452+
getFormatter() {
1453+
return new SqliteFormatter();
1454+
}
14511455
}
14521456

14531457
export {

0 commit comments

Comments
 (0)