Skip to content

Commit fd79c4c

Browse files
Merge branch 'alternation-engine' of https://github.com/drizzle-team/drizzle-orm into alternation-engine
2 parents 23a5c57 + ef0d044 commit fd79c4c

File tree

5 files changed

+16
-62
lines changed

5 files changed

+16
-62
lines changed

drizzle-orm/src/cockroach-core/dialect.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@ import {
77
mapColumnsInSQLToAlias,
88
} from '~/alias.ts';
99
import { CasingCache } from '~/casing.ts';
10-
import {
11-
CockroachColumn,
12-
CockroachDate,
13-
CockroachDateString,
14-
CockroachDecimal,
15-
CockroachJsonb,
16-
CockroachTime,
17-
CockroachTimestamp,
18-
CockroachTimestampString,
19-
CockroachUUID,
20-
} from '~/cockroach-core/columns/index.ts';
10+
import { CockroachColumn } from '~/cockroach-core/columns/index.ts';
2111
import type {
2212
AnyCockroachSelectQueryBuilder,
2313
CockroachDeleteConfig,
@@ -32,16 +22,7 @@ import { entityKind, is } from '~/entity.ts';
3222
import { DrizzleError } from '~/errors.ts';
3323
import type { MigrationConfig, MigrationMeta, MigratorInitFailResponse } from '~/migrator.ts';
3424
import { and, eq, View } from '~/sql/index.ts';
35-
import {
36-
type DriverValueEncoder,
37-
type Name,
38-
Param,
39-
type QueryTypingsValue,
40-
type QueryWithTypings,
41-
SQL,
42-
sql,
43-
type SQLChunk,
44-
} from '~/sql/sql.ts';
25+
import { type Name, Param, type QueryWithTypings, SQL, sql, type SQLChunk } from '~/sql/sql.ts';
4526
import { Subquery } from '~/subquery.ts';
4627
import { getTableName, getTableUniqueName, Table } from '~/table.ts';
4728
import { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';
@@ -598,31 +579,12 @@ export class CockroachDialect {
598579
return sql`refresh materialized view${concurrentlySql} ${view}${withNoDataSql}`;
599580
}
600581

601-
prepareTyping(encoder: DriverValueEncoder<unknown, unknown>): QueryTypingsValue {
602-
if (is(encoder, CockroachJsonb)) {
603-
return 'json';
604-
} else if (is(encoder, CockroachDecimal)) {
605-
return 'decimal';
606-
} else if (is(encoder, CockroachTime)) {
607-
return 'time';
608-
} else if (is(encoder, CockroachTimestamp) || is(encoder, CockroachTimestampString)) {
609-
return 'timestamp';
610-
} else if (is(encoder, CockroachDate) || is(encoder, CockroachDateString)) {
611-
return 'date';
612-
} else if (is(encoder, CockroachUUID)) {
613-
return 'uuid';
614-
} else {
615-
return 'none';
616-
}
617-
}
618-
619582
sqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {
620583
return sql.toQuery({
621584
casing: this.casing,
622585
escapeName: this.escapeName,
623586
escapeParam: this.escapeParam,
624587
escapeString: this.escapeString,
625-
prepareTyping: this.prepareTyping,
626588
invokeSource,
627589
});
628590
}

drizzle-orm/src/cockroach-core/query-builders/query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { entityKind } from '~/entity.ts';
1010
import { QueryPromise } from '~/query-promise.ts';
1111
import type { RunnableQuery } from '~/runnable-query.ts';
12-
import type { Query, QueryWithTypings, SQL, SQLWrapper } from '~/sql/sql.ts';
12+
import type { Query, SQL, SQLWrapper } from '~/sql/sql.ts';
1313
import { tracer } from '~/tracing.ts';
1414
import type { KnownKeysOnly, NeonAuthToken } from '~/utils.ts';
1515
import type { CockroachDialect } from '../dialect.ts';
@@ -130,10 +130,10 @@ export class CockroachRelationalQuery<TResult> extends QueryPromise<TResult>
130130
return this._getQuery().sql as SQL;
131131
}
132132

133-
private _toSQL(): { query: BuildRelationalQueryResult; builtQuery: QueryWithTypings } {
133+
private _toSQL(): { query: BuildRelationalQueryResult; builtQuery: Query } {
134134
const query = this._getQuery();
135135

136-
const builtQuery = this.dialect.sqlToQuery(query.sql as SQL);
136+
const { typings: _typings, ...builtQuery } = this.dialect.sqlToQuery(query.sql as SQL);
137137

138138
return { query, builtQuery };
139139
}

drizzle-orm/src/sqlite-cloud/driver.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DefaultLogger } from '~/logger.ts';
55
import type { AnyRelations, EmptyRelations } from '~/relations.ts';
66
import { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';
77
import { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';
8-
import { type DrizzleConfig, isConfig } from '~/utils.ts';
8+
import type { DrizzleConfig } from '~/utils.ts';
99
import { SQLiteCloudSession } from './session.ts';
1010

1111
export type SQLiteCloudRunResult = unknown;
@@ -92,9 +92,9 @@ export function drizzle<
9292
TClient extends Database = Database,
9393
>(
9494
...params: [
95-
TClient | string,
95+
string,
9696
] | [
97-
TClient | string,
97+
string,
9898
DrizzleConfig<TSchema, TRelations>,
9999
] | [
100100
(
@@ -115,21 +115,17 @@ export function drizzle<
115115
return construct(instance, params[1]) as any;
116116
}
117117

118-
if (isConfig(params[0])) {
119-
const { connection, client, ...drizzleConfig } = params[0] as
120-
& { connection?: DatabaseOpts; client?: TClient }
121-
& DrizzleConfig<TSchema, TRelations>;
118+
const { connection, client, ...drizzleConfig } = params[0] as
119+
& { connection?: DatabaseOpts; client?: TClient }
120+
& DrizzleConfig<TSchema, TRelations>;
122121

123-
if (client) return construct(client, drizzleConfig) as any;
122+
if (client) return construct(client, drizzleConfig) as any;
124123

125-
const instance = typeof connection === 'string'
126-
? new Database(connection)
127-
: new Database(connection.path, connection);
124+
const instance = typeof connection === 'string'
125+
? new Database(connection)
126+
: new Database(connection.path, connection);
128127

129-
return construct(instance, drizzleConfig) as any;
130-
}
131-
132-
return construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema, TRelations> | undefined) as any;
128+
return construct(instance, drizzleConfig) as any;
133129
}
134130

135131
export namespace drizzle {

drizzle-orm/tests/casing/cockroach-to-camel.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ describe('cockroach to camel case', () => {
152152
sql:
153153
'select "users"."id", "users"."AGE", "users"."firstName" || \' \' || "users"."lastName" as "name", "users_developers"."data" as "developers" from "users" "users" left join lateral (select json_build_array("users_developers"."usesDrizzleOrm") as "data" from (select * from "test"."developers" "users_developers" where "users_developers"."userId" = "users"."id" limit $1) "users_developers") "users_developers" on true where "users"."id" = $2 limit $3',
154154
params: [1, 1, 1],
155-
typings: ['none', 'none', 'none'],
156155
});
157156
expect(db.dialect.casing.cache).toEqual(cache);
158157
});
@@ -180,7 +179,6 @@ describe('cockroach to camel case', () => {
180179
sql:
181180
'select "users"."id", "users"."AGE", "users"."firstName" || \' \' || "users"."lastName" as "name", "users_developers"."data" as "developers" from "users" "users" left join lateral (select json_build_array("users_developers"."usesDrizzleOrm") as "data" from (select * from "test"."developers" "users_developers" where "users_developers"."userId" = "users"."id" limit $1) "users_developers") "users_developers" on true where "users"."id" = $2',
182181
params: [1, 1],
183-
typings: ['none', 'none'],
184182
});
185183
expect(db.dialect.casing.cache).toEqual(cache);
186184
});

drizzle-orm/tests/casing/cockroach-to-snake.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ describe('cockroach to snake case', () => {
154154
sql:
155155
'select "users"."id", "users"."AGE", "users"."first_name" || \' \' || "users"."last_name" as "name", "users_developers"."data" as "developers" from "users" "users" left join lateral (select json_build_array("users_developers"."uses_drizzle_orm") as "data" from (select * from "test"."developers" "users_developers" where "users_developers"."user_id" = "users"."id" limit $1) "users_developers") "users_developers" on true where "users"."id" = $2 limit $3',
156156
params: [1, 1, 1],
157-
typings: ['none', 'none', 'none'],
158157
});
159158
expect(db.dialect.casing.cache).toEqual(cache);
160159
});
@@ -182,7 +181,6 @@ describe('cockroach to snake case', () => {
182181
sql:
183182
'select "users"."id", "users"."AGE", "users"."first_name" || \' \' || "users"."last_name" as "name", "users_developers"."data" as "developers" from "users" "users" left join lateral (select json_build_array("users_developers"."uses_drizzle_orm") as "data" from (select * from "test"."developers" "users_developers" where "users_developers"."user_id" = "users"."id" limit $1) "users_developers") "users_developers" on true where "users"."id" = $2',
184183
params: [1, 1],
185-
typings: ['none', 'none'],
186184
});
187185
expect(db.dialect.casing.cache).toEqual(cache);
188186
});

0 commit comments

Comments
 (0)