Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: insertions on columns with the smallserial datatype are not optional #1848

Closed
t3ned opened this issue Jan 30, 2024 · 0 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@t3ned
Copy link

t3ned commented Jan 30, 2024

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

0.20.12

Describe the Bug

The smallserial, serial and bigserial datatypes with the postgres.js driver are configured with hasDefault=true and notNull=true.

However, smallserial is missing the NotNull and HasDefault type helpers wrapped around the builder.

Therefore, when you try to insert a row into a table with a smallserial column, you are required to provide an input.

Example table

export const examples = pgTable("examples", {
    id: smallserial("id").notNull().primaryKey(),
});

Example insert query

await this.drizzle
  .insert(examples)
  .values({}); // Property 'id' is missing in type '{}' but required in type '{ id: number; }'

Workaround

Ignoring the type error successfully inserts a row

await this.drizzle
  .insert(examples)
  .values({} as unknown as typeof examples.$inferInsert);

Expected behavior

smallint columns should be optional when inserting to match the behaviour of serial and bigserial

Environment & setup

Node v20.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants