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

Operators

Filter operators for the Lua query builder.

Operators are used in .where() clauses on select, update, and delete builders. In Lua, op is available globally after loading QueryBuilder.lua.

All operator column arguments accept either:

  • generated column refs such as users.id
  • string column names such as 'id'

Generated refs are the recommended path when your schema is available. Strings remain fully supported for quick scripts and compatibility.

Examples use users only as an illustration. Replace it with the tables and fields generated from your own schema.ts.

String column inputs are quoted as identifiers. They are not raw SQL fragments or expression escape hatches.

Comparison

local users = kura.db.tables.users

op.eq(users.id, 42)
op.ne(users.username, 'john')
op.lt(users.createdAt, os.time())
op.lte(users.createdAt, os.time())
op.gt(users.id, 100)
op.gte(users.id, 100)

String form:

op.eq('id', 42)
op.ne('username', 'john')
LuaTypeScriptSQL
op.eq(users.id, value)eq('id', value)"id" = $1
op.ne(users.id, value)ne('id', value)"id" <> $1
op.lt(users.id, value)lt('id', value)"id" < $1
op.lte(users.id, value)lte('id', value)"id" <= $1
op.gt(users.id, value)gt('id', value)"id" > $1
op.gte(users.id, value)gte('id', value)"id" >= $1

Pattern matching

local users = kura.db.tables.users

op.like(users.username, '%john%')
op.ilike(users.username, '%john%')
LuaTypeScriptSQL
op.like(users.username, '%john%')like('username', '%john%')"username" LIKE $1
op.ilike(users.username, '%john%')ilike('username', '%john%')"username" ILIKE $1

Array membership

local users = kura.db.tables.users

op.inArray(users.id, { 1, 2, 3 })
op.notInArray(users.id, { 4, 5 })
LuaTypeScriptSQL
op.inArray(users.id, {1, 2, 3})inArray('id', [1, 2, 3])"id" IN ($1, $2, $3)
op.notInArray(users.id, {4, 5})notInArray('id', [4, 5])"id" NOT IN ($1, $2)

Null checks

local users = kura.db.tables.users

op.isNull(users.deletedAt)
op.isNotNull(users.deletedAt)
LuaTypeScriptSQL
op.isNull(users.deletedAt)isNull('deleted_at')"deleted_at" IS NULL
op.isNotNull(users.deletedAt)isNotNull('deleted_at')"deleted_at" IS NOT NULL

Logical composition

Combine multiple conditions:

local users = kura.db.tables.users

op.and_(
  op.eq(users.username, 'john'),
  op.gt(users.id, 3)
)

op.or_(
  op.eq(users.username, 'john'),
  op.eq(users.username, 'jane')
)

op.not_(op.isNull(users.deletedAt))
op.and_(
  op.eq('username', 'john'),
  op.gt('id', 3)
)

op.or_(
  op.eq('username', 'john'),
  op.eq('username', 'jane')
)

op.not_(op.eq('banned', true))

Complex example

local users = kura.db.tables.users

local rows = kura.db.select({ users.id, users.username, users.createdAt })
  :from(users)
  :where(op.and_(
    op.or_(
      op.eq(users.username, 'john'),
      op.eq(users.username, 'jane')
    ),
    op.gte(users.id, 3),
    op.isNull(users.deletedAt)
  ))
  :orderBy({ [users.createdAt] = 'desc' })
  :limit(25)
  :await()

PostgreSQL-specific roadmap

The current operator set covers the common ORM-style cases. Advanced PostgreSQL helpers such as between, JSON/array containment, any/all, arithmetic update fragments, and raw SQL fragments are still roadmap items and should not be assumed to exist yet.

On this page