@housekit/orm 0.1.21 → 0.1.22

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.
@@ -1,13 +1,15 @@
1
1
  import type { ClickHouseClient } from '@clickhouse/client';
2
2
  import type { SQLExpression } from '../expressions';
3
- import type { TableRuntime } from '../core';
3
+ import type { TableRuntime, InferSelectModel } from '../core';
4
4
  export declare class ClickHouseDeleteBuilder<TTable extends TableRuntime<any, any>> {
5
5
  private client;
6
6
  private table;
7
7
  private _where;
8
8
  private _lastMutationId;
9
9
  constructor(client: ClickHouseClient, table: TTable);
10
- where(expression: SQLExpression): this;
10
+ where(expression: SQLExpression | Partial<InferSelectModel<{
11
+ $columns: TTable['$columns'];
12
+ }>> | undefined | null): this;
11
13
  toSQL(): {
12
14
  query: string;
13
15
  params: Record<string, unknown>;
@@ -1,6 +1,6 @@
1
1
  import type { ClickHouseClient } from '@clickhouse/client';
2
2
  import type { SQLExpression } from '../expressions';
3
- import { type TableRuntime } from '../core';
3
+ import { type TableRuntime, type InferSelectModel } from '../core';
4
4
  export declare class ClickHouseUpdateBuilder<TTable extends TableRuntime<any, any>> {
5
5
  private client;
6
6
  private table;
@@ -9,7 +9,9 @@ export declare class ClickHouseUpdateBuilder<TTable extends TableRuntime<any, an
9
9
  private _lastMutationId;
10
10
  constructor(client: ClickHouseClient, table: TTable);
11
11
  set(values: Record<string, any>): this;
12
- where(expression: SQLExpression): this;
12
+ where(expression: SQLExpression | Partial<InferSelectModel<{
13
+ $columns: TTable['$columns'];
14
+ }>> | undefined | null): this;
13
15
  toSQL(): {
14
16
  query: string;
15
17
  params: Record<string, unknown>;
package/dist/index.js CHANGED
@@ -2949,7 +2949,7 @@ class ClickHouseQueryBuilder {
2949
2949
  const columns = table.$columns || table;
2950
2950
  for (const [key, value] of Object.entries(expression)) {
2951
2951
  const column = table[key] || columns?.[key];
2952
- if (column) {
2952
+ if (column && value !== undefined) {
2953
2953
  chunks.push(eq(column, value));
2954
2954
  }
2955
2955
  }
@@ -4567,10 +4567,6 @@ class ClickHouseInsertBuilder {
4567
4567
  this.table = table;
4568
4568
  if (table.$options?.asyncInsert !== undefined) {
4569
4569
  this._async = table.$options.asyncInsert;
4570
- } else if (table.$options?.appendOnly) {
4571
- this._async = true;
4572
- } else {
4573
- this._async = false;
4574
4570
  }
4575
4571
  }
4576
4572
  values(value) {
@@ -4867,7 +4863,26 @@ class ClickHouseDeleteBuilder {
4867
4863
  this.table = table;
4868
4864
  }
4869
4865
  where(expression) {
4870
- this._where = expression;
4866
+ if (!expression)
4867
+ return this;
4868
+ if (typeof expression === "object" && "toSQL" in expression) {
4869
+ this._where = expression;
4870
+ return this;
4871
+ }
4872
+ if (typeof expression === "object") {
4873
+ const chunks = [];
4874
+ for (const [key, value] of Object.entries(expression)) {
4875
+ const column = this.table.$columns[key];
4876
+ if (column && value !== undefined) {
4877
+ chunks.push(eq(column, value));
4878
+ }
4879
+ }
4880
+ if (chunks.length > 0) {
4881
+ const combined = chunks.length === 1 ? chunks[0] : and(...chunks);
4882
+ if (combined)
4883
+ this._where = combined;
4884
+ }
4885
+ }
4871
4886
  return this;
4872
4887
  }
4873
4888
  toSQL() {
@@ -4964,7 +4979,26 @@ class ClickHouseUpdateBuilder {
4964
4979
  return this;
4965
4980
  }
4966
4981
  where(expression) {
4967
- this._where = expression;
4982
+ if (!expression)
4983
+ return this;
4984
+ if (typeof expression === "object" && "toSQL" in expression) {
4985
+ this._where = expression;
4986
+ return this;
4987
+ }
4988
+ if (typeof expression === "object") {
4989
+ const chunks = [];
4990
+ for (const [key, value] of Object.entries(expression)) {
4991
+ const column = this.table.$columns[key];
4992
+ if (column && value !== undefined) {
4993
+ chunks.push(eq(column, value));
4994
+ }
4995
+ }
4996
+ if (chunks.length > 0) {
4997
+ const combined = chunks.length === 1 ? chunks[0] : and(...chunks);
4998
+ if (combined)
4999
+ this._where = combined;
5000
+ }
5001
+ }
4968
5002
  return this;
4969
5003
  }
4970
5004
  toSQL() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@housekit/orm",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "Type-safe ClickHouse ORM with modern DX and ClickHouse-specific optimizations. Features Turbo Mode (RowBinary), full engine support, and advanced query capabilities.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",