Kura
Early Access: Documentation is actively evolving and may change without notice.

Update

Update existing rows with the Lua builder.

local users = kura.db.tables.users

local changed = kura.db.update(users)
  :set({ username = 'jane' })
  :where(op.eq(users.id, userId))
  :await()

The generated table and column names above come from your own schema.ts. String-based calls still work:

local changed = kura.db.update('users')
  :set({ username = 'jane' })
  :where(op.eq('id', userId))
  :await()

Returning helpers

Use explicit helpers when you want returned rows instead of an affected-row count:

local users = kura.db.tables.users

local row = kura.db.update(users)
  :set({ username = 'jane' })
  :where(op.eq(users.id, userId))
  :returningOne({ users.id, users.username, users.createdAt })
  :await()

local updatedIds = kura.db.update(users)
  :set({ username = 'archived' })
  :where(op.isNull(users.deletedAt))
  :returningRows({ users.id })
  :await()

Available helpers:

  • :returningRows({ ... })
  • :returningOne({ ... })
  • :returningValue(column)

Compatibility behavior

returning() is still supported, but plain await() on update() remains compatibility-oriented:

local changed = kura.db.update(users)
  :set({ username = 'jane' })
  :where(op.eq(users.id, userId))
  :returning({ users.id, users.username })
  :await()

returning() is compiled into SQL, but plain :await() on update() still returns the affected row count for backwards compatibility. Use returningRows, returningOne, or returningValue when you want returned data.

Safety

local users = kura.db.tables.users

kura.db.update(users)
  :set({ banned = true })
  :where(op.eq(users.id, userId))
  :await()

update() without where() is still allowed today and will affect every row in the target table. KuraDB does not yet enforce an allowAllRows()-style guard, so add where() explicitly unless a full-table update is intentional.

Complex updates

For advanced PostgreSQL expressions, use raw SQL:

local changed = kura.db.raw.update.await(
  'UPDATE "public"."users" SET last_seen_at = NOW() WHERE id = $1',
  { userId }
)

On this page