Overview
TheAPPSQL class is the primary interface for ServiceSQL. It manages the connection to your Google Spreadsheet and provides access to query builders, models, schemas, and other features.
Initialization
init()
Initialize APPSQL as a singleton instance.Configuration object for APPSQL
The ID of the Google Spreadsheet to use as database
Returns the singleton APPSQL instance
init() follows the singleton pattern. Calling it multiple times returns the same instance.getInstance()
Get the existing APPSQL singleton instance.Returns the existing APPSQL instance
Core Methods
table()
Create a query builder for a specific sheet/table.Name of the sheet to query
Returns a new QueryBuilder instance for the specified sheet
model()
Register and configure a Model class with the database.A Model class to register with the database
Returns the registered Model class with database connection configured
What model() Does
- Links the database connection: Assigns
app,driver, and_dbto the Model class - Resolves table name: Uses
tableName,table, or the class name as the table - Calls boot(): Executes the Model’s
boot()method once for initialization - Enables queries: Allows the Model to execute database queries
Example: Complete Model Registration
Example: Complete Model Registration
Additional Features
schema()
Access schema management features for creating and modifying sheets.Returns a Schema builder instance
gmail()
Access Gmail integration features.Returns a GmailBuilder instance for email operations
triggers()
Manage Apps Script triggers.Returns a TriggerBuilder instance
cache()
Access caching utilities.Returns a CacheBuilder instance for caching operations
utils()
Access utility functions.Returns a Utils instance with helper methods
db()
Create a table instance directly.Name of the table
Array of column names
Returns a Table instance
Complete Example
Properties
The opened Google Spreadsheet instance
The underlying driver that handles sheet operations
Static property holding the singleton instance