K
Kyselybombillazo

jsonArrayFrom with `as` not being typed

I have the following query
await db
.selectFrom('user')
.selectAll()
.select((eb) => [
jsonArrayFrom(
eb
.selectFrom('book')
.selectAll()
.where('book.is_enabled', '=', true)
).as('books'),
])
.execute();
await db
.selectFrom('user')
.selectAll()
.select((eb) => [
jsonArrayFrom(
eb
.selectFrom('book')
.selectAll()
.where('book.is_enabled', '=', true)
).as('books'),
])
.execute();
but the resulting query is not seeing the jsonArrayFrom field with the name books , rather it types it like this:
{
[x: string]: {
created_at: TimestampTZ;
description: string | null;
id: string;
label: string | null;
name: string;
is_enabled: boolean;
}[];
... 5 more ...;
name: string;
}[]
{
[x: string]: {
created_at: TimestampTZ;
description: string | null;
id: string;
label: string | null;
name: string;
is_enabled: boolean;
}[];
... 5 more ...;
name: string;
}[]
How can i fix this?
Solution:
so Im using deno, and it uses import maps to import deps, I have these 2 import paths set up: I forgot to bump the helper path version to 0.27.3 as well šŸ¤¦ā€ā™‚ļø...
Igal
Igalā€¢37d ago
Hey šŸ‘‹ This works fine in the playground. Is tsconfig.json#compilerOptions.strict not true by any chance?
bombillazo
bombillazoā€¢37d ago
let me check yes, it is true hey, somethign weird, this happens on kysely v 0.27.3, not on 0.27.2 hmmmm esm.sh CDN has a kysely version for 0.27.3, but the GH releases stop at 0.27.2 it works for 0.27.2
Igal
Igalā€¢37d ago
the playground can use 0.27.3, 0.27.2, etc. this is something local what typescript version?
bombillazo
bombillazoā€¢37d ago
what chagnes occurred for .3? I dont see them in the release notes. Im using TS 5.4.4
Igal
Igalā€¢37d ago
We haven't posted a release, nothing major
bombillazo
bombillazoā€¢37d ago
its strange that there is no TS problem on 0.27.2 but there is for 0.27.3, using the same TS version
Igal
Igalā€¢37d ago
can you share your Database interface with just the two tables?
bombillazo
bombillazoā€¢37d ago
sure, one sec
declare const TimestampTZ: unique symbol;

export type TimestampTZ = string & { _opaque: typeof TimestampTZ };

export type DBTimestampTZ = ColumnType<TimestampTZ, TimestampTZ, TimestampTZ>;

export interface BookTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
is_enabled: Generated<boolean>;
label: string;
name: string;
}

export interface UserTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
name: string;
interests: string[]
email: string;
level: number;
birthdate: string;
score: number;
}

export interface KyselyDB {
user:UserTable,
book: BookTable,
}
declare const TimestampTZ: unique symbol;

export type TimestampTZ = string & { _opaque: typeof TimestampTZ };

export type DBTimestampTZ = ColumnType<TimestampTZ, TimestampTZ, TimestampTZ>;

export interface BookTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
is_enabled: Generated<boolean>;
label: string;
name: string;
}

export interface UserTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
name: string;
interests: string[]
email: string;
level: number;
birthdate: string;
score: number;
}

export interface KyselyDB {
user:UserTable,
book: BookTable,
}
Igal
Igalā€¢37d ago
can you share the definition of DBTeimstampTZ ?
bombillazo
bombillazoā€¢37d ago
updated*
Igal
Igalā€¢37d ago
where did you import jsonArrayFrom from ?
bombillazo
bombillazoā€¢37d ago
aaaaaaaah šŸ™‚
Solution
bombillazo
bombillazoā€¢37d ago
so Im using deno, and it uses import maps to import deps, I have these 2 import paths set up: I forgot to bump the helper path version to 0.27.3 as well šŸ¤¦ā€ā™‚ļø
No description
bombillazo
bombillazoā€¢37d ago
now its fixed, thanks šŸ˜„
Want results from more Discord servers?
Add your server
More Posts
How to use multiple schema definitions ( e.g. <catalog>.<schema>.<table> )Hey guys, I'm currently working on a new version for our graphql wrapper. Currently we're using kneUsing raw SQL with `or` whereI have been using the raw SQL template tag to work with certain JSON columns and wanted to add a `orCustom Plugin to transform Alias.* to "Alias.Column1", "Alias.Column2", etc.Hi everyone, in the previous question, I asked how to transform the following syntax into a new one.can kysely be extended with custom types within the databasehi. i would like to extend my database with custom types (a date type for sqlite) so that it is easinewbie need help with json_build_objectHi! Just starting with kysely and encountered problem I cant solve. I want to build raw query with kSolved: Exporting query builder classesI saw this PR https://github.com/kysely-org/kysely/pull/763 where you guys have decided not to exporbuilding kysely makes the package size very largehi. i'd be more than happy to figure this out because i like kysely a lot more than drizzle. the thiKysely setup in monolith APIHello, we have a basic http server with a basic router and a PostgreSQL database. We're wondering whIs it possible to get the total count while fetching rows in a single query?I have a query which looks like this: ```typescript const { items, count } = await db .selectFrom(Separating results of join into objects of each typeHey guys, I'm curious if anyone knows a way to unmerge the results of a join into objects of both tySnippet compilationHi, is it somehow possible to get only part of the compiled code to use it as snippet in ORM? Or vicCreating an 'enum' type columnHi all, Trying to re-create this MySQL in Kysely ``` ... CREATE TABLE ...( ... members ENUM('femalError when destructuring QueryCreator in withRecursiveI'm new to Kysely and attempting to migrate a Next app from prisma to kysely. I've generated types, Is `sql.join` the best way to concatenate sql templates?I have some business logic that incrementally builds up a sql WHERE query as a string. It looks likeMultiple calls to values in insert statement?I just had a production bug where I was calling `.values` multiple times on a query object. I've fix0.27.3 is out. Didn't have time to write0.27.3 is out. Didn't have time to write release notes yet since it was a hotfix to support typescriusing pgvector with KyselyFollowing the example here: https://github.com/pgvector/pgvector-node?darkschemeovr=1#kysely But I Static/reusable custom window functionsHello, I'm trying to buld a properly typed `array_agg` window function and would like to reuse the eIs the Kysely main site down?I just want to confirm if Kysely's main site is downOn Conflict do update set ALL to be inserted columnsHere I am once again with a question for the on conflict bit in postgres. Would there be a way to au