Dialects
Write once, deploy anywhere. genaql supports PostgreSQL, MySQL, and SQLite with automatic syntax conversion.
Supported Databases
PostgreSQL
Full support with JSONB, arrays, and advanced features.
dialect: 'postgres'MySQL
Compatible with MySQL 5.7+ and MariaDB.
dialect: 'mysql'SQLite
Perfect for local development and embedded apps.
dialect: 'sqlite'Configuring a Dialect
config.ts
import { createClient } from 'genaql';
// PostgreSQL
const pgClient = createClient({
dialect: 'postgres',
pool: pgPool
});
// MySQL
const mysqlClient = createClient({
dialect: 'mysql',
pool: mysqlPool
});
// SQLite
const sqliteClient = createClient({
dialect: 'sqlite',
database: './data.db'
});Placeholder Syntax
genaql automatically converts placeholders to match each database's syntax:
placeholders.ts
const query = cook`main:users slay:* sus:id=1 sus:role=admin`;
// PostgreSQL: WHERE id = $1 AND role = $2
// MySQL: WHERE id = ? AND role = ?
// SQLite: WHERE id = ? AND role = ?Dialect Differences
| Feature | PostgreSQL | MySQL | SQLite |
|---|---|---|---|
| RETURNING | ✓ | ✗ | ✓ (3.35+) |
| UPSERT | ON CONFLICT | ON DUPLICATE KEY | ON CONFLICT |
| JSONB | ✓ | JSON (5.7+) | ✗ |
| Arrays | ✓ | ✗ | ✗ |
| FULL OUTER JOIN | ✓ | ✗ | ✓ |
Cross-Database Testing
Use SQLite for fast tests, PostgreSQL for production:
testing.ts
// test.ts
const testDb = createClient({
dialect: 'sqlite',
database: ':memory:' // In-memory for speed
});
// production.ts
const prodDb = createClient({
dialect: 'postgres',
pool: pgPool
});
// Same queries work in both!
const query = cook`main:users slay:* sus:active=true`;Dialect Detection
genaql will warn you at compile time if you use a feature that isn't supported by your configured dialect, preventing runtime surprises.