Skip to content

Apps Script · Software Development

When Your Google Sheet Starts Acting Like a Database

Your support queue starts with six rows and a dropdown. Then a form starts adding tickets, a scheduled script sends reminders, and someone sorts the sheet before lunch. By the end of the week, a reminder goes out for a ticket that was already closed. The sheet still looks fine. The scripts disagree about what its rows mean.

The Universal Google Sheets Database Engine is a JavaScript toolkit for Google Apps Script. It gives scripts a common way to create, read, update, and validate records while keeping the data in a spreadsheet. If a small team already runs its work from Sheets, that can buy it time before a move to a dedicated database makes sense.

Give every ticket an identity

Laptop displaying a spreadsheet and a code editor side by side.

Row 12 is a location. It changes when someone sorts or deletes rows. A ticket ID is part of the record, so a reminder job can look up the same ticket even after the sheet has been rearranged. Define that ID once, alongside rules for the fields every writer needs to agree on.

Here’s a small support queue you can run in a fresh spreadsheet. The source reference is unique so a retried import can recognize a ticket it has already seen. The default status means a new ticket enters the queue even if the intake form sends only a subject and reference.

function trySupportQueue() {
  const db = connect();
  const tickets = db.createTable('SupportTickets', {
    primaryKey: 'id',
    columns: {
      id: { type: 'number', autoIncrement: true },
      reference: { type: 'string', required: true, unique: true },
      subject: { type: 'string', required: true },
      status: { type: 'string', default: 'open' },
      priority: { type: 'number', min: 1, max: 5, default: 3 }
    }
  }, { ifNotExists: true });

  tickets.insertMany([
    { reference: 'REQ-101', subject: 'Invoice PDF missing', priority: 4 },
    { reference: 'REQ-102', subject: 'Update billing contact' },
    { reference: 'REQ-103', subject: 'Export job stalled', priority: 5 }
  ], { skipDuplicates: true });

  const urgent = tickets.where('status', 'open')
    .where('priority', '>=', 4)
    .orderBy('priority', 'desc')
    .select('id', 'reference', 'subject')
    .get();

  Logger.log(JSON.stringify(urgent));
}

On a fresh run, the export ticket comes first, followed by the invoice ticket. The billing contact request stays in the sheet at the default priority of 3. Run the function again and the existing references are skipped. If an incoming ticket needs to change an existing record, look up its ID and use an explicit update.

What happens between the script and the sheet?

Ticket intake passes through a script lock and schema validation before reaching the SupportTickets tab.

Each table gets a sheet tab. Headers occupy the first row, and the engine turns the rows underneath into objects keyed by those headers. It keeps schema information in a hidden metadata tab. An existing sheet with headers can also be read with an inferred schema. Start with an explicit schema when validation is the reason you’re adopting the engine.

For reads, the engine loads a table into memory and reuses that data for subsequent queries in the same execution. A reminder job can ask for open tickets and an operations report can group them by status with groupBy() and aggregate(). Both can use the same table API. Each initial load still reads the table, even if the final result contains only two records.

For writes, the engine uses a script lock and reads fresh data before applying changes. A batch can be validated before any of its rows are written. For a form import, this makes it possible to reject a priority of 9 and report the bad input instead of leaving the queue half imported.

Plan for the edits that happen outside your code

People can still type directly into the spreadsheet. A manual edit bypasses the engine’s validation and lock, so treat script checks and spreadsheet editing permissions as two separate controls. Run validateAll() after a bulk edit to catch values that violate the schema. If another writer has changed the sheet during a running execution, clear the engine’s cache before a read that needs the latest data.

Use audit logging if your team needs to see when a scripted update changed a ticket. Keep in mind that the audit records may include an email address as well as before-and-after values. For changes that touch multiple tables, db.transaction() can restore snapshots of table data when the callback throws. Schema changes and side effects such as sending an email sit outside that rollback. Take a backup before a migration, especially if you’re renaming headers.

Try it on a spreadsheet you can discard

View the Apps Script source files on Zonedak.online.

Get the free Google Sheets Database Engine ZIP.

  1. Open a fresh Google Sheet and choose Extensions → Apps Script.
  2. Copy the numbered .gs files from the source bundle’s src directory into the script project. Keep each file in its own script tab.
  3. Run runAllTests() to test in your Google account. The suite creates a temporary spreadsheet and uses Drive to trash it afterward, so review the requested permissions.
  4. Paste the support queue function into a new script file, run it, and check the execution log and the SupportTickets tab.

All 22 bundled tests passed when run against the project’s local Sheets mock. That run exercised validation, queries, backups, and rollback. Test with your real Sheets data and triggers before relying on it for daily work.

When it’s time to move beyond Sheets

The engine fits a low-volume workflow when people already review records in Sheets and a handful of scripts handle the updates. Think a small support queue, a content approval tracker, or an internal inventory list. Read performance depends on table size and width, and writes that use the same script lock wait for one another. Apps Script also has execution and service quotas. Google Apps Script quotas.

If delays from competing writers start affecting users, or if you need stronger isolation or fine-grained access to records, plan a move to a dedicated database such as PostgreSQL. The engine can export records as JSON. The best time to try that export is while the sheet is still small enough to compare the output with what your team sees every day.

Before you connect a live workflow

Run the example in a test spreadsheet. Import the same ticket twice, check the priority order, and try a batch with an out-of-range priority. If your team edits rows directly, run validateAll() after a bulk edit and confirm your reminder job looks up tickets by stable ID.

Leave a Reply

Your email address will not be published. Required fields are marked *