diff --git a/drizzle-orm/src/pg-core/columns/smallserial.ts b/drizzle-orm/src/pg-core/columns/smallserial.ts index 7d02c306e..b7bf86757 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 @@ -44,5 +54,5 @@ export class PgSmallSerial } export function smallserial(name: TName): PgSmallSerialBuilderInitial { - return new PgSmallSerialBuilder(name); + return new PgSmallSerialBuilder(name) as PgSmallSerialBuilderInitial; } 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'] }),