kysely-writes-transactions
Installation
SKILL.md
Kysely Writes & Transactions
Decision Tree
| Need | Pattern |
|---|---|
| Single insert | insertInto().values().execute() |
| Insert + return row | .returningAll().executeTakeFirstOrThrow() (PG/SQLite) |
| Bulk insert | .values([...]) |
| Insert from select | .columns([...]).expression(selectQuery) |
| Upsert (PG/SQLite) | .onConflict(oc => oc.column().doUpdateSet()) |
| Upsert (MySQL) | .onDuplicateKeyUpdate({...}) |
| Ignore conflict | .onConflict(oc => oc.column().doNothing()) |
| MERGE | .mergeInto().using().whenMatched().thenUpdateSet() |
| Update | updateTable().set().where().execute() |
| Delete | deleteFrom().where().execute() |
| Transaction (auto) | db.transaction().execute(async trx => {}) |
| Transaction (manual) | db.startTransaction().execute() |
| Pin connection | db.connection().execute(async db => {}) |