@egi/smart-db 2.3.2 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/drivers/smart-db-better-sqlite3.d.ts +36 -0
- package/drivers/smart-db-better-sqlite3.js +1 -0
- package/drivers/smart-db-mysql.d.ts +26 -0
- package/drivers/smart-db-mysql.js +1 -0
- package/drivers/smart-db-mysql2.d.ts +26 -0
- package/drivers/smart-db-mysql2.js +1 -0
- package/drivers/smart-db-sqlite3.d.ts +30 -0
- package/drivers/smart-db-sqlite3.js +1 -0
- package/helpers/extract-db-api.d.ts +1 -0
- package/helpers/extract-db-api.js +1 -0
- package/models/abstract-model.d.ts +22 -0
- package/models/abstract-model.js +1 -0
- package/models/smart-db-core-table-model.d.ts +35 -0
- package/models/smart-db-core-table-model.js +1 -0
- package/models/smart-db-dictionary.d.ts +13 -0
- package/models/smart-db-dictionary.js +1 -0
- package/models/smart-db-log-model.d.ts +65 -0
- package/models/smart-db-log-model.js +1 -0
- package/models/smart-db-version-model.d.ts +65 -0
- package/models/smart-db-version-model.js +1 -0
- package/models/smart-db-version-view-model.d.ts +71 -0
- package/models/smart-db-version-view-model.js +1 -0
- package/models/sqlite-master-model.d.ts +36 -0
- package/models/sqlite-master-model.js +1 -0
- package/models/sqlite-sequence-model.d.ts +24 -0
- package/models/sqlite-sequence-model.js +1 -0
- package/package.json +1 -1
- package/{src/smart-db-api.ts → smart-db-api.d.ts} +0 -3
- package/smart-db-api.js +1 -0
- package/smart-db-globals.d.ts +22 -0
- package/smart-db-globals.js +1 -0
- package/{src/smart-db-interfaces.ts → smart-db-interfaces.d.ts} +34 -82
- package/smart-db-interfaces.js +1 -0
- package/smart-db-log.d.ts +58 -0
- package/smart-db-log.js +1 -0
- package/smart-db-sql-build-data.d.ts +9 -0
- package/smart-db-sql-build-data.js +1 -0
- package/smart-db-upgrade-manager.d.ts +13 -0
- package/smart-db-upgrade-manager.js +1 -0
- package/smart-db.d.ts +67 -0
- package/smart-db.js +1 -0
- package/.eslintrc.json +0 -212
- package/README.md +0 -2
- package/bin/copy-assets +0 -6
- package/src/drivers/smart-db-better-sqlite3.ts +0 -284
- package/src/drivers/smart-db-mysql.ts +0 -159
- package/src/drivers/smart-db-mysql2.ts +0 -159
- package/src/drivers/smart-db-sqlite3.ts +0 -198
- package/src/helpers/extract-db-api.ts +0 -465
- package/src/helpers/terser-tree.ts +0 -39
- package/src/models/abstract-model.ts +0 -209
- package/src/models/smart-db-core-table-model.ts +0 -161
- package/src/models/smart-db-dictionary.ts +0 -28
- package/src/models/smart-db-log-model.ts +0 -316
- package/src/models/smart-db-version-model.ts +0 -316
- package/src/models/smart-db-version-view-model.ts +0 -347
- package/src/models/sqlite-master-model.ts +0 -140
- package/src/models/sqlite-sequence-model.ts +0 -91
- package/src/smart-db-globals.ts +0 -136
- package/src/smart-db-log.ts +0 -262
- package/src/smart-db-sql-build-data.ts +0 -28
- package/src/smart-db-upgrade-manager.ts +0 -171
- package/src/smart-db.ts +0 -854
- package/test/data/sql-engine-tests.json +0 -232
- package/test/db/mysql/database-init.sql +0 -11
- package/test/db/sqlite3/database-init.sql +0 -11
- package/test/exer.js +0 -28
- package/test/model/smart-db-dictionary.ts +0 -19
- package/test/model/test-table-model.ts +0 -214
- package/test/test.js +0 -273
- package/test/test2.js +0 -252
- package/tsconfig.json +0 -32
- package/tsconfig.pro.json +0 -32
- package/tsconfig.test-model.json +0 -23
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
|
-
|
|
3
|
-
import _ from "lodash";
|
|
4
|
-
import Mysql, {Connection, ConnectionConfig} from "mysql";
|
|
5
|
-
|
|
6
|
-
import {AbstractModel} from "../models/abstract-model";
|
|
7
|
-
import {SmartDb} from "../smart-db";
|
|
8
|
-
|
|
9
|
-
import {SmartDbSqlBuildData} from "../smart-db-sql-build-data";
|
|
10
|
-
import {AbstractModelGlobals, GenericModelData, SmartDbRunResult, SmartDbTableInfo} from "../smart-db-interfaces";
|
|
11
|
-
|
|
12
|
-
// noinspection DuplicatedCode
|
|
13
|
-
export class SmartDbMysql2 extends SmartDb {
|
|
14
|
-
protected db: Mysql.Connection;
|
|
15
|
-
|
|
16
|
-
constructor(connectorOrDb: string | ConnectionConfig | Connection) {
|
|
17
|
-
if ((<Connection>connectorOrDb).config && (<Connection>connectorOrDb).connect) {
|
|
18
|
-
super((<Connection>connectorOrDb).config);
|
|
19
|
-
this.db = connectorOrDb as Mysql.Connection;
|
|
20
|
-
} else {
|
|
21
|
-
super(connectorOrDb);
|
|
22
|
-
this.db = Mysql.createConnection(connectorOrDb as ConnectionConfig | string);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getDatabaseType(): string {
|
|
27
|
-
return "mysql";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public getDbConnector(): string | Mysql.ConnectionConfig {
|
|
31
|
-
return this.dbConnector;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public getDbQuote(): string {
|
|
35
|
-
return "`";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public hasConcurrentTransactions(): boolean {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public closeSync(): boolean {
|
|
43
|
-
throw new Error("Method not implemented.");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public exists<T extends AbstractModel<T, D>, D extends GenericModelData>(modelClass: string | (new () => T), type?: "view" | "table" | "index", indexTableName?: string): Promise<boolean> {
|
|
47
|
-
return new Promise<boolean>((resolve, reject) => {
|
|
48
|
-
const tableName = _.isString(modelClass) ? modelClass : (<AbstractModelGlobals<T, D>><unknown>modelClass).getTableName();
|
|
49
|
-
|
|
50
|
-
this.db.query(`show tables like '${tableName}'`, (error, result: any[], fields) => {
|
|
51
|
-
if (error) {
|
|
52
|
-
reject(error);
|
|
53
|
-
} else {
|
|
54
|
-
resolve(result && result.length > 0);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public existsSync<T extends AbstractModel<T, D>, D extends GenericModelData>(modelClass: string | (new () => T), type?: "view" | "table" | "index", indexTableName?: string): boolean {
|
|
61
|
-
throw new Error("Method not implemented.");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public exec(script: string): Promise<void> {
|
|
65
|
-
return new Promise<void>((resolve, reject) => {
|
|
66
|
-
try {
|
|
67
|
-
this.db.query(script, (error, result, fields) => {
|
|
68
|
-
if (error) {
|
|
69
|
-
reject(error);
|
|
70
|
-
} else {
|
|
71
|
-
resolve();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
} catch (err) {
|
|
75
|
-
reject(err);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public execSync(script: string): boolean {
|
|
81
|
-
throw new Error("Method not implemented.");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public getTableInfo(table: string): Promise<SmartDbTableInfo> {
|
|
85
|
-
return new Promise<SmartDbTableInfo>((resolve, reject) => {
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
protected statementGet(buildData: SmartDbSqlBuildData): Promise<any> {
|
|
91
|
-
return new Promise<any>((resolve, reject) => {
|
|
92
|
-
try {
|
|
93
|
-
this.db.query(buildData.sql, buildData.values, (error, rows, fields) => {
|
|
94
|
-
if (error) {
|
|
95
|
-
reject(error);
|
|
96
|
-
} else {
|
|
97
|
-
resolve(rows && rows[0]);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
} catch (err) {
|
|
101
|
-
reject(err);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
protected statementGetSync(buildData: SmartDbSqlBuildData): any {
|
|
107
|
-
throw new Error("Method not implemented.");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
protected statementGetAll(buildData: SmartDbSqlBuildData): Promise<any[]> {
|
|
111
|
-
return new Promise<any[]>((resolve, reject) => {
|
|
112
|
-
this.db.query(buildData.sql, buildData.values, (error, rows, fields) => {
|
|
113
|
-
if (error) {
|
|
114
|
-
reject(error);
|
|
115
|
-
} else {
|
|
116
|
-
console.log(fields);
|
|
117
|
-
resolve(rows && rows);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
protected statementGetAllSync(buildData: SmartDbSqlBuildData): any[] {
|
|
124
|
-
throw new Error("Method not implemented.");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected statementRun(buildData: SmartDbSqlBuildData): Promise<SmartDbRunResult> {
|
|
128
|
-
return new Promise<SmartDbRunResult>((resolve, reject) => {
|
|
129
|
-
this.db.query(buildData.sql, buildData.values, (error, results, fields) => {
|
|
130
|
-
if (error) {
|
|
131
|
-
reject(error);
|
|
132
|
-
} else {
|
|
133
|
-
const runResult: SmartDbRunResult = {
|
|
134
|
-
changes: results.changedRows,
|
|
135
|
-
affected: results.affectedRows,
|
|
136
|
-
lastId: results.insertId
|
|
137
|
-
};
|
|
138
|
-
resolve(runResult);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
protected statementRunSync(buildData: SmartDbSqlBuildData): SmartDbRunResult {
|
|
145
|
-
throw new Error("Method not implemented.");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public close(): Promise<void> {
|
|
149
|
-
return new Promise<void>((resolve, reject) => {
|
|
150
|
-
this.db.end((err) => {
|
|
151
|
-
if (err) {
|
|
152
|
-
reject(err);
|
|
153
|
-
} else {
|
|
154
|
-
resolve();
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
|
-
|
|
3
|
-
import _ from "lodash";
|
|
4
|
-
import Sqlite3 from "sqlite3";
|
|
5
|
-
|
|
6
|
-
import {AbstractModel} from "../models/abstract-model";
|
|
7
|
-
import {SqliteMasterModel} from "../models/sqlite-master-model";
|
|
8
|
-
import {SmartDb} from "../smart-db";
|
|
9
|
-
import {AbstractModelGlobals, GenericModelData, SmartDbConnector, SmartDbRunResult, SmartDbTableInfo} from "../smart-db-interfaces";
|
|
10
|
-
import {SmartDbSqlBuildData} from "../smart-db-sql-build-data";
|
|
11
|
-
|
|
12
|
-
export interface SmartDbSqlite3Options {
|
|
13
|
-
mode?: number;
|
|
14
|
-
callback?: (this: Sqlite3.Database, err: Error | null) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// noinspection DuplicatedCode
|
|
18
|
-
export class SmartDbSqlite3 extends SmartDb {
|
|
19
|
-
protected db: Sqlite3.Database;
|
|
20
|
-
|
|
21
|
-
constructor(connectorOrDb: string | Sqlite3.Database, options?: SmartDbSqlite3Options) {
|
|
22
|
-
if (_.isString(connectorOrDb)) {
|
|
23
|
-
super(connectorOrDb);
|
|
24
|
-
this.db = new Sqlite3.Database(connectorOrDb, options && options.mode, options && options.callback);
|
|
25
|
-
} else {
|
|
26
|
-
super(null);
|
|
27
|
-
this.db = connectorOrDb;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public getDatabaseType(): string {
|
|
32
|
-
return "sqlite3";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public getDbConnector(): string | SmartDbConnector {
|
|
36
|
-
return this.dbConnector;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public getDbQuote(): string {
|
|
40
|
-
return "\"";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public hasConcurrentTransactions(): boolean {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// noinspection JSUnusedGlobalSymbols
|
|
48
|
-
public exists<T extends AbstractModel<T, D>, D extends GenericModelData>(modelClass: string | (new () => T), type?: "view" | "table" | "index", indexTableName?: string): Promise<boolean> {
|
|
49
|
-
return new Promise<boolean>((resolve, reject) => {
|
|
50
|
-
try {
|
|
51
|
-
const tableName = _.isString(modelClass) ? modelClass : (<AbstractModelGlobals<T, D>><unknown>modelClass).getTableName();
|
|
52
|
-
|
|
53
|
-
this.getFirst(SqliteMasterModel, {
|
|
54
|
-
name: tableName,
|
|
55
|
-
type: type,
|
|
56
|
-
tblName: indexTableName
|
|
57
|
-
}).then((rows) => {
|
|
58
|
-
if (rows === null) {
|
|
59
|
-
reject(this.getLastError());
|
|
60
|
-
} else {
|
|
61
|
-
resolve(!!rows);
|
|
62
|
-
}
|
|
63
|
-
}).catch((err) => {
|
|
64
|
-
reject(err);
|
|
65
|
-
});
|
|
66
|
-
} catch (err) {
|
|
67
|
-
reject(err);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public existsSync<T extends AbstractModel<T, D>, D extends GenericModelData>(modelClass: string | (new () => T), type?: "view" | "table" | "index", indexTableName?: string): boolean {
|
|
73
|
-
throw new Error("Method not implemented.");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public exec(script: string): Promise<void> {
|
|
77
|
-
return new Promise<void>((resolve, reject) => {
|
|
78
|
-
try {
|
|
79
|
-
this.db.exec(script, function (err) {
|
|
80
|
-
if (err) {
|
|
81
|
-
reject(err);
|
|
82
|
-
} else {
|
|
83
|
-
resolve();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
} catch (err) {
|
|
87
|
-
reject(err);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public execSync(script: string): Sqlite3.Database | false {
|
|
93
|
-
throw new Error("Method not implemented.");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// noinspection JSUnusedGlobalSymbols
|
|
97
|
-
public closeSync(): boolean {
|
|
98
|
-
throw new Error("Method not implemented.");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public getTableInfo(table: string): Promise<SmartDbTableInfo> {
|
|
102
|
-
throw new Error("Method not implemented.");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
protected statementRun(buildData: SmartDbSqlBuildData): Promise<SmartDbRunResult> {
|
|
106
|
-
return new Promise<SmartDbRunResult>((resolve, reject) => {
|
|
107
|
-
try {
|
|
108
|
-
this.db.run(buildData.sql, buildData.values, function (err: Error | null) {
|
|
109
|
-
if (err) {
|
|
110
|
-
reject(err);
|
|
111
|
-
} else {
|
|
112
|
-
resolve({
|
|
113
|
-
changes: this.changes,
|
|
114
|
-
affected: this.changes,
|
|
115
|
-
lastId: this.lastID
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
} catch (err) {
|
|
120
|
-
reject(err);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
protected statementRunSync(buildData: SmartDbSqlBuildData): SmartDbRunResult {
|
|
126
|
-
throw new Error("Method not implemented.");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
protected statementGet(buildData: SmartDbSqlBuildData): Promise<any> {
|
|
130
|
-
return new Promise<any>((resolve, reject) => {
|
|
131
|
-
try {
|
|
132
|
-
this.db.prepare(buildData.sql, function (err: Error | null) {
|
|
133
|
-
if (err) {
|
|
134
|
-
reject(err);
|
|
135
|
-
} else {
|
|
136
|
-
this.get(buildData.values, function (err, row) {
|
|
137
|
-
if (err) {
|
|
138
|
-
reject(err);
|
|
139
|
-
} else {
|
|
140
|
-
resolve(row);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
} catch (err) {
|
|
146
|
-
reject(err);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
protected statementGetSync(buildData: SmartDbSqlBuildData) {
|
|
152
|
-
throw new Error("Method not implemented.");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
protected statementGetAll(buildData: SmartDbSqlBuildData): Promise<any[]> {
|
|
156
|
-
return new Promise<any[]>((resolve, reject) => {
|
|
157
|
-
try {
|
|
158
|
-
this.db.prepare(buildData.sql, function (err: Error | null) {
|
|
159
|
-
if (err) {
|
|
160
|
-
reject(err);
|
|
161
|
-
} else {
|
|
162
|
-
this.all(buildData.values, function (err, rows) {
|
|
163
|
-
if (err) {
|
|
164
|
-
reject(err);
|
|
165
|
-
} else {
|
|
166
|
-
resolve(rows);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
} catch (err) {
|
|
172
|
-
reject(err);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
protected statementGetAllSync(buildData: SmartDbSqlBuildData): any[] {
|
|
178
|
-
throw new Error("Method not implemented.");
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// noinspection JSUnusedGlobalSymbols
|
|
182
|
-
public close(): Promise<void> {
|
|
183
|
-
return new Promise<void>((resolve, reject) => {
|
|
184
|
-
try {
|
|
185
|
-
this.smartDbLog.setDb(null);
|
|
186
|
-
this.db.close(function (err) {
|
|
187
|
-
if (err) {
|
|
188
|
-
reject(err);
|
|
189
|
-
} else {
|
|
190
|
-
resolve();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
} catch (err) {
|
|
194
|
-
reject(err);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|