Database

This app uses Val Town Blob Storage to manage data. Every Val Town account comes with free blob storage for simple key-value data persistence. This folder contains:

  • queries.ts - functions to read and write grid data to blob storage, which are imported and used in the main Hono server in /backend/index.ts

Storage Strategy

Instead of using SQLite, this app uses blob storage because:

  • Simpler for this use case (no complex relationships)
  • No need for database migrations
  • Easy JSON serialization/deserialization
  • Perfect for storing arrays of grid objects

Data Structure

The app stores a single blob with the key savedGrids containing an array of Grid objects. Each grid has:

  • id: unique identifier
  • cells: array of 16 booleans representing the 4x4 grid state
  • timestamp: when the grid was created
  • saved: whether the grid has been saved (prevents duplicate saves)

Queries

The queries file exports functions to:

  • getSavedGrids(): Retrieve all saved grids from blob storage
  • saveGrid(grid): Add a new grid to the saved collection (with duplicate prevention)

The functions handle cases where the blob doesn't exist yet and provide proper error handling for duplicate saves.