Holysheets!Logo Holysheets!

API documentation

base

The base method is used to set the sheet that is going to be used.

const baseConfig = base("Users");

You can also use your own type definition to have access to typescript static typing checking, for instance:

interface User {
  name: string;
  email: string;
  age: number;
}
const baseConfig = base<User>("Users");
/// Now you should only be able to add where clauses based on User interface keys

findFirst

Retrieves the first row that matches the given filter criteria.

Parameters

Example

const user = await userSheet.findFirst({
  where: {
    email: "john.doe@example.com",
  },
});
console.log(user);
// Output: { range: 'Users!A2:D2', row: 2, fields: { id: 1, name: 'John Doe', email: 'john.doe@example.com', points: 1200 } }

findMany

Retrieves all rows that match the given filter criteria.

Parameters

Example

const users = await userSheet.findMany({
  where: {
    points: {
      greaterThan: 1000,
    },
  },
});
console.log(users);
// Output: [
//   { range: 'Users!A2:D2', row: 2, fields: { id: 1, name: 'John Doe', points: 1050 } },
//   { range: 'Users!A3:D3', row: 3, fields: { id: 2, name: 'Jane Smith', points: 1100 } }
// ]

updateFirst

Updates the first row that matches the given filter criteria with the specified new data.

Parameters

Example

Before update:

// Assuming the sheet has the following data:
// | id | name    | points |
// |----|---------|--------|
// | 1  | John    | 950    |
// | 2  | Jane    | 1050   |
// | 3  | Maria   | 1100   |

const updatedUser = await userSheet.updateFirst(
  { where: { name: { contains: "Jane" } } },
  { data: { points: 1150 } },
);
console.log(updatedUser);
// Output: { range: 'Users!A3:D3', row: 3, fields: { id: 2, name: 'Jane', points: 1150 } }

// The sheet now has the following data: // | id | name | points | // |----|---------|--------| // | 1 | John | 950 | // | 2 | Jane | 1150 | // | 3 | Maria | 1100 |

updateMany

Updates all rows that match the given filter criteria with the specified new data.

Parameters

Example

// Assuming the sheet has the following data:
// | id | name    | points |
// |----|---------|--------|
// | 1  | John    | 950    |
// | 2  | Jane    | 1050   |
// | 3  | Maria   | 1100   |

const updatedUsers = await userSheet.updateMany(
  { where: { points: { greaterThan: 1000 } } },
  { data: { points: 1200 } },
);
console.log(updatedUsers);
// Output: [
//   { range: 'Users!A2:D2', row: 2, fields: { id: 2, name: 'Jane', points: 1200 } },
//   { range: 'Users!A3:D3', row: 3, fields: { id: 3, name: 'Maria', points: 1200 } }
// ]

// The sheet now has the following data:
// | id | name    | points |
// |----|---------|--------|
// | 1  | John    | 950    |
// | 2  | Jane    | 1200   |
// | 3  | Maria   | 1200   |

clearFirst

Clears the data in the first row that matches the given filter criteria.

Parameters

Example

const clearedUser = await userSheet.clearFirst({
  where: {
    name: "John Doe",
  },
});
console.log(clearedUser);
// Output: { range: 'Users!A2:D2', row: 2, fields: { id: 1, name: '', email: '', points: '' } }

clearMany

Clears the data in all rows that match the given filter criteria.

Parameters

const clearedUsers = await userSheet.clearMany({
  where: {
    points: {
      lessThan: 1000,
    },
  },
});
console.log(clearedUsers);
// Output: [
//   { range: 'Users!A2:D2', row: 2, fields: { id: 1, name: '', points: '' } }
// ]

// The sheet now has the following data:
// | id | name    | points |
// |----|---------|--------|
// | 1  |         |        |
// | 2  | Jane    | 1050   |
// | 3  | Maria   | 1100   |

deleteFirst

Deletes the first row that matches the given filter criteria.

Parameters

Examples

const deletedUser = await userSheet.deleteFirst({
  where: {
    email: "john.doe@example.com",
  },
});
console.log(deletedUser);
// Output: { range: 'Users!A2:D2', row: 2, fields: { id: 1, name: 'John Doe', email: 'john.doe@example.com', points: 1200 } }

deleteMany

Deletes all rows that match the given filter criteria.

Parameters

Example

const deletedUsers = await userSheet.deleteMany({
  where: {
    points: {
      lessThan: 1000,
    },
  },
});
console.log(deletedUsers);
// Output: [
//   { range: 'Users!A2:D2', row: 2, fields: { id: 1, name: 'John', points: 950 } }
// ]

// The sheet now has the following data:
// | id | name    | points |
// |----|---------|--------|
// | 2  | Jane    | 1050   |
// | 3  | Maria   | 1100   |