Skip to content

v0.6.0 - Rise of the `IF ELSE` statement.

Choose a tag to compare

@igalklebanov igalklebanov released this 26 Mar 20:52
· 19 commits to main since this release
  • Added IF ELSE statement support. Try out SurrealKysely.ifThen(condition, expression).
const accounts = await db
  .ifThen(sql`${scope} = ${sql.literal('admin')}`, db.selectFrom('account').selectAll())
  .elseIfThen(sql`${scope} = ${sql.literal('user')}`, sql<Account[]>`(select * from ${auth}.account)`)
  .else(sql<[]>`[]`)
  .end()
  .execute()
const result = await db.updateTable('person').set({
  railcard: db
    .ifThen(sql`${sql.ref('age')} <= 10`, sql.literal('junior'))
    .elseIfThen(sql`${sql.ref('age')} <= 21`, sql.literal('student'))
    .elseIfThen(sql`${sql.ref('age')} >= 65`, sql.literal('senior'))
    .else(sql`null`)
    .end(),
  })
  .executeTakeFirstOrThrow()

These would be very nice once the new Kysely ExpressionBuilder capabilities are released!

  • Fixed a bug where update/insert/delete results might not have had correct affected rows.
  • Deprecated a bunch of call, if, withPlugin, etc methods to align with Kysely's changes (adding $ prefix to utility non-sql methods).
  • Bumped Kysely peer dependency to >= 0.23.5.