Sillvva
DTDrizzle Team
•Created by Sillvva on 3/13/2024 in #help
Is LIMIT 0 possible?
In drizzle it seems that
I ended up writing the query like this:
limit: 0
is the same as excluding the limit. However, in SQL it normally is supposed to return an empty set.
I had tried this, but it returned all the logs regardless of includeLogs
:
return await q.characters.findFirst({
with: {
user: true,
logs: {
with: {
dm: true,
magic_items_gained: true,
magic_items_lost: true,
story_awards_gained: true,
story_awards_lost: true
},
orderBy: (logs, { asc }) => asc(logs.date),
limit: includeLogs ? undefined : 0
}
},
where: (characters, { eq }) => eq(characters.id, characterId)
});
return await q.characters.findFirst({
with: {
user: true,
logs: {
with: {
dm: true,
magic_items_gained: true,
magic_items_lost: true,
story_awards_gained: true,
story_awards_lost: true
},
orderBy: (logs, { asc }) => asc(logs.date),
limit: includeLogs ? undefined : 0
}
},
where: (characters, { eq }) => eq(characters.id, characterId)
});
const character: (Character & { user: User; logs: LogData[] }) | undefined = await (async () => {
if (includeLogs) {
return await q.characters.findFirst({
with: {
user: true,
logs: {
with: {
dm: true,
magic_items_gained: true,
magic_items_lost: true,
story_awards_gained: true,
story_awards_lost: true
},
orderBy: (logs, { asc }) => asc(logs.date)
}
},
where: (characters, { eq }) => eq(characters.id, characterId)
});
} else {
return await q.characters
.findFirst({
with: {
user: true
},
where: (characters, { eq }) => eq(characters.id, characterId)
})
.then((c) => (c && { ...c, logs: [] }) || undefined);
}
})();
const character: (Character & { user: User; logs: LogData[] }) | undefined = await (async () => {
if (includeLogs) {
return await q.characters.findFirst({
with: {
user: true,
logs: {
with: {
dm: true,
magic_items_gained: true,
magic_items_lost: true,
story_awards_gained: true,
story_awards_lost: true
},
orderBy: (logs, { asc }) => asc(logs.date)
}
},
where: (characters, { eq }) => eq(characters.id, characterId)
});
} else {
return await q.characters
.findFirst({
with: {
user: true
},
where: (characters, { eq }) => eq(characters.id, characterId)
})
.then((c) => (c && { ...c, logs: [] }) || undefined);
}
})();
8 replies
DTDrizzle Team
•Created by Sillvva on 3/12/2024 in #help
PostgresError: relation "Session" does not exist
3 replies