drizzle-databend 0.1.13 → 0.1.14

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.
@@ -11,7 +11,7 @@ export declare class DatabendDatabase {
11
11
  query: any;
12
12
  constructor(dialect: any, session: any, schema?: any);
13
13
  $with(alias: string): {
14
- as(qb: any): WithSubquery<string, Record<string, unknown>>;
14
+ as(qb: any): WithSubquery<string, any>;
15
15
  };
16
16
  $count(source: any, filters?: any): DatabendCountBuilder;
17
17
  with(...queries: any[]): {
@@ -7,7 +7,7 @@ export declare class QueryBuilder {
7
7
  dialectConfig: any;
8
8
  constructor(dialect?: any);
9
9
  $with(alias: string): {
10
- as(qb: any): WithSubquery<string, Record<string, unknown>>;
10
+ as(qb: any): WithSubquery<string, any>;
11
11
  };
12
12
  with(...queries: any[]): {
13
13
  select: (fields?: any) => DatabendSelectBuilder;
@@ -45,7 +45,7 @@ declare class DatabendSelectQueryBuilderBase extends TypedQueryBuilder<any, any>
45
45
  /** @internal */
46
46
  getSQL(): any;
47
47
  toSQL(): any;
48
- as(alias: string): Subquery<string, Record<string, unknown>>;
48
+ as(alias: string): Subquery<string, any>;
49
49
  /** @internal */
50
50
  getSelectedFields(): any;
51
51
  $dynamic(): this;
package/dist/index.mjs CHANGED
@@ -2952,6 +2952,12 @@ import {
2952
2952
  is as is10,
2953
2953
  SQL as SQL8
2954
2954
  } from "drizzle-orm";
2955
+ function getFieldSql(field) {
2956
+ const f = field;
2957
+ if (f.sql instanceof SQL8) return f.sql;
2958
+ if (f._?.sql instanceof SQL8) return f._.sql;
2959
+ throw new Error("Cannot extract SQL from field");
2960
+ }
2955
2961
  function toDecoderInput(decoder, value) {
2956
2962
  void decoder;
2957
2963
  return value;
@@ -3002,11 +3008,12 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
3002
3008
  } else if (is10(field, SQL8)) {
3003
3009
  decoder = field.decoder;
3004
3010
  } else {
3005
- const col = field.sql.queryChunks.find((chunk) => is10(chunk, Column3));
3011
+ const fieldSql = getFieldSql(field);
3012
+ const col = fieldSql.queryChunks.find((chunk) => is10(chunk, Column3));
3006
3013
  if (is10(col, DatabendCustomColumn)) {
3007
3014
  decoder = col;
3008
3015
  } else {
3009
- decoder = field.sql.decoder;
3016
+ decoder = fieldSql.decoder;
3010
3017
  }
3011
3018
  }
3012
3019
  let node = acc;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "./dist/index.mjs",
4
4
  "main": "./dist/index.mjs",
5
5
  "types": "./dist/index.d.ts",
6
- "version": "0.1.13",
6
+ "version": "0.1.14",
7
7
  "description": "A drizzle ORM driver for use with Databend. Based on drizzle's Postgres driver surface.",
8
8
  "type": "module",
9
9
  "scripts": {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "peerDependencies": {
20
20
  "databend-driver": ">=0.33.0",
21
- "drizzle-orm": "^0.40.0"
21
+ "drizzle-orm": ">=0.40.0"
22
22
  },
23
23
  "peerDependenciesMeta": {
24
24
  "databend-driver": {
@@ -29,7 +29,7 @@
29
29
  "@biomejs/biome": "^2.4.7",
30
30
  "@types/node": "^25.5.0",
31
31
  "databend-driver": "^0.33.6",
32
- "drizzle-orm": "0.40.0",
32
+ "drizzle-orm": "0.45.0",
33
33
  "esbuild": "^0.25.0",
34
34
  "typescript": "^5.8.2",
35
35
  "vitest": "^1.6.0"
@@ -6,6 +6,7 @@ import {
6
6
  is,
7
7
  type SelectedFieldsOrdered,
8
8
  SQL,
9
+ Subquery,
9
10
  } from 'drizzle-orm';
10
11
  import { DatabendCustomColumn } from '../databend-core/columns/custom.ts';
11
12
  import { DatabendDate } from '../databend-core/columns/date.ts';
@@ -15,6 +16,14 @@ type SQLInternal<T = unknown> = SQL<T> & {
15
16
  decoder: DriverValueDecoder<T, any>;
16
17
  };
17
18
 
19
+ /** Extract SQL from Aliased (has .sql) or Subquery (has _.sql) */
20
+ function getFieldSql(field: unknown): SQL {
21
+ const f = field as any;
22
+ if (f.sql instanceof SQL) return f.sql;
23
+ if (f._?.sql instanceof SQL) return f._.sql;
24
+ throw new Error('Cannot extract SQL from field');
25
+ }
26
+
18
27
  type DecoderInput<TDecoder extends DriverValueDecoder<unknown, unknown>> =
19
28
  Parameters<TDecoder['mapFromDriverValue']>[0];
20
29
 
@@ -113,12 +122,13 @@ export function mapResultRow<TResult>(
113
122
  } else if (is(field, SQL)) {
114
123
  decoder = (field as SQLInternal).decoder;
115
124
  } else {
116
- const col = field.sql.queryChunks.find((chunk) => is(chunk, Column));
125
+ const fieldSql = getFieldSql(field);
126
+ const col = fieldSql.queryChunks.find((chunk) => is(chunk, Column));
117
127
 
118
128
  if (is(col, DatabendCustomColumn)) {
119
129
  decoder = col;
120
130
  } else {
121
- decoder = (field.sql as SQLInternal).decoder;
131
+ decoder = (fieldSql as SQLInternal).decoder;
122
132
  }
123
133
  }
124
134
  let node = acc;