pawql
v0.3.0
Published
The Runtime-First ORM for TypeScript. Type-safe database query builder with zero code generation.
Maintainers
Readme
PawQL
The Runtime-First ORM for TypeScript — Zero code generation. Zero build step. Full type safety.
PawQL is a modern, type-safe database query builder that infers types directly from your runtime schema definition. No CLI tools, no .prisma files, no generated code.
Why PawQL?
| Feature | Prisma | Drizzle | PawQL |
|---------|--------|---------|-----------|
| Code Generation | ✅ Required | ⚠ Optional | ❌ Not needed |
| Build Step | ✅ Required | ⚠ Sometimes | ❌ Not needed |
| Runtime Schema | ❌ | ❌ | ✅ Yes |
| Type Safety | ✅ | ✅ | ✅ Native inference |
| Schema Definition | .prisma file | TypeScript schema | Plain JS objects |
| Learning Curve | Medium | Medium | Low |
Features
- 🚀 Runtime-First — Define schema using plain JavaScript objects
- 🔒 Native Type Inference — End-to-end TypeScript support without code generation
- 🛠️ Zero Build Step — No CLI, no schema files, no generated clients
- ⚡ Lightweight Core — Minimal abstraction, ideal for serverless & edge
- 📦 Modern — ESM-first, works with Node.js and Bun
Capabilities (v0.3.0)
- CRUD:
SELECT,INSERT,UPDATE,DELETE - Filtering:
WHERE,OR,IN,LIKE,BETWEEN,IS NULL, comparison operators - ORDER BY: Single/multiple column sorting with ASC/DESC
- LIMIT / OFFSET: Pagination support
- Joins:
INNER,LEFT,RIGHT,FULLJOIN with type inference - Transactions: Atomic operations with auto-rollback
- Data Types:
String,Number,Boolean,Date,JSON,UUID,Enum,Array - DDL: Auto-generate tables from schema with
db.createTables() - Controllable RETURNING: Choose which columns to return from mutations
- Shortcuts:
.first()for single row,.count()for counting
When Should You Use PawQL?
Use PawQL if you:
- Prefer runtime schema over DSL files
- Want type inference without code generation
- Need a lightweight alternative to heavy ORMs
- Work in serverless or edge environments
- Prefer clean, minimal APIs
Installation
npm install pawql pg
pgis a peer dependency for PostgreSQL connectivity.
Quick Start
import { createDB, PostgresAdapter } from 'pawql';
// 1. Define your schema using plain JS objects
const db = createDB({
users: {
id: { type: Number, primaryKey: true },
name: String,
email: { type: String, nullable: true },
age: Number,
isActive: { type: Boolean, default: true },
},
posts: {
id: { type: Number, primaryKey: true },
userId: Number,
title: String,
content: String,
}
}, new PostgresAdapter({ connectionString: process.env.DATABASE_URL }));
// 2. Create tables (DDL)
await db.createTables();
// 3. Insert data
await db.query('users')
.insert({ id: 1, name: 'Alice', email: '[email protected]', age: 28 })
.execute();
// 4. Query with full type inference
const activeUsers = await db.query('users')
.select('id', 'name')
.where({ isActive: true })
.orderBy('name', 'ASC')
.limit(10)
.execute();
// 5. Get a single row
const user = await db.query('users')
.where({ id: 1 })
.first(); // Returns single object or null
// 6. Count rows
const total = await db.query('users')
.where({ isActive: true })
.count(); // Returns numberAdvanced Types
import { createDB, PostgresAdapter, uuid, json, enumType, arrayType } from 'pawql';
const db = createDB({
events: {
id: uuid, // UUID
name: String, // TEXT
type: enumType('conference', 'meetup'), // TEXT + CHECK constraint
tags: arrayType(String), // TEXT[]
details: json<{ location: string }>(), // JSONB with TypeScript generic
createdAt: Date, // TIMESTAMP
}
}, adapter);Documentation
For complete documentation, see the docs/ directory:
- Getting Started — Installation, setup, first query
- Schema Definition — Defining tables, columns, and types
- Querying — SELECT, WHERE, ORDER BY, LIMIT, joins
- Mutations — INSERT, UPDATE, DELETE, RETURNING
- Transactions — Atomic operations
- Testing — Using DummyAdapter for testing
- API Reference — Complete API listing
Philosophy
Most ORMs require a separate schema definition language or complex build steps. PawQL takes a different approach: your schema is just JavaScript. TypeScript infers everything at compile time, giving you full autocomplete and type checking without any extra tooling.
License
MIT — Ahmat Fauzi
