vona-module-a-ormdialect 5.0.18 → 5.0.20
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/dist/.metadata/index.d.ts +22 -5
- package/dist/bean/databaseDialect.betterSqlite3.d.ts +18 -0
- package/dist/bean/databaseDialect.mysql.d.ts +5 -2
- package/dist/bean/databaseDialect.mysql3.d.ts +3 -1
- package/dist/bean/databaseDialect.pg.d.ts +5 -2
- package/dist/index.js +95 -28
- package/package.json +9 -4
|
@@ -1,37 +1,54 @@
|
|
|
1
1
|
/** databaseDialect: begin */
|
|
2
|
+
export * from '../bean/databaseDialect.betterSqlite3.ts';
|
|
2
3
|
export * from '../bean/databaseDialect.mysql.ts';
|
|
3
4
|
export * from '../bean/databaseDialect.mysql3.ts';
|
|
4
5
|
export * from '../bean/databaseDialect.pg.ts';
|
|
5
|
-
import '
|
|
6
|
-
|
|
6
|
+
import type { IDatabaseDialectOptionsBetterSqlite3 } from '../bean/databaseDialect.betterSqlite3.ts';
|
|
7
|
+
import type { IDatabaseDialectOptionsMysql } from '../bean/databaseDialect.mysql.ts';
|
|
8
|
+
import type { IDatabaseDialectOptionsMysql3 } from '../bean/databaseDialect.mysql3.ts';
|
|
9
|
+
import type { IDatabaseDialectOptionsPg } from '../bean/databaseDialect.pg.ts';
|
|
10
|
+
import 'vona-module-a-orm';
|
|
11
|
+
declare module 'vona-module-a-orm' {
|
|
7
12
|
interface IDatabaseDialectRecord {
|
|
8
|
-
'a-ormdialect:
|
|
9
|
-
'a-ormdialect:
|
|
10
|
-
'a-ormdialect:
|
|
13
|
+
'a-ormdialect:betterSqlite3': IDatabaseDialectOptionsBetterSqlite3;
|
|
14
|
+
'a-ormdialect:mysql': IDatabaseDialectOptionsMysql;
|
|
15
|
+
'a-ormdialect:mysql3': IDatabaseDialectOptionsMysql3;
|
|
16
|
+
'a-ormdialect:pg': IDatabaseDialectOptionsPg;
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
19
|
declare module 'vona-module-a-ormdialect' {
|
|
20
|
+
interface DatabaseDialectBetterSqlite3 {
|
|
21
|
+
}
|
|
22
|
+
interface DatabaseDialectBetterSqlite3 {
|
|
23
|
+
get $beanFullName(): 'a-ormdialect.databaseDialect.betterSqlite3';
|
|
24
|
+
get $onionName(): 'a-ormdialect:betterSqlite3';
|
|
25
|
+
get $onionOptions(): IDatabaseDialectOptionsBetterSqlite3;
|
|
26
|
+
}
|
|
14
27
|
interface DatabaseDialectMysql {
|
|
15
28
|
}
|
|
16
29
|
interface DatabaseDialectMysql {
|
|
17
30
|
get $beanFullName(): 'a-ormdialect.databaseDialect.mysql';
|
|
18
31
|
get $onionName(): 'a-ormdialect:mysql';
|
|
32
|
+
get $onionOptions(): IDatabaseDialectOptionsMysql;
|
|
19
33
|
}
|
|
20
34
|
interface DatabaseDialectPg {
|
|
21
35
|
}
|
|
22
36
|
interface DatabaseDialectPg {
|
|
23
37
|
get $beanFullName(): 'a-ormdialect.databaseDialect.pg';
|
|
24
38
|
get $onionName(): 'a-ormdialect:pg';
|
|
39
|
+
get $onionOptions(): IDatabaseDialectOptionsPg;
|
|
25
40
|
}
|
|
26
41
|
}
|
|
27
42
|
/** databaseDialect: end */
|
|
28
43
|
/** databaseDialect: begin */
|
|
44
|
+
import type { DatabaseDialectBetterSqlite3 } from '../bean/databaseDialect.betterSqlite3.ts';
|
|
29
45
|
import type { DatabaseDialectMysql } from '../bean/databaseDialect.mysql.ts';
|
|
30
46
|
import type { DatabaseDialectMysql3 } from '../bean/databaseDialect.mysql3.ts';
|
|
31
47
|
import type { DatabaseDialectPg } from '../bean/databaseDialect.pg.ts';
|
|
32
48
|
import 'vona';
|
|
33
49
|
declare module 'vona' {
|
|
34
50
|
interface IBeanRecordGeneral {
|
|
51
|
+
'a-ormdialect.databaseDialect.betterSqlite3': DatabaseDialectBetterSqlite3;
|
|
35
52
|
'a-ormdialect.databaseDialect.mysql': DatabaseDialectMysql;
|
|
36
53
|
'a-ormdialect.databaseDialect.mysql3': DatabaseDialectMysql3;
|
|
37
54
|
'a-ormdialect.databaseDialect.pg': DatabaseDialectPg;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { TableIdentity } from 'table-identity';
|
|
3
|
+
import type { ConfigDatabaseClient, IDatabaseDialectCapabilities, IDecoratorDatabaseDialectOptions, IFetchDatabasesResultItem, IFetchIndexesResultItem, TypeDatabaseDialectTableColumnsFn } from 'vona-module-a-orm';
|
|
4
|
+
import { BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
5
|
+
export interface IDatabaseDialectOptionsBetterSqlite3 extends IDecoratorDatabaseDialectOptions {
|
|
6
|
+
}
|
|
7
|
+
export declare class DatabaseDialectBetterSqlite3 extends BeanDatabaseDialectBase {
|
|
8
|
+
protected _capabilities: IDatabaseDialectCapabilities;
|
|
9
|
+
getConfigBase(): ConfigDatabaseClient | undefined;
|
|
10
|
+
fetchDatabases(_schemaBuilder: Knex.SchemaBuilder, databasePrefix: string): Promise<IFetchDatabasesResultItem[]>;
|
|
11
|
+
createDatabase(_schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<string>;
|
|
12
|
+
dropDatabase(_schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
13
|
+
fetchIndexes(schemaBuilder: Knex.SchemaBuilder, tableName: string): Promise<IFetchIndexesResultItem[]>;
|
|
14
|
+
insert(builder: Knex.QueryBuilder, datas: any[]): Promise<TableIdentity[]>;
|
|
15
|
+
select(builder: Knex.QueryBuilder, datas: any[], fn: TypeDatabaseDialectTableColumnsFn): Promise<any[]>;
|
|
16
|
+
query(result: any): any;
|
|
17
|
+
private _getDbDir;
|
|
18
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import type { TableIdentity } from 'table-identity';
|
|
3
|
-
import type { ConfigDatabaseClient, IFetchDatabasesResultItem, IFetchIndexesResultItem } from 'vona-module-a-orm';
|
|
3
|
+
import type { ConfigDatabaseClient, IDatabaseDialectCapabilities, IDecoratorDatabaseDialectOptions, IFetchDatabasesResultItem, IFetchIndexesResultItem } from 'vona-module-a-orm';
|
|
4
4
|
import { BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
5
|
+
export interface IDatabaseDialectOptionsMysql extends IDecoratorDatabaseDialectOptions {
|
|
6
|
+
}
|
|
5
7
|
export declare class DatabaseDialectMysql extends BeanDatabaseDialectBase {
|
|
8
|
+
protected _capabilities: IDatabaseDialectCapabilities;
|
|
6
9
|
getConfigBase(): ConfigDatabaseClient | undefined;
|
|
7
10
|
fetchDatabases(schemaBuilder: Knex.SchemaBuilder, databasePrefix: string): Promise<IFetchDatabasesResultItem[]>;
|
|
8
|
-
createDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<
|
|
11
|
+
createDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<string>;
|
|
9
12
|
dropDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
10
13
|
fetchIndexes(schemaBuilder: Knex.SchemaBuilder, tableName: string): Promise<IFetchIndexesResultItem[]>;
|
|
11
14
|
insert(builder: Knex.QueryBuilder, datas: any[]): Promise<TableIdentity[]>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { ConfigDatabaseClient } from 'vona-module-a-orm';
|
|
1
|
+
import type { ConfigDatabaseClient, IDecoratorDatabaseDialectOptions } from 'vona-module-a-orm';
|
|
2
2
|
import { DatabaseDialectMysql } from './databaseDialect.mysql.ts';
|
|
3
|
+
export interface IDatabaseDialectOptionsMysql3 extends IDecoratorDatabaseDialectOptions {
|
|
4
|
+
}
|
|
3
5
|
export declare class DatabaseDialectMysql3 extends DatabaseDialectMysql {
|
|
4
6
|
getConfigBase(): ConfigDatabaseClient | undefined;
|
|
5
7
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import type { TableIdentity } from 'table-identity';
|
|
3
|
-
import type { ConfigDatabaseClient, IFetchDatabasesResultItem, IFetchIndexesResultItem } from 'vona-module-a-orm';
|
|
3
|
+
import type { ConfigDatabaseClient, IDatabaseDialectCapabilities, IDecoratorDatabaseDialectOptions, IFetchDatabasesResultItem, IFetchIndexesResultItem } from 'vona-module-a-orm';
|
|
4
4
|
import { BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
5
|
+
export interface IDatabaseDialectOptionsPg extends IDecoratorDatabaseDialectOptions {
|
|
6
|
+
}
|
|
5
7
|
export declare class DatabaseDialectPg extends BeanDatabaseDialectBase {
|
|
8
|
+
protected _capabilities: IDatabaseDialectCapabilities;
|
|
6
9
|
getConfigBase(): ConfigDatabaseClient | undefined;
|
|
7
10
|
fetchDatabases(schemaBuilder: Knex.SchemaBuilder, databasePrefix: string): Promise<IFetchDatabasesResultItem[]>;
|
|
8
|
-
createDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<
|
|
11
|
+
createDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<string>;
|
|
9
12
|
dropDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
10
13
|
fetchIndexes(schemaBuilder: Knex.SchemaBuilder, tableName: string): Promise<IFetchIndexesResultItem[]>;
|
|
11
14
|
insert(builder: Knex.QueryBuilder, datas: any[]): Promise<TableIdentity[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,94 @@
|
|
|
1
1
|
import { BeanInfo, Virtual, BeanScopeBase } from 'vona';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ensureDir, remove } from 'fs-extra';
|
|
4
|
+
import { globby } from 'globby';
|
|
4
5
|
import { DatabaseDialect, BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
5
7
|
import { Scope } from 'vona-module-a-bean';
|
|
6
8
|
|
|
9
|
+
var _dec$4, _dec2$4, _class$4;
|
|
10
|
+
let DatabaseDialectBetterSqlite3 = (_dec$4 = DatabaseDialect(), _dec2$4 = BeanInfo({
|
|
11
|
+
module: "a-ormdialect"
|
|
12
|
+
}), _dec$4(_class$4 = _dec2$4(_class$4 = class DatabaseDialectBetterSqlite3 extends BeanDatabaseDialectBase {
|
|
13
|
+
constructor(...args) {
|
|
14
|
+
super(...args);
|
|
15
|
+
this._capabilities = {
|
|
16
|
+
ilike: false,
|
|
17
|
+
level: false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getConfigBase() {
|
|
21
|
+
return {
|
|
22
|
+
pool: {
|
|
23
|
+
afterCreate(conn, done) {
|
|
24
|
+
sqlite3_afterCreate(conn).then(done).catch(done);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async fetchDatabases(_schemaBuilder, databasePrefix) {
|
|
30
|
+
const dbDir = this._getDbDir();
|
|
31
|
+
const files = await globby(`${databasePrefix}*.db`, {
|
|
32
|
+
cwd: dbDir,
|
|
33
|
+
onlyFiles: true
|
|
34
|
+
});
|
|
35
|
+
return files.map(item => {
|
|
36
|
+
return {
|
|
37
|
+
name: path.join(dbDir, item)
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async createDatabase(_schemaBuilder, databaseName) {
|
|
42
|
+
const dbDir = this._getDbDir();
|
|
43
|
+
await ensureDir(dbDir);
|
|
44
|
+
return path.join(dbDir, `${databaseName}.db`);
|
|
45
|
+
}
|
|
46
|
+
async dropDatabase(_schemaBuilder, databaseName) {
|
|
47
|
+
await remove(databaseName);
|
|
48
|
+
for (const part of ['shm', 'wal', 'journal']) {
|
|
49
|
+
await remove(`${databaseName}-${part}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async fetchIndexes(schemaBuilder, tableName) {
|
|
53
|
+
let items = await schemaBuilder.raw(`PRAGMA index_list(${tableName})`);
|
|
54
|
+
items = items.map(item => {
|
|
55
|
+
return {
|
|
56
|
+
indexName: item.name
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
return items;
|
|
60
|
+
}
|
|
61
|
+
async insert(builder, datas) {
|
|
62
|
+
return await this.insertAsMysql(builder, datas);
|
|
63
|
+
}
|
|
64
|
+
async select(builder, datas, fn) {
|
|
65
|
+
return await this.selectAsSqlite3(builder, datas, fn);
|
|
66
|
+
}
|
|
67
|
+
query(result) {
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
_getDbDir() {
|
|
71
|
+
return path.join(this.app.projectPath, '.app/sqlite3');
|
|
72
|
+
}
|
|
73
|
+
}) || _class$4) || _class$4);
|
|
74
|
+
async function sqlite3_afterCreate(conn) {
|
|
75
|
+
const pragma = conn.pragma('journal_mode');
|
|
76
|
+
if (pragma[0]?.journal_mode?.toLocaleLowerCase() !== 'wal') {
|
|
77
|
+
conn.pragma('journal_mode = wal');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
7
81
|
var _dec$3, _dec2$3, _class$3;
|
|
8
82
|
let DatabaseDialectMysql = (_dec$3 = DatabaseDialect(), _dec2$3 = BeanInfo({
|
|
9
83
|
module: "a-ormdialect"
|
|
10
84
|
}), _dec$3(_class$3 = _dec2$3(_class$3 = class DatabaseDialectMysql extends BeanDatabaseDialectBase {
|
|
85
|
+
constructor(...args) {
|
|
86
|
+
super(...args);
|
|
87
|
+
this._capabilities = {
|
|
88
|
+
ilike: false,
|
|
89
|
+
level: true
|
|
90
|
+
};
|
|
91
|
+
}
|
|
11
92
|
getConfigBase() {
|
|
12
93
|
return {
|
|
13
94
|
pool: {
|
|
@@ -30,6 +111,7 @@ let DatabaseDialectMysql = (_dec$3 = DatabaseDialect(), _dec2$3 = BeanInfo({
|
|
|
30
111
|
}
|
|
31
112
|
async createDatabase(schemaBuilder, databaseName) {
|
|
32
113
|
await schemaBuilder.raw(`CREATE DATABASE \`${databaseName}\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci`);
|
|
114
|
+
return databaseName;
|
|
33
115
|
}
|
|
34
116
|
async dropDatabase(schemaBuilder, databaseName) {
|
|
35
117
|
await schemaBuilder.raw(`drop database \`${databaseName}\``);
|
|
@@ -45,21 +127,7 @@ let DatabaseDialectMysql = (_dec$3 = DatabaseDialect(), _dec2$3 = BeanInfo({
|
|
|
45
127
|
return items;
|
|
46
128
|
}
|
|
47
129
|
async insert(builder, datas) {
|
|
48
|
-
|
|
49
|
-
if (isNil(datas[0].id)) {
|
|
50
|
-
const ids = [];
|
|
51
|
-
for (const data of datas) {
|
|
52
|
-
const builder2 = builder.clone();
|
|
53
|
-
builder2.insert(data);
|
|
54
|
-
const items = await builder2;
|
|
55
|
-
ids.push(items[0]);
|
|
56
|
-
}
|
|
57
|
-
return ids;
|
|
58
|
-
} else {
|
|
59
|
-
builder.insert(datas);
|
|
60
|
-
await builder;
|
|
61
|
-
return datas.map(item => item.id);
|
|
62
|
-
}
|
|
130
|
+
return await this.insertAsMysql(builder, datas);
|
|
63
131
|
}
|
|
64
132
|
query(result) {
|
|
65
133
|
return result[0];
|
|
@@ -115,6 +183,13 @@ var _dec$1, _dec2$1, _class$1;
|
|
|
115
183
|
let DatabaseDialectPg = (_dec$1 = DatabaseDialect(), _dec2$1 = BeanInfo({
|
|
116
184
|
module: "a-ormdialect"
|
|
117
185
|
}), _dec$1(_class$1 = _dec2$1(_class$1 = class DatabaseDialectPg extends BeanDatabaseDialectBase {
|
|
186
|
+
constructor(...args) {
|
|
187
|
+
super(...args);
|
|
188
|
+
this._capabilities = {
|
|
189
|
+
ilike: true,
|
|
190
|
+
level: true
|
|
191
|
+
};
|
|
192
|
+
}
|
|
118
193
|
getConfigBase() {
|
|
119
194
|
return {
|
|
120
195
|
connection: {
|
|
@@ -139,6 +214,7 @@ let DatabaseDialectPg = (_dec$1 = DatabaseDialect(), _dec2$1 = BeanInfo({
|
|
|
139
214
|
}
|
|
140
215
|
async createDatabase(schemaBuilder, databaseName) {
|
|
141
216
|
await schemaBuilder.raw(`CREATE DATABASE "${databaseName}" encoding=UTF8`);
|
|
217
|
+
return databaseName;
|
|
142
218
|
}
|
|
143
219
|
async dropDatabase(schemaBuilder, databaseName) {
|
|
144
220
|
await schemaBuilder.raw(`DROP DATABASE "${databaseName}"`);
|
|
@@ -154,16 +230,7 @@ let DatabaseDialectPg = (_dec$1 = DatabaseDialect(), _dec2$1 = BeanInfo({
|
|
|
154
230
|
return items;
|
|
155
231
|
}
|
|
156
232
|
async insert(builder, datas) {
|
|
157
|
-
|
|
158
|
-
if (isNil(datas[0].id)) {
|
|
159
|
-
builder.insert(datas).returning('id');
|
|
160
|
-
const items = await builder;
|
|
161
|
-
return items.map(item => item.id);
|
|
162
|
-
} else {
|
|
163
|
-
builder.insert(datas);
|
|
164
|
-
await builder;
|
|
165
|
-
return datas.map(item => item.id);
|
|
166
|
-
}
|
|
233
|
+
return await this.insertAsPg(builder, datas);
|
|
167
234
|
}
|
|
168
235
|
query(result) {
|
|
169
236
|
return result.rows;
|
|
@@ -201,4 +268,4 @@ let ScopeModuleAOrmdialect = (_dec = Scope(), _dec2 = BeanInfo({
|
|
|
201
268
|
|
|
202
269
|
/** scope: end */
|
|
203
270
|
|
|
204
|
-
export { DatabaseDialectMysql, DatabaseDialectMysql3, DatabaseDialectPg, ScopeModuleAOrmdialect };
|
|
271
|
+
export { DatabaseDialectBetterSqlite3, DatabaseDialectMysql, DatabaseDialectMysql3, DatabaseDialectPg, ScopeModuleAOrmdialect };
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-module-a-ormdialect",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.20",
|
|
5
5
|
"title": "a-ormdialect",
|
|
6
6
|
"vonaModule": {
|
|
7
|
-
"dependencies": {}
|
|
7
|
+
"dependencies": {},
|
|
8
|
+
"globalDependencies": {
|
|
9
|
+
"better-sqlite3": true
|
|
10
|
+
}
|
|
8
11
|
},
|
|
9
12
|
"description": "",
|
|
10
13
|
"author": "",
|
|
@@ -22,10 +25,12 @@
|
|
|
22
25
|
"./package.json": "./package.json"
|
|
23
26
|
},
|
|
24
27
|
"files": [
|
|
25
|
-
"
|
|
26
|
-
"
|
|
28
|
+
"assets",
|
|
29
|
+
"dist"
|
|
27
30
|
],
|
|
28
31
|
"dependencies": {
|
|
32
|
+
"better-sqlite3": "^12.5.0",
|
|
33
|
+
"globby": "^16.0.0",
|
|
29
34
|
"mysql2": "^3.15.0",
|
|
30
35
|
"pg": "^8.16.3",
|
|
31
36
|
"pg-types": "^4.1.0"
|