PNG-DB
A simple database that stores JSON data rows as compressed text within the zTXt chunks of PNG image files. Each JSON row is associated with a pixel coordinate and can be queried using a simple SQL-like syntax.
Try it online: https://pngdb.jonaylor.com

Quick Start
Features
- PNG Storage: Stores JSON data in PNG zTXt chunks while maintaining a valid image file
- Schema Definition: Define field types for your JSON data structure
- Coordinate-based Storage: Associate each JSON row with pixel coordinates (x, y)
- SQL-like Queries: Query data using WHERE clauses with coordinate and JSON field filtering
- Compression: Uses zlib compression for efficient storage of JSON data
- CLI Interface: Easy-to-use command-line interface for database operations
Installation
NPM Package (WASM)
import init from '@jonaylor89/png-db';
await ;
// Create a new database
const db = ;
// Insert data
db.;
db.;
// Query data
const results = db.;
console.log;
// Save to file (in Node.js) or get bytes for browser download
const pngBytes = db.;
CLI Version
Using Just (recommended):
Or install from crates.io (coming soon):
Usage
Creating a Database
Create a new PNG database with a schema:
Inserting Data
Insert JSON data at specific coordinates:
Querying Data
Query data using WHERE clauses:
# Find all active users
# Find users in a specific coordinate range
# Combine coordinate and data filters
# Find users by name
Listing All Data
List all rows in the database:
Query Syntax
The query engine supports simple WHERE clauses with the following features:
Supported Operators
=- Equal!=- Not equal>- Greater than<- Less than>=- Greater than or equal<=- Less than or equal
Supported Fields
x,y- Pixel coordinates (numbers)- Any field defined in your JSON schema
Value Types
- Strings: Use double quotes, e.g.,
name = "Alice" - Numbers: Integer or float, e.g.,
age = 30orheight = 5.9 - Booleans:
trueorfalse
Combining Conditions
Use AND to combine multiple conditions:
WHERE x > 100 AND y < 200 AND active = true AND age >= 25
Examples
Complete Workflow
# 1. Create a user database
# 2. Add some users
# 3. Query the data
# 4. List all data
Technical Details
Storage Format
- PNG Image: Creates a valid PNG image (black pixels by default)
- Schema: Stored in a zTXt chunk with keyword "schema"
- Data Rows: Each row stored in a zTXt chunk with keyword "row_x_y" (where x,y are coordinates)
- Compression: All text data is compressed using zlib before storage
File Structure
PNG File
├── IHDR chunk (image header)
├── zTXt chunk (keyword: "schema") - Database schema
├── zTXt chunk (keyword: "row_10_20") - JSON data at (10,20)
├── zTXt chunk (keyword: "row_50_100") - JSON data at (50,100)
├── ...
├── IDAT chunks (image data - black pixels)
└── IEND chunk (end marker)
Limitations
- Query Complexity: Only supports simple WHERE clauses with AND conditions
- Data Types: Limited to JSON-compatible types (string, number, boolean, null)
- Performance: Not optimized for large datasets - intended for small to medium data storage
- Concurrency: No built-in support for concurrent access
- Indexing: No indexing - queries perform linear scans