✦ xcaeser
✦ xcaeser4mo ago

thank you!! im migrating from prisma, i

thank you!! im migrating from prisma, i had this enum Status { DRAFT PUBLISHED ARCHIVED } having a hard time defining here properties: defineTable({ title: v.string(), description: v.string(), price: v.number(), propertyType: v.string(), }),
18 Replies
erquhart
erquhart4mo ago
properties: defineTable({
title: v.string(),
description: v.string(),
price: v.number(),
propertyType: v.string(),
status: v.union(
v.literal('DRAFT'),
v.literal('PUBLISHED'),
v.literal('ARCHIVED'),
),
}),
properties: defineTable({
title: v.string(),
description: v.string(),
price: v.number(),
propertyType: v.string(),
status: v.union(
v.literal('DRAFT'),
v.literal('PUBLISHED'),
v.literal('ARCHIVED'),
),
}),
✦ xcaeser
✦ xcaeserOP4mo ago
you're awesome thank you last question i think lol, how about default values? promoted Boolean @default(false) is it promoted: v.boolean() || false, @erquhart
erquhart
erquhart4mo ago
Doesn't have to be last question 🙂 Default values you'll handle in your mutations.
✦ xcaeser
✦ xcaeserOP4mo ago
what if i do v.optional(v.bool
erquhart
erquhart4mo ago
If you want the value to always be populated, don't make it optional
✦ xcaeser
✦ xcaeserOP4mo ago
oh undefined i see i like how opinionated convex is so far
erquhart
erquhart4mo ago
they're pretty great opinions (I don't work for Convex so I can say that lol)
✦ xcaeser
✦ xcaeserOP4mo ago
haha, and many to many, one to many? is just v.id("table") correct? i like how drizzle relations does it
erquhart
erquhart4mo ago
yep, id field is how you handle relations. How does drizzle do it?
✦ xcaeser
✦ xcaeserOP4mo ago
let me show u gotta open another old repo
export const dealRelations = relations(deals, ({ one, many }) => ({
users: many(dealUsers),
announcements: many(announcements),
creator: one(users, {
fields: [deals.createdByUserId],
references: [users.id],
}),
companies: many(dealCompanies),
streams: many(vdrStreams),
})
)
export const dealRelations = relations(deals, ({ one, many }) => ({
users: many(dealUsers),
announcements: many(announcements),
creator: one(users, {
fields: [deals.createdByUserId],
references: [users.id],
}),
companies: many(dealCompanies),
streams: many(vdrStreams),
})
)
erquhart
erquhart4mo ago
Yeah there will be libraries to provide these kinds of ergonomics, the canonical one so far is Ents: https://labs.convex.dev/convex-ents It's an early effort that probably won't go much further, so not necessarily one to use, but it shows what's possible.
Convex Ents - Convex Ents
Relations, default values, unique fields and more for Convex
erquhart
erquhart4mo ago
Current focus for Convex has been nailing the bottom level of abstractions and the base api
✦ xcaeser
✦ xcaeserOP4mo ago
should i use convex-auth?
erquhart
erquhart4mo ago
I'd recommend it personally. Only reason not to is if you have complex auth requirements.
✦ xcaeser
✦ xcaeserOP4mo ago
nah, just need roles, and oauth
erquhart
erquhart4mo ago
Roles you can handle in your backend logic, convex functions. Yeah I'd recommend convex auth.
✦ xcaeser
✦ xcaeserOP4mo ago
great, and for this
regions: defineTable({
name: v.string(),
countryId: v.id("countries"),
}),

cities: defineTable({
name: v.string(),
regionId: v.id("regions"),
areaId: v.id("areas"),
}),
regions: defineTable({
name: v.string(),
countryId: v.id("countries"),
}),

cities: defineTable({
name: v.string(),
regionId: v.id("regions"),
areaId: v.id("areas"),
}),
that's all i need? or do i add in regions cities: v.id or v.array?
erquhart
erquhart4mo ago
You don't need to denormalize by default. You may find it helpful depending on how you end up querying your data, though. What you have should be a good starting point.

Did you find this page helpful?