cal
cal
Explore posts from servers
DTDrizzle Team
Created by nk on 1/29/2024 in #help
Dynamic select with types?
yeah this is definitely a valid pattern. I was just looking into the patter OP posted for a usecase where I would select users accounts with sensitive data and wanted to create something like
withUnsecure(user(id))
withUnsecure(user(id))
your approach would be to create - unsecureUser - user in the interface and the some wrapper like user(id, unsecure) is that correct?
16 replies
DTDrizzle Team
Created by nk on 1/29/2024 in #help
Dynamic select with types?
what do you dislike about it?
16 replies
DTDrizzle Team
Created by cal on 10/25/2023 in #help
`sql.join` with `ODER BY` leads to syntax error while the sql query seems correct.
The problem was not using sql.raw on the join separator: this is the correct code to achieve what I want to do:
const sortSqlChunks: SQL[] = [];
if (sorting.length > 1) {
const customSort = sorting.shift();
if (customSort) {
const [property, order] = Object.entries(customSort)[0];
sortSqlChunks.push(
sql`${ad[property as unknown as keyof AdSelect]} ${order} nulls last`,
);
}
}
sortSqlChunks.push(sql`${ad.publisherCreatedDateTime} desc nulls last`);

const ads = await this.dataAccessService
.getDb("AD")
.select()
.from(ad)
.where(inArray(ad.publicId, elasticSearchAds.publicIds))
.orderBy(sql.join(sortSqlChunks, sql.raw(", ")));
const sortSqlChunks: SQL[] = [];
if (sorting.length > 1) {
const customSort = sorting.shift();
if (customSort) {
const [property, order] = Object.entries(customSort)[0];
sortSqlChunks.push(
sql`${ad[property as unknown as keyof AdSelect]} ${order} nulls last`,
);
}
}
sortSqlChunks.push(sql`${ad.publisherCreatedDateTime} desc nulls last`);

const ads = await this.dataAccessService
.getDb("AD")
.select()
.from(ad)
.where(inArray(ad.publicId, elasticSearchAds.publicIds))
.orderBy(sql.join(sortSqlChunks, sql.raw(", ")));
6 replies
DTDrizzle Team
Created by cal on 10/25/2023 in #help
`sql.join` with `ODER BY` leads to syntax error while the sql query seems correct.
sql.join seems to be the cause for the problem here: if I use
sortSql = sql`${ad[property as unknown as keyof AdSelect]} ${sql.raw(order)} nulls last, ${ad.publisherCreatedDateTime} desc nulls last`;
sortSql = sql`${ad[property as unknown as keyof AdSelect]} ${sql.raw(order)} nulls last, ${ad.publisherCreatedDateTime} desc nulls last`;
this results in a query of
{
sql: ... from "ads"."Ad" where "Ad"."publicId" in ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) order by "Ad"."price" asc nulls last, "Ad"."publisherCreatedDateTime" desc nulls last',
params: [
...
]
}
{
sql: ... from "ads"."Ad" where "Ad"."publicId" in ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) order by "Ad"."price" asc nulls last, "Ad"."publisherCreatedDateTime" desc nulls last',
params: [
...
]
}
and a successful db query
6 replies
DTDrizzle Team
Created by cal on 10/25/2023 in #help
`sql.join` with `ODER BY` leads to syntax error while the sql query seems correct.
this results in
{
sql: 'select ... from "ads"."Ad" where "Ad"."publicId" in ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) order by "Ad"."price" desc nulls last$26"Ad"."publisherCreatedDateTime" desc nulls last',
params: [
...
', '
]
}
{
sql: 'select ... from "ads"."Ad" where "Ad"."publicId" in ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) order by "Ad"."price" desc nulls last$26"Ad"."publisherCreatedDateTime" desc nulls last',
params: [
...
', '
]
}
with the following error: syntax error at or near \"nulls\" 🤔
6 replies