@atscript/db-postgres 0.1.82 → 0.1.84
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 +11 -8
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +11 -8
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -77,8 +77,8 @@ function buildInsert(table, data) {
|
|
|
77
77
|
function buildSelect(table, where, controls) {
|
|
78
78
|
return (0, _atscript_db_sql_tools.buildSelect)(pgDialect, table, where, controls);
|
|
79
79
|
}
|
|
80
|
-
function buildUpdate(table, data, where, limit, ops) {
|
|
81
|
-
return (0, _atscript_db_sql_tools.buildUpdate)(pgDialect, table, data, where, limit, ops);
|
|
80
|
+
function buildUpdate(table, data, where, limit, ops, versionColumn, expectedVersion) {
|
|
81
|
+
return (0, _atscript_db_sql_tools.buildUpdate)(pgDialect, table, data, where, limit, ops, versionColumn, expectedVersion);
|
|
82
82
|
}
|
|
83
83
|
function buildDelete(table, where, limit) {
|
|
84
84
|
return (0, _atscript_db_sql_tools.buildDelete)(pgDialect, table, where, limit);
|
|
@@ -511,17 +511,19 @@ var PostgresAdapter = class PostgresAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
511
511
|
this._log(sql, params);
|
|
512
512
|
return this._exec().all(sql, params);
|
|
513
513
|
}
|
|
514
|
-
async updateOne(filter, data, ops) {
|
|
514
|
+
async updateOne(filter, data, ops, expectedVersion) {
|
|
515
515
|
const where = buildWhere(filter);
|
|
516
516
|
const tableName = this.resolveTableName();
|
|
517
517
|
const quotedTable = quoteTableName(tableName);
|
|
518
518
|
const pkCols = this._table.primaryKeys;
|
|
519
519
|
const quotedKeys = (pkCols.length > 0 ? pkCols : ["ctid"]).map((c) => c === "ctid" ? "ctid" : qi(c));
|
|
520
520
|
const colList = quotedKeys.join(", ");
|
|
521
|
-
const
|
|
521
|
+
const limitedWhere = {
|
|
522
522
|
sql: `${quotedKeys.length === 1 ? quotedKeys[0] : `(${colList})`} ${quotedKeys.length === 1 ? "=" : "IN"} (SELECT ${colList} FROM ${quotedTable} WHERE ${where.sql} LIMIT 1)`,
|
|
523
523
|
params: where.params
|
|
524
|
-
}
|
|
524
|
+
};
|
|
525
|
+
const versionColumn = this._table.versionColumn;
|
|
526
|
+
const { sql, params } = buildUpdate(tableName, data, limitedWhere, void 0, ops, versionColumn, expectedVersion);
|
|
525
527
|
this._log(sql, params);
|
|
526
528
|
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
527
529
|
return {
|
|
@@ -531,7 +533,8 @@ var PostgresAdapter = class PostgresAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
531
533
|
}
|
|
532
534
|
async updateMany(filter, data, ops) {
|
|
533
535
|
const where = buildWhere(filter);
|
|
534
|
-
const
|
|
536
|
+
const versionColumn = this._table.versionColumn;
|
|
537
|
+
const { sql, params } = buildUpdate(this.resolveTableName(), data, where, void 0, ops, versionColumn);
|
|
535
538
|
this._log(sql, params);
|
|
536
539
|
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
537
540
|
return {
|
|
@@ -539,8 +542,8 @@ var PostgresAdapter = class PostgresAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
539
542
|
modifiedCount: result.affectedRows
|
|
540
543
|
};
|
|
541
544
|
}
|
|
542
|
-
async replaceOne(filter, data) {
|
|
543
|
-
return this.updateOne(filter, data);
|
|
545
|
+
async replaceOne(filter, data, expectedVersion) {
|
|
546
|
+
return this.updateOne(filter, data, void 0, expectedVersion);
|
|
544
547
|
}
|
|
545
548
|
async replaceMany(filter, data) {
|
|
546
549
|
return this.updateMany(filter, data);
|
package/dist/index.d.cts
CHANGED
|
@@ -147,9 +147,9 @@ declare class PostgresAdapter extends BaseDbAdapter {
|
|
|
147
147
|
findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
148
148
|
count(query: DbQuery): Promise<number>;
|
|
149
149
|
aggregate(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
150
|
-
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
|
|
150
|
+
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
151
151
|
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
|
|
152
|
-
replaceOne(filter: FilterExpr, data: Record<string, unknown
|
|
152
|
+
replaceOne(filter: FilterExpr, data: Record<string, unknown>, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
153
153
|
replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
154
154
|
deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
155
155
|
deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
|
package/dist/index.d.mts
CHANGED
|
@@ -147,9 +147,9 @@ declare class PostgresAdapter extends BaseDbAdapter {
|
|
|
147
147
|
findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
148
148
|
count(query: DbQuery): Promise<number>;
|
|
149
149
|
aggregate(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
150
|
-
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
|
|
150
|
+
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
151
151
|
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
|
|
152
|
-
replaceOne(filter: FilterExpr, data: Record<string, unknown
|
|
152
|
+
replaceOne(filter: FilterExpr, data: Record<string, unknown>, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
153
153
|
replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
154
154
|
deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
155
155
|
deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
|
package/dist/index.mjs
CHANGED
|
@@ -76,8 +76,8 @@ function buildInsert$1(table, data) {
|
|
|
76
76
|
function buildSelect$1(table, where, controls) {
|
|
77
77
|
return buildSelect(pgDialect, table, where, controls);
|
|
78
78
|
}
|
|
79
|
-
function buildUpdate$1(table, data, where, limit, ops) {
|
|
80
|
-
return buildUpdate(pgDialect, table, data, where, limit, ops);
|
|
79
|
+
function buildUpdate$1(table, data, where, limit, ops, versionColumn, expectedVersion) {
|
|
80
|
+
return buildUpdate(pgDialect, table, data, where, limit, ops, versionColumn, expectedVersion);
|
|
81
81
|
}
|
|
82
82
|
function buildDelete$1(table, where, limit) {
|
|
83
83
|
return buildDelete(pgDialect, table, where, limit);
|
|
@@ -510,17 +510,19 @@ var PostgresAdapter = class PostgresAdapter extends BaseDbAdapter {
|
|
|
510
510
|
this._log(sql, params);
|
|
511
511
|
return this._exec().all(sql, params);
|
|
512
512
|
}
|
|
513
|
-
async updateOne(filter, data, ops) {
|
|
513
|
+
async updateOne(filter, data, ops, expectedVersion) {
|
|
514
514
|
const where = buildWhere(filter);
|
|
515
515
|
const tableName = this.resolveTableName();
|
|
516
516
|
const quotedTable = quoteTableName(tableName);
|
|
517
517
|
const pkCols = this._table.primaryKeys;
|
|
518
518
|
const quotedKeys = (pkCols.length > 0 ? pkCols : ["ctid"]).map((c) => c === "ctid" ? "ctid" : qi(c));
|
|
519
519
|
const colList = quotedKeys.join(", ");
|
|
520
|
-
const
|
|
520
|
+
const limitedWhere = {
|
|
521
521
|
sql: `${quotedKeys.length === 1 ? quotedKeys[0] : `(${colList})`} ${quotedKeys.length === 1 ? "=" : "IN"} (SELECT ${colList} FROM ${quotedTable} WHERE ${where.sql} LIMIT 1)`,
|
|
522
522
|
params: where.params
|
|
523
|
-
}
|
|
523
|
+
};
|
|
524
|
+
const versionColumn = this._table.versionColumn;
|
|
525
|
+
const { sql, params } = buildUpdate$1(tableName, data, limitedWhere, void 0, ops, versionColumn, expectedVersion);
|
|
524
526
|
this._log(sql, params);
|
|
525
527
|
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
526
528
|
return {
|
|
@@ -530,7 +532,8 @@ var PostgresAdapter = class PostgresAdapter extends BaseDbAdapter {
|
|
|
530
532
|
}
|
|
531
533
|
async updateMany(filter, data, ops) {
|
|
532
534
|
const where = buildWhere(filter);
|
|
533
|
-
const
|
|
535
|
+
const versionColumn = this._table.versionColumn;
|
|
536
|
+
const { sql, params } = buildUpdate$1(this.resolveTableName(), data, where, void 0, ops, versionColumn);
|
|
534
537
|
this._log(sql, params);
|
|
535
538
|
const result = await this._wrapConstraintError(() => this._exec().run(sql, params));
|
|
536
539
|
return {
|
|
@@ -538,8 +541,8 @@ var PostgresAdapter = class PostgresAdapter extends BaseDbAdapter {
|
|
|
538
541
|
modifiedCount: result.affectedRows
|
|
539
542
|
};
|
|
540
543
|
}
|
|
541
|
-
async replaceOne(filter, data) {
|
|
542
|
-
return this.updateOne(filter, data);
|
|
544
|
+
async replaceOne(filter, data, expectedVersion) {
|
|
545
|
+
return this.updateOne(filter, data, void 0, expectedVersion);
|
|
543
546
|
}
|
|
544
547
|
async replaceMany(filter, data) {
|
|
545
548
|
return this.updateMany(filter, data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-postgres",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.84",
|
|
4
4
|
"description": "PostgreSQL adapter for @atscript/db with pg (node-postgres) driver support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -43,20 +43,20 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@atscript/core": "^0.1.
|
|
47
|
-
"@atscript/typescript": "^0.1.
|
|
46
|
+
"@atscript/core": "^0.1.59",
|
|
47
|
+
"@atscript/typescript": "^0.1.59",
|
|
48
48
|
"@types/pg": "^8.11.0",
|
|
49
49
|
"@uniqu/core": "^0.1.6",
|
|
50
50
|
"pg": "^8.13.0",
|
|
51
|
-
"unplugin-atscript": "^0.1.
|
|
51
|
+
"unplugin-atscript": "^0.1.59"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@atscript/core": "^0.1.
|
|
55
|
-
"@atscript/typescript": "^0.1.
|
|
54
|
+
"@atscript/core": "^0.1.59",
|
|
55
|
+
"@atscript/typescript": "^0.1.59",
|
|
56
56
|
"@uniqu/core": "^0.1.6",
|
|
57
57
|
"pg": ">=8.0.0",
|
|
58
|
-
"@atscript/db": "^0.1.
|
|
59
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
58
|
+
"@atscript/db": "^0.1.84",
|
|
59
|
+
"@atscript/db-sql-tools": "^0.1.84"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"pg": {
|