David L. Bowman
David L. Bowman
DTDrizzle Team
Created by David L. Bowman on 8/29/2024 in #help
`id` type is `undefined` when using `serial("id").primaryKey()`
No description
7 replies
DTDrizzle Team
Created by David L. Bowman on 8/26/2024 in #help
Formatting date_of_birth as MM-DD-YYYY
What's the best way of doing this? date_of_birth: varchar("date_of_birth", { length: 10 }).notNull() That's what I have so far, but I need it to be MM-DD-YYYY. It needs to be this way because of the API I need to sync with.
import { pgTable, serial, timestamp, varchar } from "drizzle-orm/pg-core"
import { createInsertSchema } from "drizzle-zod"
import type { z } from "zod"

export const users = pgTable("users", {
id: serial("id").primaryKey(),
email: varchar("email", { length: 255 }).notNull(),
phone: varchar("phone", { length: 10 }).notNull(),
first_name: varchar("first_name", { length: 255 }).notNull(),
middle_name: varchar("middle_name", { length: 255 }),
last_name: varchar("last_name", { length: 255 }).notNull(),
gender: varchar("gender", {
enum: ["male", "female", "other"],
}),
gender_biological: varchar("gender_biological", {
enum: ["male", "female"],
}).notNull(),
date_of_birth: varchar("date_of_birth", { length: 10 }).notNull(),
})

export const insertUserSchema = createInsertSchema(users)
export type User = z.infer<typeof insertUserSchema>
import { pgTable, serial, timestamp, varchar } from "drizzle-orm/pg-core"
import { createInsertSchema } from "drizzle-zod"
import type { z } from "zod"

export const users = pgTable("users", {
id: serial("id").primaryKey(),
email: varchar("email", { length: 255 }).notNull(),
phone: varchar("phone", { length: 10 }).notNull(),
first_name: varchar("first_name", { length: 255 }).notNull(),
middle_name: varchar("middle_name", { length: 255 }),
last_name: varchar("last_name", { length: 255 }).notNull(),
gender: varchar("gender", {
enum: ["male", "female", "other"],
}),
gender_biological: varchar("gender_biological", {
enum: ["male", "female"],
}).notNull(),
date_of_birth: varchar("date_of_birth", { length: 10 }).notNull(),
})

export const insertUserSchema = createInsertSchema(users)
export type User = z.infer<typeof insertUserSchema>
1 replies
DTDrizzle Team
Created by David L. Bowman on 5/23/2024 in #help
HIPAA Compliant Drivers
can i use drizzle with aws healthlake? or, are there any recommended solutions?
1 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
I'm sorry, I'm new to Drizzle, but I've read through the documentation and discord and cannot find a solution to my problem. I'm using Next.js 14, Postgresql through Vercel. When I first started, I built a test UsersTable but now I want to change the id from a serial to a uuid. Everytime I try to generate:pg it works, but push:pg fails, giving the following error:
error: column "id" cannot be cast automatically to type uuid
code: '42804',
hint: 'You might need to specify "USING id::uuid".',
error: column "id" cannot be cast automatically to type uuid
code: '42804',
hint: 'You might need to specify "USING id::uuid".',
Could you please tell me how I'm supposed to update my table?
import { pgTable, uuid, varchar, timestamp } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"

export const UsersTable = pgTable("users", {
id: uuid("id").defaultRandom(),
firstName: varchar("first_name", { length: 50 }).notNull(),
lastName: varchar("last_name", { length: 50 }).notNull(),
email: varchar("email", { length: 100 }).notNull().unique(),
password: varchar("password", { length: 100 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull()
})
import { pgTable, uuid, varchar, timestamp } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"

export const UsersTable = pgTable("users", {
id: uuid("id").defaultRandom(),
firstName: varchar("first_name", { length: 50 }).notNull(),
lastName: varchar("last_name", { length: 50 }).notNull(),
email: varchar("email", { length: 100 }).notNull().unique(),
password: varchar("password", { length: 100 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull()
})
82 replies