SlintORM
Docsnpm

select()

select(...cols) picks which columns appear in the result. When joins are present and no select() is called, SlintORM auto-qualifies to table.* to avoid ambiguity errors.

Basic column selection

// select(...columns) — pick specific columns
const users = await User.query()
  .select('id', 'name', 'email')
  .get();
// SELECT id, name, email FROM users WHERE deletedAt IS NULL

No selection (all columns)

// No .select() — returns all columns
const users = await User.query().get();
// SELECT users.* FROM users WHERE deletedAt IS NULL

select() with joins

When joins are active, qualify columns with the table name to avoid collisions on id, createdAt, etc.

// When joins are present, unqualified table columns
// are auto-qualified to prevent ambiguity

const posts = await Post.query()
  .join('users', 'posts.userId', '=', 'users.id')
  .select('posts.id', 'posts.title', 'users.name')
  .get();
// SELECT posts.id, posts.title, users.name
// FROM posts
// INNER JOIN users ON posts.userId = users.id

exclude()

exclude(column) removes a column from the result after fetching. It can target root columns or nested preloaded relation columns using dot notation.

// .exclude(column) — strip columns from result
// Useful for hiding sensitive fields like passwords

const users = await User.query()
  .exclude('password')
  .exclude('secretToken')
  .get();
// Returns all columns except password and secretToken
// exclude() also works on preloaded relations
const posts = await Post.query()
  .preload('user')
  .exclude('user.password')   // strips from nested user objects
  .get();

get() — execute the query

.get() is the primary terminal method on every builder. It fires the accumulated SQL and returns EntityWithUpdate<T>[]. No query is sent to the database until .get(), .first(), or .getPaginated() is called.

// .get() — terminal method, executes the query
// Returns EntityWithUpdate<T>[] — every row augmented with
// .update(), .delete(), .refresh(), .toJSON()

const users = await User.query()
  .where('active', '=', true)
  .orderBy('name', 'ASC')
  .get();

// users is EntityWithUpdate<User>[]
// users[0].update({ name: 'Bob' })  — works directly
// users[0].toJSON()                 — plain object, no ORM methods

// Empty result: returns [] not null
const none = await User.query()
  .where('role', '=', 'nonexistent')
  .get();
// none.length === 0
PreviousQuery BuilderNextwhere()