Installation
This guide covers everything you need to install and configure ServiceSQL in your Google Apps Script project.Installation Methods
There are two ways to add ServiceSQL to your project:Library (Recommended)
Add ServiceSQL as a Google Apps Script library - easier to update and maintain
Direct Copy
Copy the source code directly into your project - full control and customization
Method 1: Google Apps Script Library (Recommended)
This is the recommended approach for most projects.Get the Script ID
You need the ServiceSQL library’s Script ID. If you’re using a published version, you’ll receive this from the library publisher.
The Script ID is a long string that looks like:
1abc...xyzOpen your Apps Script project
- Go to script.google.com
- Open your project or create a new one
- You should see the script editor
Add the library
In the Apps Script editor:
- Click the Libraries icon (
+) in the left sidebar - In the “Script ID” field, paste the ServiceSQL Script ID
- Click Look up
- Select the latest version from the dropdown
- Set the identifier to
ServiceSQL(recommended) - Click Add
Updating the Library
When a new version of ServiceSQL is released:- Go to Libraries in the left sidebar
- Click on ServiceSQL
- Select the new version from the dropdown
- Click Save
Method 2: Copy Source Code Directly
For projects that need customization or don’t want external dependencies:Get the source code
Download or clone the ServiceSQL source code from the repository:The source files are located in the
src/ directory.Copy files to your project
Copy all
.js files from the src/ directory into your Google Apps Script project:Required files:APPSQL.js- Main classModel.js- Model base classQueryBuilder.js- Query builderCollection.js- Collection wrapperTable.js- Table helperDriver.js- Abstract driverSheetDriver.js- Sheets implementationEagerLoader.js- Relationship loaderUtils.js- UtilitiesTypes.js- Type definitions
CacheBuilder.js- Caching supportTriggerBuilder.js- Trigger managementGmailBuilder.js- Gmail integrationrelations/folder - All relationship classes
When copying source code directly, you’re responsible for updating files manually when new versions are released.
Configuration
Basic Configuration
Initialize ServiceSQL with your spreadsheet:Using the Active Spreadsheet
If your script is bound to a spreadsheet (container-bound script):Global Instance Pattern
For larger projects, create a global database instance:Environment-Based Configuration
Manage multiple environments (development, production):Config.gs
Script Properties Setup
Store sensitive configuration in Script Properties:Open Project Settings
In the Apps Script editor, click Project Settings (gear icon) in the left sidebar.
Add Script Properties
Scroll to “Script Properties” and click Add script property:
- Property:
DB_SPREADSHEET_ID - Value: Your spreadsheet ID
Script Properties are ideal for storing configuration that changes between environments or shouldn’t be in your code.
Setting Up Your First Database
Once ServiceSQL is installed, set up your database structure:1. Create Tables
Setup.gs
2. Define Models
Models.gs
3. Initialize Models
Init.gs
Permissions and Authorization
ServiceSQL needs permissions to access your spreadsheets:First Run
The first time you run a function that uses ServiceSQL, Google will ask for authorization.
Advanced Settings
If you see a warning screen, click Advanced and then Go to [Your Project Name] (unsafe).
Project Structure Recommendations
Organize your ServiceSQL project for maintainability:Example Project Structure
Verification Checklist
Before moving to production, verify your installation:- ServiceSQL library added and correct version selected
- Test function runs without errors
- Database connection successful
- Tables created successfully
- Models can query data
- Relationships work as expected
- Script permissions granted
- Script properties configured (if used)
Next Steps
Now that ServiceSQL is installed, you’re ready to start building:Quickstart
Build your first application in 5 minutes
Models Guide
Learn about model features and best practices
Query Builder
Master the query builder API
API Reference
Complete API documentation
Troubleshooting
Library not found
Problem: Error when adding library by Script ID Solution: Verify the Script ID is correct and the library is published. Contact the library maintainer for the correct Script ID.Authorization issues
Problem: Permission denied errors Solution: Remove the project from your Google Account’s authorized apps and reauthorize. Go to myaccount.google.com/permissions.Spreadsheet not found
Problem: “Spreadsheet not found” error Solution:- Verify the spreadsheet ID is correct
- Ensure you have access to the spreadsheet
- Check that the spreadsheet hasn’t been deleted
Models not working
Problem: Models return undefined or throw errors Solution: Make sure you’ve calledModel.use(db) before using any model methods.
Getting Help
If you encounter issues during installation:- Check the Troubleshooting section above
- Review the Quickstart guide for working examples
- Consult the API Reference for detailed documentation
- Search existing issues on GitHub
- Open a new issue with a detailed description