HolySheets!
is a TypeScript library that simplifies the process of interacting with the Google Sheets API. It offers a set of tools for reading and writing data to and from Google Sheets, with a Prisma-like syntax.
-
No more memorizing range codes: With
HolySheets!
, you don't need to remember complex range codes. The library handles all the range-related operations for you, allowing you to focus on your data.
- Easy-to-use API for interacting with Google Sheets.
- Supports reading and writing data.
- Supports authentication with the Google Sheets API.
- TypeScript support: Enhances development with static typing and intellisense.
You can install HolySheets!
using npm:
npm install holysheets
To use HolySheets!
in your TypeScript project, you need to import it and initialize it with your Google Sheets credentials. Here's an example:
interface User {
name: string
email: string
age: number
}
const hollySheets = new HolySheets({
spreadsheetId: 'spreadsheet-id',
privateKey: credentials.private_key, // Your credentials
clientEmail: credentials.client_email // Your client email
})
const user = holySheets.base<User>('Users')
await user.findMany({
where: {
name: {
contains: 'Joe'
}
}
})
/// Find all users named Joe in Users sheet
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
Retrieves the first row that matches the given filter criteria.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met.
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 } }
Retrieves all rows that match the given filter criteria.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met.
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 } }
// ]
Updates the first row that matches the given filter criteria with the specified new data.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met. -
data
: An object specifying the new data to update the matching row with.
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 |
Updates all rows that match the given filter criteria with the specified new data.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met. -
data
: An object specifying the new data to update the matching rows with.
// 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 |
Clears the data in the first row that matches the given filter criteria.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met.
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: '' } }
Clears the data in all rows that match the given filter criteria.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met.
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 |
Deletes the first row that matches the given filter criteria.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met.
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 } }
Deletes all rows that match the given filter criteria.
-
filter
: An object specifying the filter criteria. Each key corresponds to a column name and each value specifies the condition to be met.
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 |
HolySheets!
provides a variety of filter conditions to help you query data from your Google Sheets. These filters allow you to specify criteria for selecting rows based on the values in their columns.
Checks if the value in the column equals the specified value.
const user = await userSheet.findFirst({
where: {
email: {
equals: 'john.doe@example.com'
}
}
});
Checks if the value in the column does not equal the specified value.
const users = await userSheet.findMany({
where: {
email: {
not: 'john.doe@example.com'
}
}
});
Checks if the value in the column is included in the specified array.
const users = await userSheet.findMany({
where: {
role: {
in: ['admin', 'editor']
}
}
});
Checks if the value in the column is not included in the specified array.
const users = await userSheet.findMany({
where: {
role: {
notIn: ['guest', 'banned']
}
}
});
Checks if the numeric value in the column is less than the specified value.
const users = await userSheet.findMany({
where: {
age: {
lt: 30
}
}
});
Checks if the numeric value in the column is less than or equal to the specified value.
const users = await userSheet.findMany({
where: {
age: {
lte: 30
}
}
});
Checks if the numeric value in the column is greater than the specified value.
const users = await userSheet.findMany({
where: {
points: {
gt: 1000
}
}
});
Checks if the numeric value in the column is greater than or equal to the specified value.
const users = await userSheet.findMany({
where: {
points: gte(1000)
}
});
Checks if the string value in the column contains the specified substring.
const users = await userSheet.findMany({
where: {
name:{
contains: 'Doe'
}
}
});
Performs a case-insensitive search to check if the string value in the column contains the specified substring.
const users = await userSheet.findMany({
where: {
name: {
search: 'doe'
}
}
});
Checks if the string value in the column starts with the specified substring.
const users = await userSheet.findMany({
where: {
name: {
startsWith: 'John'
}
}
});
Checks if the string value in the column ends with the specified substring.
const users = await userSheet.findMany({
where: {
email: {
endsWith: '@example.com'
}
}
});
HolySheets!
is licensed under the MIT License. For more details, see the LICENSE file in the project repository.
While HolySheets!
provides a simplified interface for managing Google Sheets data, it is not intended to replace a dedicated database system. Please consider the specific needs and requirements of your project when deciding whether to use HolySheets!
.