YuHeng (玉衡)

A local nutrition tracking app powered by AI

View the Project on GitHub formaxcn/yuheng

Database Adapter

YuHeng uses an adapter pattern to support both SQLite and PostgreSQL databases. The appropriate adapter is automatically selected based on the DATABASE_URL environment variable.

Architecture

The database layer is located in lib/db/:

Database Selection

Database Connection String Format Use Case
SQLite file:/app/data/yuheng.db Single container, personal use, simple setup
PostgreSQL postgresql://user:password@host:5432/yuheng Docker Compose, multi-user, scalable deployments

Features

Schema Versioning

YuHeng uses Drizzle Kit for database schema version management:

Local Development

With PostgreSQL (Docker Compose):

docker compose up -d
bun run db:migrate
bun run dev

With SQLite:

# set in .env: DATABASE_URL=file:./data/yuheng.db
bun run db:migrate:sqlite
bun run dev

The application automatically connects using the connection string from .env.