TheMelonAssassin
TheMelonAssassin
Explore posts from servers
KKysely
Created by TheMelonAssassin on 12/13/2024 in #help
Typing enums
Alright thanks I believe I was making it harder then needed to be. I was looking for a way to sync enum values from the database (either with a pgEnum or the enum table from above) with this:
export const ROLES = {
LESGEVER: "Lesgever",
COORDINATOR: "Coördinator",
BESTUUR: "Bestuur",
} as const;

export type Role = (typeof ROLES)[keyof typeof ROLES];
export const ROLES = {
LESGEVER: "Lesgever",
COORDINATOR: "Coördinator",
BESTUUR: "Bestuur",
} as const;

export type Role = (typeof ROLES)[keyof typeof ROLES];
But enum values should not change often so just adding them if it happens to the definition makes more sense
4 replies
KKysely
Created by TheMelonAssassin on 11/1/2024 in #help
Making Updateable<X> fields required
That makes sense. On the same subject, how come that for my own UpdateableActivity the fields have | undefined, but when hovering over Updateable there's no | undefined in the example
6 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
Thanks for the help
15 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
I'll see how much it impacts my performance, and otherwise I'll rewrite the test cases
15 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
Already was doing this
15 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
Well obviously in the front-end it does not matter given that both are the same time. I stumbled upon in because of my test cases
15 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
Hmmm so I was correct in my assumption that it only occurs in the subquery because of the parsing Where would you suggest I use pg-types?
15 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
Huh really? It's a super weird thing, the same date from the same lesson returned in two different formats I'll check out the package to streamline the output, but I'm not sure how it happens in the first place
15 replies
KKysely
Created by TheMelonAssassin on 10/14/2024 in #help
Issue with how timestamptz is returned depending on main or subquery
I think I've narrowed it down to it being part of the subquery, and potentially the json helpers
15 replies
KKysely
Created by Nicolas Bourdin on 10/9/2024 in #help
select expression helper
Might help you along the way, since I'd need some more context for your example. I created the following helper:
export const Color = {
byID: (colorID: Expression<number>) => {
const eb = expressionBuilder<Database, never>();

return jsonObjectFrom(
eb
.selectFrom("color")
.select([
"color.ID",
"color.name",
"color.hex",
"color.transparency",
"color.textColor",
])
.whereRef("color.ID", "=", colorID)
);
},
};
export const Color = {
byID: (colorID: Expression<number>) => {
const eb = expressionBuilder<Database, never>();

return jsonObjectFrom(
eb
.selectFrom("color")
.select([
"color.ID",
"color.name",
"color.hex",
"color.transparency",
"color.textColor",
])
.whereRef("color.ID", "=", colorID)
);
},
};
I use this pattern to add some helper functions per entity I have. This is how the helper is called:
export const getAllModules = async () => {
const modules = db
.selectFrom("module")
.select((eb) => [
"module.ID",
"module.name",
"module.abbreviation",
Color.byID(eb.ref("module.colorID")).as("color"),
])
.where("module.isActive", "=", true)
.execute();

return modules;
};
export const getAllModules = async () => {
const modules = db
.selectFrom("module")
.select((eb) => [
"module.ID",
"module.name",
"module.abbreviation",
Color.byID(eb.ref("module.colorID")).as("color"),
])
.where("module.isActive", "=", true)
.execute();

return modules;
};
9 replies
KKysely
Created by thelinuxlich on 9/20/2024 in #help
eb.fn.coalesce on a subquery
If you mean structuring the subquery as an object inside the main select yes it's possible Mind explaining a bit more what you want?
6 replies