freshyo/packages/db_helper_sqlite
2026-03-26 17:16:56 +05:30
..
src enh 2026-03-26 17:16:56 +05:30
.env.example enh 2026-03-26 17:16:56 +05:30
drizzle.config.ts enh 2026-03-26 17:16:56 +05:30
index.ts enh 2026-03-26 17:16:56 +05:30
package.json enh 2026-03-26 17:16:56 +05:30
README.md enh 2026-03-26 17:16:56 +05:30
tsconfig.json enh 2026-03-26 17:16:56 +05:30

Database Helper - SQLite (Cloudflare D1)

This package contains database helpers and schema definitions for Cloudflare D1.

Structure

  • src/db/ - Database source files
    • schema.ts - Drizzle ORM schema definitions (SQLite)
    • db_index.ts - D1 database initializer and client
    • types.ts - Database types
    • seed.ts - Database seeding script
    • porter.ts - Data migration utilities
  • drizzle.config.ts - Drizzle Kit configuration

Environment Variables

Create a .env file with:

DATABASE_URL=file:./dev.db

Initialization (Workers)

Use initDb with your D1 binding before calling helpers:

import { initDb } from '@packages/db_helper_sqlite'

export default {
  async fetch(request: Request, env: Env) {
    initDb(env.DB)
    // ... call helper methods
  },
}

Scripts

  • npm run migrate - Generate new migration files (SQLite)
  • npm run db:push - Push schema changes to database
  • npm run db:seed - Run database seeding
  • npm run db:studio - Open Drizzle Studio