Mixed Nuts
Explore posts from serversDTDrizzle Team
•Created by Mixed Nuts on 2/22/2024 in #help
Select<Type> Help
Random, but how can I get this to be type safe?
I get the object exactly how I want it but just not the type safety where it knows the Reports type is the actual selected type
type Reports = {
character: typeof characters.$inferSelect & {
faction: typeof factions.$inferSelect,
guild: typeof guilds.$inferSelect & {
faction: typeof factions.$inferSelect
}
},
log: typeof logs.$inferSelect
}
const characterFaction = alias(factions, 'characterFaction')
const guildFaction = alias(factions, 'guildFaction')
const preparedReports = db.select({
character: {
...characters,
faction: characterFaction,
guild: {
...guilds,
faction: guildFaction
}
},
log: logs
})
//...
type Reports = {
character: typeof characters.$inferSelect & {
faction: typeof factions.$inferSelect,
guild: typeof guilds.$inferSelect & {
faction: typeof factions.$inferSelect
}
},
log: typeof logs.$inferSelect
}
const characterFaction = alias(factions, 'characterFaction')
const guildFaction = alias(factions, 'guildFaction')
const preparedReports = db.select({
character: {
...characters,
faction: characterFaction,
guild: {
...guilds,
faction: guildFaction
}
},
log: logs
})
//...
1 replies
DTDrizzle Team
•Created by Mixed Nuts on 2/17/2024 in #help
Multiple `onConflictDoUpdate()`
Is there a cleaner way to do this? I tried
case
and where
in the sql
statements in one vs chaining, but that didn't work
const stmt = db.insert(characters).values(chars)
.onConflictDoUpdate({
target: characters.id,
set: {
name: sql`excluded.name`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.name is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
level: sql`excluded.level`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.level is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
factionId: sql`excluded.faction_id`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.faction_id is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
foreground: sql`excluded.foreground`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.foreground is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
background: sql`excluded.background`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.background is not null`
})
const stmt = db.insert(characters).values(chars)
.onConflictDoUpdate({
target: characters.id,
set: {
name: sql`excluded.name`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.name is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
level: sql`excluded.level`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.level is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
factionId: sql`excluded.faction_id`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.faction_id is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
foreground: sql`excluded.foreground`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.foreground is not null`
})
.onConflictDoUpdate({
target: characters.id,
set: {
background: sql`excluded.background`,
updatedAt: sql`CURRENT_TIMESTAMP`
},
where: sql`excluded.background is not null`
})
4 replies