Closed igalklebanov closed 5 months ago
I currently do it like this:
export async function GetInsertedIdIfUndefined(
trx: IKyselyTrx,
insertResult: InsertResult,
) {
if (insertResult.insertId === undefined) {
// return db.fn.scopeIdentity();
const queryResult: any = await sql`SELECT @@IDENTITY as id`.execute(trx);
// const queryResult: any = await sql`SELECT SCOPE_IDENTITY() as id`.execute(db);
return queryResult.rows?.[0]?.id;
}
return insertResult.insertId;
}
P.S.: Should db.fn.scopeIdentity()
be implemented too?
Hey 👋
Now that mssql dialect is in the core, it's time to pick and choose which clauses and keywords should get support in Kysely's query API.
The OUTPUT clause, is pretty much
returning
clause, but withdeleted
andinserted
(both are available inupdate
queries so you could return new and old values) "tables" in context.This one seems like an easy win. Without it, consumers will have to perform another query in inserts to get IDs.