ChatiumFor developersPlaygroundPricing
Sign in

HeapTableRepo.findOneBy

Returns the first heap object from a selection with the specified filtering.

This method is syntactic sugar for findBy in cases where the developer expects that the selection based on this condition should return one record (or none) from a business logic perspective, and it is convenient to work with it as a single record.

If no filtering is specified, all records from the table are returned.

Usage/Signature

table.findOneBy(ctx, where)
  • Arguments

    • ctx*: app.Ctx
      Request context. Used for internal implementation and also allows executing the query in the desired transaction.
    • fields: HeapFilter
      An object with filtering conditions in a special language.
  • Return Value: Promise<HeapObject | null>

    • The first heap object from the selection, or null if the selection was empty.

Examples


Searching for a user profile by the provided user ID.

const UserProfiles = Heap.Table('profiles', {
  userId: Heap.Integer(),
  role: Heap.String(),
})
const userProfile = await UserProfiles.findOneBy(ctx, {
  userId: req.params.userId,
})
if (userProfile === null) {
  throw 'user not found!'
}