ccabd
ccabd
Explore posts from servers
DTDrizzle Team
Created by ccabd on 8/9/2023 in #help
How to specify type using sql template
const rowConstructor =
(v: number, idx: number) => idx === 0 ? sql`(CAST (${ v } AS integer))` : sql`(${ v })`;

const values = sql.join( appids.map( rowConstructor ), sql`,` );
const rowConstructor =
(v: number, idx: number) => idx === 0 ? sql`(CAST (${ v } AS integer))` : sql`(${ v })`;

const values = sql.join( appids.map( rowConstructor ), sql`,` );
5 replies
DTDrizzle Team
Created by ccabd on 8/9/2023 in #help
How to specify type using sql template
The column types in a row constructor are taken from the first row, so all I had to do is add a CAST() to the first row, which solved the issues I had
5 replies
DTDrizzle Team
Created by ccabd on 8/9/2023 in #help
How to specify type using sql template
Forgot to update
5 replies
DTDrizzle Team
Created by ccabd on 8/9/2023 in #help
How to specify type using sql template
To simplify the question. I'm putting in numbers, how can I get numbers out as well?
5 replies
DTDrizzle Team
Created by ccabd on 8/8/2023 in #help
Find IDs from a list which do not exist in table
which results in this query
{
query: 'SELECT * FROM ( VALUES ($1),($2),($3) ) AS temp(id) WHERE NOT EXISTS ( SELECT * FROM "mytable" WHERE "mytable"."id" = CAST( temp.id AS integer ) )',
params: [ 3445, 3446, 999 ]
}
{
query: 'SELECT * FROM ( VALUES ($1),($2),($3) ) AS temp(id) WHERE NOT EXISTS ( SELECT * FROM "mytable" WHERE "mytable"."id" = CAST( temp.id AS integer ) )',
params: [ 3445, 3446, 999 ]
}
4 replies
DTDrizzle Team
Created by ccabd on 8/8/2023 in #help
Find IDs from a list which do not exist in table
but this is what i did
const ids = [ 3445, 3446, 999 ];
const values = sql.join( ids.map( v => sql`(${v})` ), sql`,` );

const query = sql.empty();
query.append( sql`SELECT * FROM ( VALUES ` );
query.append( values );
query.append( sql` ) AS temp(id)` );
query.append( sql` WHERE NOT EXISTS (` );
query.append( sql` SELECT * FROM ${mytable} WHERE ${mytable.id} = CAST( temp.id AS integer )` );
query.append( sql` )` );

const result = await database.execute( query );
const ids = [ 3445, 3446, 999 ];
const values = sql.join( ids.map( v => sql`(${v})` ), sql`,` );

const query = sql.empty();
query.append( sql`SELECT * FROM ( VALUES ` );
query.append( values );
query.append( sql` ) AS temp(id)` );
query.append( sql` WHERE NOT EXISTS (` );
query.append( sql` SELECT * FROM ${mytable} WHERE ${mytable.id} = CAST( temp.id AS integer )` );
query.append( sql` )` );

const result = await database.execute( query );
4 replies
DTDrizzle Team
Created by ccabd on 8/8/2023 in #help
Find IDs from a list which do not exist in table
i guess not
4 replies
DTDrizzle Team
Created by Xafets on 8/1/2023 in #help
Get `id` of inserted row
i fail to see the issue here
23 replies
DTDrizzle Team
Created by Xafets on 8/1/2023 in #help
Get `id` of inserted row
const resultId = (await Database.insert(UsersTable).values(userInsert).returning())[0].id
const resultId = (await Database.insert(UsersTable).values(userInsert).returning())[0].id
23 replies
DTDrizzle Team
Created by Xafets on 8/1/2023 in #help
Get `id` of inserted row
well you can skip creating a return type
23 replies