sasat 0.19.35 → 0.19.36
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.
|
@@ -13,7 +13,7 @@ const onDuplicateKeyUpdate = (columns) => {
|
|
|
13
13
|
};
|
|
14
14
|
export const createToSql = (dsl, tableInfo) => {
|
|
15
15
|
const map = tableInfo[dsl.table].columnMap;
|
|
16
|
-
return `INSERT INTO ${escapeId(dsl.table)}(${dsl.values.map(it => escapeId(map[it.field]))}) VALUES(${dsl.values.map(it => escape(it.value))})${onDuplicateKeyUpdate(dsl.upsert)}`;
|
|
16
|
+
return `INSERT ${dsl.ignore ? 'IGNORE ' : ''}INTO ${escapeId(dsl.table)}(${dsl.values.map(it => escapeId(map[it.field]))}) VALUES(${dsl.values.map(it => escape(it.value))})${onDuplicateKeyUpdate(dsl.upsert)}`;
|
|
17
17
|
};
|
|
18
18
|
export const updateToSql = (dsl, tableInfo) => {
|
|
19
19
|
const map = tableInfo[dsl.table].columnMap;
|
|
@@ -40,8 +40,11 @@ export declare abstract class SasatDBDatasource<Entity extends EntityType, Ident
|
|
|
40
40
|
protected abstract getDefaultValueString(): Partial<{
|
|
41
41
|
[P in keyof Entity]: Entity[P] | string | null | never;
|
|
42
42
|
}> | never;
|
|
43
|
-
create(entity: Creatable,
|
|
44
|
-
|
|
43
|
+
create(entity: Creatable, option?: {
|
|
44
|
+
ignore?: boolean;
|
|
45
|
+
upsert?: {
|
|
46
|
+
updateColumns: string[];
|
|
47
|
+
};
|
|
45
48
|
}): Promise<Entity>;
|
|
46
49
|
upsert<T extends Creatable & Partial<Entity>>(entity: T, updateFields?: (keyof T)[]): Promise<Entity>;
|
|
47
50
|
update(entity: Updatable): Promise<CommandResponse>;
|
|
@@ -10,7 +10,7 @@ export class SasatDBDatasource {
|
|
|
10
10
|
this.queryLogger = noop;
|
|
11
11
|
this.commandLogger = noop;
|
|
12
12
|
}
|
|
13
|
-
async create(entity,
|
|
13
|
+
async create(entity, option) {
|
|
14
14
|
const obj = {
|
|
15
15
|
...this.getDefaultValueString(),
|
|
16
16
|
...entity,
|
|
@@ -21,7 +21,8 @@ export class SasatDBDatasource {
|
|
|
21
21
|
field: column,
|
|
22
22
|
value,
|
|
23
23
|
})),
|
|
24
|
-
upsert: upsert?.updateColumns,
|
|
24
|
+
upsert: option?.upsert?.updateColumns,
|
|
25
|
+
ignore: option?.ignore,
|
|
25
26
|
};
|
|
26
27
|
const sql = createToSql(dsl, this.tableInfo);
|
|
27
28
|
this.commandLogger(sql);
|
|
@@ -35,7 +36,9 @@ export class SasatDBDatasource {
|
|
|
35
36
|
}
|
|
36
37
|
async upsert(entity, updateFields = this.primaryKeys) {
|
|
37
38
|
return this.create(entity, {
|
|
38
|
-
|
|
39
|
+
upsert: {
|
|
40
|
+
updateColumns: this.fieldToColumn(updateFields),
|
|
41
|
+
},
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
update(entity) {
|