Skip to content

Commit 3d307b2

Browse files
authored
Merge pull request #354 from drizzle-team/kysely-fix
2 parents 0437a5c + f5d56ad commit 3d307b2

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

changelogs/drizzle-orm/0.23.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- 🐛 Fixed broken types in Kysely and Knex adapters

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.23.3",
3+
"version": "0.23.4",
44
"description": "Drizzle ORM package for SQL databases",
55
"scripts": {
66
"build": "tsc && resolve-tspaths && cp ../README.md package.json dist/",

drizzle-orm/src/table.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AnyColumn, GetColumnData } from './column';
22
import type { OptionalKeyOnly, RequiredKeyOnly } from './operations';
3-
import type { Equal, Simplify, Update } from './utils';
3+
import type { Simplify, Update } from './utils';
44

55
export interface TableConfig<TColumn extends AnyColumn = AnyColumn> {
66
name: string;
@@ -76,7 +76,9 @@ export function getTableName<T extends Table>(table: T): T['_']['name'] {
7676
}
7777

7878
export type MapColumnName<TName extends string, TColumn extends AnyColumn, TDBColumNames extends boolean> =
79-
Equal<TDBColumNames, true> extends true ? TColumn['_']['name'] : TName;
79+
[TName] extends [never] ? never
80+
: TDBColumNames extends true ? TColumn['_']['name']
81+
: TName;
8082

8183
export type InferModel<
8284
TTable extends AnyTable,

drizzle-orm/tests/kysely/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Kysely, PostgresDialect } from 'kysely';
22
import { Pool } from 'pg';
33
import { type Equal, Expect } from 'tests/utils';
44
import type { Kyselify } from '~/kysely';
5+
import { char, mysqlTable, timestamp, varchar } from '~/mysql-core';
56
import { pgTable, serial, text } from '~/pg-core';
67
import type { InferModel } from '~/table';
78
import type { PromiseOf } from '~/utils';
@@ -23,3 +24,34 @@ const db = new Kysely<Database>({
2324

2425
const result = db.selectFrom('test').selectAll().execute();
2526
Expect<Equal<PromiseOf<typeof result>, InferModel<typeof test>[]>>();
27+
28+
{
29+
const units = mysqlTable('units', {
30+
id: char('id', { length: 16 }).primaryKey(),
31+
name: varchar('name', { length: 255 }).notNull(),
32+
abbreviation: varchar('abbreviation', { length: 10 }).notNull(),
33+
created_at: timestamp('created_at').defaultNow().notNull(),
34+
updated_at: timestamp('updated_at').defaultNow().notNull().onUpdateNow(),
35+
});
36+
37+
type UnitModel = typeof units;
38+
39+
interface Database {
40+
units: Kyselify<UnitModel>;
41+
}
42+
43+
const db = new Kysely<Database>({
44+
dialect: new PostgresDialect({
45+
pool: new Pool(),
46+
}),
47+
});
48+
49+
await db
50+
.insertInto('units')
51+
.values({
52+
id: 'my-unique-id',
53+
abbreviation: 'foo',
54+
name: 'bar',
55+
})
56+
.execute();
57+
}

0 commit comments

Comments
 (0)