Skip to main content

findFirstOrThrow()

Used to retrieve the first row matching specific conditions. Works the same as findFirst, but throws an error instead of returning null when no record is found.

Available Keys​

KeyDescriptionOptionalNotes
whereSpecifies query conditionsOptionalRetrieves all rows if omitted
selectDisplay settings for columnsOptionalCannot be used with omit / include
omitExclusion settings for columnsOptionalCannot be used with select
includeRetrieve related recordsOptionalDetails here
orderBySort settingsOptionalArray can be omitted when specifying a single column
takeLimit number of recordsOptional
skipNumber of records to skipOptional
distinctDeduplication settingsOptionalArray can be omitted when specifying a single column

Example Sheet​

Example Sheet

Description​

Suppose you want to retrieve a row from the above example with the following condition:

  • age => 20 or older

The code would be:

const gassma = new GassmaClient();

// gassma.{{TARGET_SHEET_NAME}}.findFirstOrThrow
const result = gassma.sheet1.findFirstOrThrow({
where: {
age: {
gte: 20,
},
},
});

The return value has the following format:

{
name: 'akahoshi',
age: 22,
pref: 'Ibaraki',
postNumber: '310-8555'
}

Differences from findFirst​

The behavior differs when no record is found:

// findFirst → returns null
const result = gassma.sheet1.findFirst({
where: { name: "nonexistent" },
});
// => null

// findFirstOrThrow → throws NotFoundError
const result = gassma.sheet1.findFirstOrThrow({
where: { name: "nonexistent" },
});
// => NotFoundError: No record found

For other specifications, see findMany().