bambam22
bambam22
DTDrizzle Team
Created by bambam22 on 12/27/2023 in #help
Is it possible to pass sub query to `from`?
Ignore this
7 replies
DTDrizzle Team
Created by bambam22 on 12/27/2023 in #help
Is it possible to pass sub query to `from`?
The type is not assignable
7 replies
DTDrizzle Team
Created by bambam22 on 12/27/2023 in #help
Is it possible to pass sub query to `from`?
const statement = db
.select({
...getTableColumns(GamesTable),
platforms: sql<
Platform[]
>`json_agg(json_build_object('id', platforms.id, 'name', platforms.name, 'slug', platforms.slug, 'parentSlug', platforms.parent_slug, 'gamesCount', platforms.games_count, 'imageBackground', platforms.image_background))`,
})
.from(g)
const statement = db
.select({
...getTableColumns(GamesTable),
platforms: sql<
Platform[]
>`json_agg(json_build_object('id', platforms.id, 'name', platforms.name, 'slug', platforms.slug, 'parentSlug', platforms.parent_slug, 'gamesCount', platforms.games_count, 'imageBackground', platforms.image_background))`,
})
.from(g)
7 replies
DTDrizzle Team
Created by bambam22 on 12/27/2023 in #help
Is it possible to pass sub query to `from`?
Not sure what's going on here, this is my subquery but the .from won't accept it
const g = db
.select({
...getTableColumns(GamesTable),
})
.from(GamesTable)
.innerJoin(GamesToPlatforms, eq(GamesTable.id, GamesToPlatforms.gameId))jj
if (query.platformSlug) {
g.where(eq(PlatformsTable.slug, query.platformSlug))
}
g.as('g')
const g = db
.select({
...getTableColumns(GamesTable),
})
.from(GamesTable)
.innerJoin(GamesToPlatforms, eq(GamesTable.id, GamesToPlatforms.gameId))jj
if (query.platformSlug) {
g.where(eq(PlatformsTable.slug, query.platformSlug))
}
g.as('g')
7 replies
DTDrizzle Team
Created by bambam22 on 12/27/2023 in #help
Is it possible to pass sub query to `from`?
Thank youuuuuu
7 replies
DTDrizzle Team
Created by bambam22 on 12/27/2023 in #help
Use `getTableColumns` with `groupBy`
Oh thanks!
3 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
Well that was a trip, thanks so much for your help!
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
okay okay okay, I think we've got it!
const rawData = await db
.select({
...getTableColumns(GamesTable),
platforms: sql<Platform[]>`json_agg(${PlatformsTable})`,
genres: sql<Genre[]>`json_agg(${GenresTable})`,
})
.from(GamesTable)
.leftJoin(GamesToPlatforms, eq(GamesTable.id, GamesToPlatforms.gameId))
.innerJoin(
PlatformsTable,
eq(GamesToPlatforms.platformId, PlatformsTable.id)
)
.leftJoin(
GamesToGenresTable,
eq(GamesTable.id, GamesToGenresTable.gameId)
)
.innerJoin(GenresTable, eq(GamesToGenresTable.genreId, GenresTable.id))
.where(ilike(GamesTable.name, `%${query.searchText}%`))
.groupBy(GamesTable.id)
.orderBy(asc(GamesTable.createdAt))
.limit(20)
.offset(page * 20)
const rawData = await db
.select({
...getTableColumns(GamesTable),
platforms: sql<Platform[]>`json_agg(${PlatformsTable})`,
genres: sql<Genre[]>`json_agg(${GenresTable})`,
})
.from(GamesTable)
.leftJoin(GamesToPlatforms, eq(GamesTable.id, GamesToPlatforms.gameId))
.innerJoin(
PlatformsTable,
eq(GamesToPlatforms.platformId, PlatformsTable.id)
)
.leftJoin(
GamesToGenresTable,
eq(GamesTable.id, GamesToGenresTable.gameId)
)
.innerJoin(GenresTable, eq(GamesToGenresTable.genreId, GenresTable.id))
.where(ilike(GamesTable.name, `%${query.searchText}%`))
.groupBy(GamesTable.id)
.orderBy(asc(GamesTable.createdAt))
.limit(20)
.offset(page * 20)
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
like, it should just be creating that column on the query
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
But why is it looking at platforms as a column I guess is my question?
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
So why would that table not exist
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
well i was thinking that the only reference to platforms was the key but that's dumb, the actual table is platforms
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
So, the PlatformsTable is but I'm just not sure about the key platforms: in your select
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
i wonder why my query would be blowing up on that
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
You just had something hmmmm
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
Well, in your example query it doesn't seem to care about your key at all
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
Well yeah but like, the GamesTable doesn't have a platforms column on it. The platforms are coming from a join table
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
Any ideas?
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
But I'm getting the following error
column "platforms" does not exist at eval
61 replies
DTDrizzle Team
Created by bambam22 on 11/26/2023 in #help
Map casing when using sql`` operator
Things are looking better, I'm just not sure about that platforms definition, here is what I have so far
const rawData = await db
.select({
...getTableColumns(GamesTable),
platforms: sql`json_agg(${PlatformsTable})`.mapWith(JSON.parse),
})
.from(GamesTable)
.limit(20)
.offset(page * 20)
const rawData = await db
.select({
...getTableColumns(GamesTable),
platforms: sql`json_agg(${PlatformsTable})`.mapWith(JSON.parse),
})
.from(GamesTable)
.limit(20)
.offset(page * 20)
61 replies