vona-module-a-ormdialect 5.0.13 → 5.0.15
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TableIdentity } from 'table-identity';
|
|
3
|
+
import type { ConfigDatabaseClient, IFetchDatabasesResultItem, IFetchIndexesResultItem } from 'vona-module-a-orm';
|
|
3
4
|
import { BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
4
5
|
export declare class DatabaseDialectMysql extends BeanDatabaseDialectBase {
|
|
5
6
|
getConfigBase(): ConfigDatabaseClient | undefined;
|
|
@@ -7,7 +8,7 @@ export declare class DatabaseDialectMysql extends BeanDatabaseDialectBase {
|
|
|
7
8
|
createDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
8
9
|
dropDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
9
10
|
fetchIndexes(schemaBuilder: Knex.SchemaBuilder, tableName: string): Promise<IFetchIndexesResultItem[]>;
|
|
10
|
-
insert(builder: Knex.QueryBuilder): Promise<TableIdentity[]>;
|
|
11
|
+
insert(builder: Knex.QueryBuilder, datas: any[]): Promise<TableIdentity[]>;
|
|
11
12
|
query(result: any): any;
|
|
12
13
|
viewDependents(builder: Knex.QueryBuilder, viewName: string): Promise<string[]>;
|
|
13
14
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TableIdentity } from 'table-identity';
|
|
3
|
+
import type { ConfigDatabaseClient, IFetchDatabasesResultItem, IFetchIndexesResultItem } from 'vona-module-a-orm';
|
|
3
4
|
import { BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
4
5
|
export declare class DatabaseDialectPg extends BeanDatabaseDialectBase {
|
|
5
6
|
getConfigBase(): ConfigDatabaseClient | undefined;
|
|
@@ -7,7 +8,7 @@ export declare class DatabaseDialectPg extends BeanDatabaseDialectBase {
|
|
|
7
8
|
createDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
8
9
|
dropDatabase(schemaBuilder: Knex.SchemaBuilder, databaseName: string): Promise<void>;
|
|
9
10
|
fetchIndexes(schemaBuilder: Knex.SchemaBuilder, tableName: string): Promise<IFetchIndexesResultItem[]>;
|
|
10
|
-
insert(builder: Knex.QueryBuilder): Promise<TableIdentity[]>;
|
|
11
|
+
insert(builder: Knex.QueryBuilder, datas: any[]): Promise<TableIdentity[]>;
|
|
11
12
|
query(result: any): any;
|
|
12
13
|
viewDependents(builder: Knex.QueryBuilder, viewName: string): Promise<string[]>;
|
|
13
14
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BeanInfo, Virtual, BeanScopeBase } from 'vona';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
+
import { isNil } from '@cabloy/utils';
|
|
3
4
|
import { DatabaseDialect, BeanDatabaseDialectBase } from 'vona-module-a-orm';
|
|
4
5
|
import { Scope } from 'vona-module-a-bean';
|
|
5
6
|
|
|
@@ -43,9 +44,22 @@ let DatabaseDialectMysql = (_dec$3 = DatabaseDialect(), _dec2$3 = BeanInfo({
|
|
|
43
44
|
});
|
|
44
45
|
return items;
|
|
45
46
|
}
|
|
46
|
-
async insert(builder) {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
async insert(builder, datas) {
|
|
48
|
+
if (datas.length === 0) return [];
|
|
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
|
+
}
|
|
49
63
|
}
|
|
50
64
|
query(result) {
|
|
51
65
|
return result[0];
|
|
@@ -139,10 +153,17 @@ let DatabaseDialectPg = (_dec$1 = DatabaseDialect(), _dec2$1 = BeanInfo({
|
|
|
139
153
|
});
|
|
140
154
|
return items;
|
|
141
155
|
}
|
|
142
|
-
async insert(builder) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
async insert(builder, datas) {
|
|
157
|
+
if (datas.length === 0) return [];
|
|
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
|
+
}
|
|
146
167
|
}
|
|
147
168
|
query(result) {
|
|
148
169
|
return result.rows;
|