From 5d2d4cb4e83bc2691c12e78ebb9de38547ea8b89 Mon Sep 17 00:00:00 2001 From: Gabriel Donnantuoni Lima Date: Fri, 26 Jan 2024 19:28:27 -0300 Subject: [PATCH 1/3] fix: smallserial type --- .../src/pg-core/columns/smallserial.ts | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drizzle-orm/src/pg-core/columns/smallserial.ts b/drizzle-orm/src/pg-core/columns/smallserial.ts index 7d02c306e..cb0539065 100644 --- a/drizzle-orm/src/pg-core/columns/smallserial.ts +++ b/drizzle-orm/src/pg-core/columns/smallserial.ts @@ -1,17 +1,27 @@ -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts'; +import type { + ColumnBuilderBaseConfig, + ColumnBuilderRuntimeConfig, + HasDefault, + MakeColumnConfig, + NotNull, +} from '~/column-builder.ts'; import type { ColumnBaseConfig } from '~/column.ts'; import { entityKind } from '~/entity.ts'; import type { AnyPgTable } from '~/pg-core/table.ts'; import { PgColumn, PgColumnBuilder } from './common.ts'; -export type PgSmallSerialBuilderInitial = PgSmallSerialBuilder<{ - name: TName; - dataType: 'number'; - columnType: 'PgSmallSerial'; - data: number; - driverParam: number; - enumValues: undefined; -}>; +export type PgSmallSerialBuilderInitial = NotNull< + HasDefault< + PgSmallSerialBuilder<{ + name: TName; + dataType: 'number'; + columnType: 'PgSmallSerial'; + data: number; + driverParam: number; + enumValues: undefined; + }> + > +>; export class PgSmallSerialBuilder> extends PgColumnBuilder From 7cceb0b8ba528c9e74250aabbdc3cbe7be2ebef8 Mon Sep 17 00:00:00 2001 From: AndriiSherman Date: Wed, 27 Mar 2024 13:05:24 +0200 Subject: [PATCH 2/3] Fix type errors --- drizzle-orm/src/pg-core/columns/smallserial.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drizzle-orm/src/pg-core/columns/smallserial.ts b/drizzle-orm/src/pg-core/columns/smallserial.ts index cb0539065..b7bf86757 100644 --- a/drizzle-orm/src/pg-core/columns/smallserial.ts +++ b/drizzle-orm/src/pg-core/columns/smallserial.ts @@ -54,5 +54,5 @@ export class PgSmallSerial } export function smallserial(name: TName): PgSmallSerialBuilderInitial { - return new PgSmallSerialBuilder(name); + return new PgSmallSerialBuilder(name) as PgSmallSerialBuilderInitial; } From fecb99378e1828acb0dbe47b1f2f6b2998cd101b Mon Sep 17 00:00:00 2001 From: AndriiSherman Date: Wed, 27 Mar 2024 13:10:34 +0200 Subject: [PATCH 3/3] Add type tests for small serial --- drizzle-orm/type-tests/pg/tables.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drizzle-orm/type-tests/pg/tables.ts b/drizzle-orm/type-tests/pg/tables.ts index 4a940ebcb..0ab243f57 100644 --- a/drizzle-orm/type-tests/pg/tables.ts +++ b/drizzle-orm/type-tests/pg/tables.ts @@ -31,6 +31,7 @@ import { real, serial, smallint, + smallserial, text, time, timestamp, @@ -105,6 +106,22 @@ export const cities = pgTable('cities_table', { citiesNameIdx: index().on(cities.id), })); +export const smallSerialTest = pgTable('cities_table', { + id: smallserial('id').primaryKey(), + name: text('name').notNull(), + population: integer('population').default(0), +}, (cities) => ({ + citiesNameIdx: index().on(cities.id), +})); + +Expect< + Equal<{ + id?: number; + name: string; + population?: number | null; + }, typeof smallSerialTest.$inferInsert> +>; + export const classes = pgTable('classes_table', { id: serial('id').primaryKey(), class: text('class', { enum: ['A', 'C'] }),