sqlite-zod-orm 3.22.0 → 3.23.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/dist/index.js CHANGED
@@ -4620,6 +4620,18 @@ class QueryBuilder {
4620
4620
  const result = this.executor(`SELECT changes() as c`, [], true);
4621
4621
  return result[0]?.c ?? 0;
4622
4622
  }
4623
+ increment(column, amount = 1) {
4624
+ const { sql: selectSql, params } = compileIQO(this.tableName, this.iqo);
4625
+ const whereMatch = selectSql.match(/WHERE (.+?)(?:\s+ORDER|\s+LIMIT|\s+GROUP|\s+HAVING|$)/s);
4626
+ const wherePart = whereMatch ? whereMatch[1] : "1=1";
4627
+ const sql = `UPDATE "${this.tableName}" SET "${column}" = "${column}" + ? WHERE ${wherePart}`;
4628
+ this.executor(sql, [amount, ...params], true);
4629
+ const result = this.executor(`SELECT changes() as c`, [], true);
4630
+ return result[0]?.c ?? 0;
4631
+ }
4632
+ decrement(column, amount = 1) {
4633
+ return this.increment(column, -amount);
4634
+ }
4623
4635
  then(onfulfilled, onrejected) {
4624
4636
  try {
4625
4637
  const result = this.all();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlite-zod-orm",
3
- "version": "3.22.0",
3
+ "version": "3.23.0",
4
4
  "description": "Type-safe SQLite ORM for Bun — Zod schemas, fluent queries, auto relationships, zero SQL",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/builder.ts CHANGED
@@ -572,6 +572,34 @@ export class QueryBuilder<T extends Record<string, any>, TResult extends Record<
572
572
  return (result[0] as any)?.c ?? 0;
573
573
  }
574
574
 
575
+ /**
576
+ * Atomically increment a numeric column for matching rows.
577
+ * Returns the number of affected rows.
578
+ * ```ts
579
+ * db.users.select().where({ id: 1 }).increment('score', 10)
580
+ * ```
581
+ */
582
+ increment(column: keyof T & string, amount: number = 1): number {
583
+ const { sql: selectSql, params } = compileIQO(this.tableName, this.iqo);
584
+ const whereMatch = selectSql.match(/WHERE (.+?)(?:\s+ORDER|\s+LIMIT|\s+GROUP|\s+HAVING|$)/s);
585
+ const wherePart = whereMatch ? whereMatch[1] : '1=1';
586
+
587
+ const sql = `UPDATE "${this.tableName}" SET "${column}" = "${column}" + ? WHERE ${wherePart}`;
588
+ this.executor(sql, [amount, ...params], true);
589
+ const result = this.executor(`SELECT changes() as c`, [], true);
590
+ return (result[0] as any)?.c ?? 0;
591
+ }
592
+
593
+ /**
594
+ * Atomically decrement a numeric column for matching rows.
595
+ * Returns the number of affected rows.
596
+ * ```ts
597
+ * db.users.select().where({ id: 1 }).decrement('score', 5)
598
+ * ```
599
+ */
600
+ decrement(column: keyof T & string, amount: number = 1): number {
601
+ return this.increment(column, -amount);
602
+ }
575
603
 
576
604
  // ---------- Thenable (async/await support) ----------
577
605