TheMelonAssassin
TheMelonAssassin
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
KKysely
Created by TheMelonAssassin on 9/13/2024 in #help
Creating helper functions
Okay I understand, thanks a lot again
14 replies
KKysely
Created by TheMelonAssassin on 9/13/2024 in #help
Creating helper functions
I was wondering about two things after messing around more with extracting parts of my queries. 1. Why did you go with whereRef("module.ID", "=", moduleId) here? Isn't the moduleID always a value in this scope? I understand it's passed down as a column reference from the main function. 2. Say I want to use this function to use this function with an actual moduleID rather then a column ref. Would I just need to the following:
function moduleWithColor(moduleId: Expression<number> | number)
function moduleWithColor(moduleId: Expression<number> | number)
14 replies
KKysely
Created by TheMelonAssassin on 9/13/2024 in #help
Creating helper functions
Yeah I totally understand haha, I meant that before asking my question I did the same but didn't think to include the first jsonObjectFrom in the return of my helper That's why it wasn't working
14 replies