@umituz/web-database 1.3.0 → 1.4.0
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/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/query.ts +22 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-database",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Database layer for the fleet — the single vendor-coupled module (Neon serverless HTTP driver today): sql(url) raw executor, createDb(url, schema) drizzle factory, Db type alias, query utilities (batchQueries, findFirst, findMany, exists, countRows), and db lifecycle tooling (reset / snapshot / seed)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"typecheck": "tsc --noEmit",
|
|
23
23
|
"lint": "eslint .",
|
|
24
|
-
"test": "vitest run",
|
|
24
|
+
"test": "vitest run --no-file-parallelism",
|
|
25
25
|
"test:watch": "vitest",
|
|
26
26
|
"prepublishOnly": "npm run typecheck && npm run lint && npm test",
|
|
27
27
|
"version:patch": "npm version patch -m 'chore: release v%s'",
|
package/src/index.ts
CHANGED
package/src/query.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
sql,
|
|
19
19
|
} from 'drizzle-orm';
|
|
20
20
|
import type { InferInsertModel, InferSelectModel, SQL, SQLWrapper } from 'drizzle-orm';
|
|
21
|
-
import type { PgTable, TableConfig } from 'drizzle-orm/pg-core';
|
|
21
|
+
import type { PgColumn, PgTable, TableConfig } from 'drizzle-orm/pg-core';
|
|
22
22
|
import type { Db } from './driver';
|
|
23
23
|
|
|
24
24
|
export {
|
|
@@ -37,6 +37,7 @@ export {
|
|
|
37
37
|
lte,
|
|
38
38
|
ne,
|
|
39
39
|
or,
|
|
40
|
+
sql as rawSql,
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
export type AnyPgTable = PgTable<TableConfig>;
|
|
@@ -406,3 +407,23 @@ export async function deleteWhere<T extends AnyPgTable>(
|
|
|
406
407
|
|
|
407
408
|
return (await (query as never as { returning: () => Promise<InferSelectModel<T>[]> }).returning());
|
|
408
409
|
}
|
|
410
|
+
|
|
411
|
+
export async function incrementRow<T extends AnyPgTable & { id: unknown }>(
|
|
412
|
+
db: AnyDb,
|
|
413
|
+
table: T,
|
|
414
|
+
id: string,
|
|
415
|
+
increments: Partial<Record<keyof T['_']['columns'] & string, number>>,
|
|
416
|
+
extraValues?: Partial<InferInsertModel<T>>,
|
|
417
|
+
options?: MutationOptions
|
|
418
|
+
): Promise<InferSelectModel<T> | null> {
|
|
419
|
+
const patch: Record<string, unknown> = { ...extraValues };
|
|
420
|
+
for (const [colName, delta] of Object.entries(increments)) {
|
|
421
|
+
if (typeof delta === 'number') {
|
|
422
|
+
const col = (table as unknown as Record<string, unknown>)[colName] as PgColumn;
|
|
423
|
+
if (col) {
|
|
424
|
+
patch[colName] = sql`${col} + ${delta}`;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return updateRow(db, table, id, patch as Partial<InferInsertModel<T>>, options);
|
|
429
|
+
}
|