Daniel Cruz
Daniel Cruz
KKysely
Created by Daniel Cruz on 5/18/2023 in #help
Extract OrderBy TS Keys
I dropped the function wrapper 😅 but I still need to get the possible keys, since I want to build a type safe white list to pass to my orderBy
type BaseQuery = ReturnType<typeof getBaseQuery>;

type Key = Parameters<BaseQuery["orderBy"]>["0"];

type WhiteList = Key[];

const WHITELIST_ORDER_BY_KEYS: WhiteList = [
"name",
"price_btc",
"sold",
"marketplace",
];
type BaseQuery = ReturnType<typeof getBaseQuery>;

type Key = Parameters<BaseQuery["orderBy"]>["0"];

type WhiteList = Key[];

const WHITELIST_ORDER_BY_KEYS: WhiteList = [
"name",
"price_btc",
"sold",
"marketplace",
];
What do you mean by orderBy having overloads?
11 replies
KKysely
Created by Daniel Cruz on 5/18/2023 in #help
Extract OrderBy TS Keys
I was able to make it work in the following way. I'd like your input if this is a good approach or is there any helper I'm not aware of @Igal
type BaseQuery = ReturnType<typeof getBaseQuery>;

//My approach👇
type Key = Parameters<BaseQuery["orderBy"]>["0"];

type AddOrderBy = {
query: BaseQuery;
key?: Key;
dir?: "asc" | "desc";
};
type BaseQuery = ReturnType<typeof getBaseQuery>;

//My approach👇
type Key = Parameters<BaseQuery["orderBy"]>["0"];

type AddOrderBy = {
query: BaseQuery;
key?: Key;
dir?: "asc" | "desc";
};
11 replies
KKysely
Created by Daniel Cruz on 5/18/2023 in #help
Extract OrderBy TS Keys
@Igal sorry for the ping 😅 I think this might had lost between other posts
11 replies
KKysely
Created by Daniel Cruz on 5/19/2023 in #help
Coalesce return empty array
Oh yeah I had another issue and tried to using it but I have to pass an id for the type, which could be the same or not between dev db and prod
14 replies
KKysely
Created by Daniel Cruz on 5/19/2023 in #help
Coalesce return empty array
I tried casting the whole thing to ::text[] and still got null
14 replies
KKysely
Created by Daniel Cruz on 5/19/2023 in #help
Coalesce return empty array
I guess I'll just handle the null. I'm migrating from Prisma and out of nowhere my app crashed haha, and it's because Prisma returns empty array
14 replies
KKysely
Created by Daniel Cruz on 5/19/2023 in #help
Coalesce return empty array
still null 😦
14 replies
KKysely
Created by Daniel Cruz on 5/19/2023 in #help
Coalesce return empty array
I think it may be a node-postgres thing? That empty sql arrays are transformed to null ?
14 replies
KKysely
Created by Daniel Cruz on 5/19/2023 in #help
Coalesce return empty array
I get malformed array literal: "[]"
14 replies
KKysely
Created by Daniel Cruz on 5/10/2023 in #help
Correct type definitions for function receiving builder
Thanks
5 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
You're the best
25 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
Yeah, the custom type oid was different in my local db and prod db, idk why 🤷‍♂️ but better not to risk it
25 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
Yep, I ended up doing
...
.selectAll("Collection")
.select((eb) => [
sql<string[]>`categories::text[]`.as("categories"),
...
...
.selectAll("Collection")
.select((eb) => [
sql<string[]>`categories::text[]`.as("categories"),
...
As using oid seems brittle, for any reason the id could change between dev and prod
25 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
do you know how can I define the custom types with Kysely? 😅
25 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
25 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
25 replies
KKysely
Created by Daniel Cruz on 5/8/2023 in #help
Transform Postgres array into JS array
I'm getting a string. Maybe is the fact that my column type is an enum array?
25 replies
KKysely
Created by Daniel Cruz on 5/4/2023 in #help
Argument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.
ok ok thanks 🙂
15 replies
KKysely
Created by Daniel Cruz on 5/4/2023 in #help
Argument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.
why should it be never? 😅
15 replies
KKysely
Created by Daniel Cruz on 5/4/2023 in #help
Argument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.
For now I fixed it by not using Kysely's min function
fn("round", [fn("min", ["ld.price_btc"]), sql.lit(5)]).as(
"floor_price"
),
fn("round", [fn("min", ["ld.price_btc"]), sql.lit(5)]).as(
"floor_price"
),
15 replies