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()`
I could do this, maybe this is best?
if (id) {
await db
.update(users)
.set({
telegra_sso_key: telegraSSOKey,
})
.where(eq(users.id, id))
}
if (id) {
await db
.update(users)
.set({
telegra_sso_key: telegraSSOKey,
})
.where(eq(users.id, id))
}
7 replies
DTDrizzle Team
Created by David L. Bowman on 8/29/2024 in #help
`id` type is `undefined` when using `serial("id").primaryKey()`
I can do id as number but that's bad practice 😦
7 replies
DTDrizzle Team
Created by David L. Bowman on 8/29/2024 in #help
`id` type is `undefined` when using `serial("id").primaryKey()`
what's the best way to do this?
7 replies
DTDrizzle Team
Created by David L. Bowman on 8/29/2024 in #help
`id` type is `undefined` when using `serial("id").primaryKey()`
id can be undefined because it's created as a serial, but... i'm using .update so it obviously exists.
7 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
you both taught me a lot today.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
thhank you for your help @samson and @ColdRiver
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
easy enough then.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
ahhh, i got you.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
No description
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
i built a CLI tool for myself, which I use to do this 😄 i thought it would be good practice to turn it into an app.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
i bought a domain b/c i figured i'd share w/ others 😄
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
i was going to add the features after i figured out the orm/db part, which was harder than i thought.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
so far, the only commands are "help" "hi" and "bye" 😄
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
it's just a stupid terminal app which plays a sound at an interval to remind you to do something
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
I was going to try this 😄
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
got it, so should I just have a counter for the user which counts up, and rejects when a sixth comes?
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
updatedAt: timestamp("updated_at")
.$onUpdateFn(() => sql`current_timestamp`)
.notNull()
updatedAt: timestamp("updated_at")
.$onUpdateFn(() => sql`current_timestamp`)
.notNull()
82 replies
DTDrizzle Team
Created by David L. Bowman on 5/6/2024 in #help
Changing `id` type from serial to uuid, causing error.
import { sql } from "drizzle-orm"
import {
check,
index,
pgTable,
smallint,
timestamp,
uniqueIndex,
uuid,
varchar
} from "drizzle-orm/pg-core"

export const UsersTable = pgTable(
"users",
{
uuid: uuid("uuid").defaultRandom().primaryKey(),
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()
},
(table) => {
return {
emailIdx: uniqueIndex("email_idx").on(table.email)
}
}
)

export const RemindersTable = pgTable(
"reminders",
{
id: uuid("id").defaultRandom().primaryKey(),
userId: uuid("user_id")
.references(() => UsersTable.uuid)
.notNull(),
message: varchar("message", { length: 500 }).notNull(),
reminderInterval: smallint("reminder_interval").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull()
},
(reminders) => ({
userIdIndex: index("user_id_index").on(reminders.userId),
userReminderCountConstraint: check(
"user_reminder_count_constraint",
sql`(SELECT COUNT(*) FROM reminders WHERE user_id = ${reminders.userId}) <= 5`
)
})
)
import { sql } from "drizzle-orm"
import {
check,
index,
pgTable,
smallint,
timestamp,
uniqueIndex,
uuid,
varchar
} from "drizzle-orm/pg-core"

export const UsersTable = pgTable(
"users",
{
uuid: uuid("uuid").defaultRandom().primaryKey(),
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()
},
(table) => {
return {
emailIdx: uniqueIndex("email_idx").on(table.email)
}
}
)

export const RemindersTable = pgTable(
"reminders",
{
id: uuid("id").defaultRandom().primaryKey(),
userId: uuid("user_id")
.references(() => UsersTable.uuid)
.notNull(),
message: varchar("message", { length: 500 }).notNull(),
reminderInterval: smallint("reminder_interval").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull()
},
(reminders) => ({
userIdIndex: index("user_id_index").on(reminders.userId),
userReminderCountConstraint: check(
"user_reminder_count_constraint",
sql`(SELECT COUNT(*) FROM reminders WHERE user_id = ${reminders.userId}) <= 5`
)
})
)
82 replies