@atscript/db-postgres 0.1.168 → 0.1.170
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/index.cjs +9 -8
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +9 -8
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -971,8 +971,13 @@ var PostgresAdapter = class PostgresAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
971
971
|
const sql = insert.sql + this._pk().returning;
|
|
972
972
|
const params = insert.params;
|
|
973
973
|
this._log(sql, params);
|
|
974
|
-
const
|
|
975
|
-
return { insertedId: this.
|
|
974
|
+
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
975
|
+
return { insertedId: this._insertedIdOf(data, result.rows?.[0]) };
|
|
976
|
+
}
|
|
977
|
+
/** The inserted id of `row`, from its `RETURNING` row (the primary-key columns, by name). */
|
|
978
|
+
_insertedIdOf(row, returned) {
|
|
979
|
+
const pkCols = this._pk().cols;
|
|
980
|
+
return this._resolveInsertedId(row, pkCols.length > 0 ? returned?.[pkCols[0]] : void 0, returned);
|
|
976
981
|
}
|
|
977
982
|
async insertMany(data) {
|
|
978
983
|
if (data.length === 0) return {
|
|
@@ -990,10 +995,7 @@ var PostgresAdapter = class PostgresAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
990
995
|
const params = insert.params;
|
|
991
996
|
this._log(sql, params);
|
|
992
997
|
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
993
|
-
for (let i = 0; i < batch.length; i++)
|
|
994
|
-
const returned = result.rows?.[i];
|
|
995
|
-
allIds.push(this._resolveInsertedId(batch[i], returned ? Object.values(returned)[0] : void 0));
|
|
996
|
-
}
|
|
998
|
+
for (let i = 0; i < batch.length; i++) allIds.push(this._insertedIdOf(batch[i], result.rows?.[i]));
|
|
997
999
|
}
|
|
998
1000
|
return {
|
|
999
1001
|
insertedCount: allIds.length,
|
|
@@ -1037,8 +1039,7 @@ var PostgresAdapter = class PostgresAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1037
1039
|
const run = async () => {
|
|
1038
1040
|
const tableName = this.resolveTableName();
|
|
1039
1041
|
const { keySets, returning, nonTextKeyCols, returningSuffix } = plan;
|
|
1040
|
-
const
|
|
1041
|
-
const insertedId = (row, returned) => ({ insertedId: this._resolveInsertedId(row, pkCols.length > 0 ? returned?.[pkCols[0]] : void 0) });
|
|
1042
|
+
const insertedId = (row, returned) => ({ insertedId: this._insertedIdOf(row, returned) });
|
|
1042
1043
|
const slots = [];
|
|
1043
1044
|
for (const batch of batches) {
|
|
1044
1045
|
const insert = buildInsertMany(tableName, batch, columns);
|
package/dist/index.d.cts
CHANGED
|
@@ -220,6 +220,8 @@ declare class PostgresAdapter extends BaseDbAdapter {
|
|
|
220
220
|
/** Rethrows `error` as a structured `DbError` when it is a unique / FK violation or a deadlock / lock timeout, else as is. */
|
|
221
221
|
private _mapConstraintError;
|
|
222
222
|
insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
|
|
223
|
+
/** The inserted id of `row`, from its `RETURNING` row (the primary-key columns, by name). */
|
|
224
|
+
private _insertedIdOf;
|
|
223
225
|
insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
|
|
224
226
|
supportsInsertIgnore(): boolean;
|
|
225
227
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -220,6 +220,8 @@ declare class PostgresAdapter extends BaseDbAdapter {
|
|
|
220
220
|
/** Rethrows `error` as a structured `DbError` when it is a unique / FK violation or a deadlock / lock timeout, else as is. */
|
|
221
221
|
private _mapConstraintError;
|
|
222
222
|
insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
|
|
223
|
+
/** The inserted id of `row`, from its `RETURNING` row (the primary-key columns, by name). */
|
|
224
|
+
private _insertedIdOf;
|
|
223
225
|
insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
|
|
224
226
|
supportsInsertIgnore(): boolean;
|
|
225
227
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -970,8 +970,13 @@ var PostgresAdapter = class PostgresAdapter extends BaseDbAdapter {
|
|
|
970
970
|
const sql = insert.sql + this._pk().returning;
|
|
971
971
|
const params = insert.params;
|
|
972
972
|
this._log(sql, params);
|
|
973
|
-
const
|
|
974
|
-
return { insertedId: this.
|
|
973
|
+
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
974
|
+
return { insertedId: this._insertedIdOf(data, result.rows?.[0]) };
|
|
975
|
+
}
|
|
976
|
+
/** The inserted id of `row`, from its `RETURNING` row (the primary-key columns, by name). */
|
|
977
|
+
_insertedIdOf(row, returned) {
|
|
978
|
+
const pkCols = this._pk().cols;
|
|
979
|
+
return this._resolveInsertedId(row, pkCols.length > 0 ? returned?.[pkCols[0]] : void 0, returned);
|
|
975
980
|
}
|
|
976
981
|
async insertMany(data) {
|
|
977
982
|
if (data.length === 0) return {
|
|
@@ -989,10 +994,7 @@ var PostgresAdapter = class PostgresAdapter extends BaseDbAdapter {
|
|
|
989
994
|
const params = insert.params;
|
|
990
995
|
this._log(sql, params);
|
|
991
996
|
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
992
|
-
for (let i = 0; i < batch.length; i++)
|
|
993
|
-
const returned = result.rows?.[i];
|
|
994
|
-
allIds.push(this._resolveInsertedId(batch[i], returned ? Object.values(returned)[0] : void 0));
|
|
995
|
-
}
|
|
997
|
+
for (let i = 0; i < batch.length; i++) allIds.push(this._insertedIdOf(batch[i], result.rows?.[i]));
|
|
996
998
|
}
|
|
997
999
|
return {
|
|
998
1000
|
insertedCount: allIds.length,
|
|
@@ -1036,8 +1038,7 @@ var PostgresAdapter = class PostgresAdapter extends BaseDbAdapter {
|
|
|
1036
1038
|
const run = async () => {
|
|
1037
1039
|
const tableName = this.resolveTableName();
|
|
1038
1040
|
const { keySets, returning, nonTextKeyCols, returningSuffix } = plan;
|
|
1039
|
-
const
|
|
1040
|
-
const insertedId = (row, returned) => ({ insertedId: this._resolveInsertedId(row, pkCols.length > 0 ? returned?.[pkCols[0]] : void 0) });
|
|
1041
|
+
const insertedId = (row, returned) => ({ insertedId: this._insertedIdOf(row, returned) });
|
|
1041
1042
|
const slots = [];
|
|
1042
1043
|
for (const batch of batches) {
|
|
1043
1044
|
const insert = buildInsertMany$1(tableName, batch, columns);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-postgres",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.170",
|
|
4
4
|
"description": "PostgreSQL adapter for @atscript/db with pg (node-postgres) driver support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -43,22 +43,22 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
46
|
+
"@atscript/db-sql-tools": "^0.1.170"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@atscript/core": "^0.2.
|
|
50
|
-
"@atscript/typescript": "^0.2.
|
|
49
|
+
"@atscript/core": "^0.2.7",
|
|
50
|
+
"@atscript/typescript": "^0.2.7",
|
|
51
51
|
"@types/pg": "^8.11.0",
|
|
52
|
-
"@uniqu/core": "^0.2.
|
|
52
|
+
"@uniqu/core": "^0.2.1",
|
|
53
53
|
"pg": "^8.13.0",
|
|
54
|
-
"unplugin-atscript": "^0.2.
|
|
54
|
+
"unplugin-atscript": "^0.2.7"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@atscript/core": "^0.2.
|
|
58
|
-
"@atscript/typescript": "^0.2.
|
|
59
|
-
"@uniqu/core": "^0.2.
|
|
57
|
+
"@atscript/core": "^0.2.7",
|
|
58
|
+
"@atscript/typescript": "^0.2.7",
|
|
59
|
+
"@uniqu/core": "^0.2.1",
|
|
60
60
|
"pg": ">=8.0.0",
|
|
61
|
-
"@atscript/db": "^0.1.
|
|
61
|
+
"@atscript/db": "^0.1.170"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"pg": {
|