Super lightweight generic typed SQL query builder, SQL dialects and composite engine.
npm install @stackpress/inquire




Super lightweight generic typed SQL query builder, SQL dialects and composite engine. Schema builder, but no ORM. Bring your own database library.
Inquire is a powerful yet lightweight SQL query builder that provides a unified interface for working with multiple database engines. Unlike traditional ORMs, Inquire focuses on query building and execution while letting you bring your own database connection library. This approach gives you the flexibility to use your preferred database driver while benefiting from a consistent, type-safe query building experience.
- ðŠķ Lightweight: No ORM overhead - just pure query building
- ð§ Generic Typed: Full TypeScript support with generic types for enhanced type safety
- ðïļ Multi-Database: Same expressive query builder pattern for all SQL engines
- ð Unified Interface: Consistent API across different database engines
- ð Schema Builder: Create and modify database schemas programmatically
- ð Template Strings: Support for type-safe template string query building
- ⥠Transaction Support: Common transaction pattern across all engines
- ðŊ Dialect Agnostic: Query builders work with any supported SQL dialect
Inquire supports a wide range of database engines through dedicated connection packages:
- MySQL - via @stackpress/inquire-mysql2 (Node MySQL2)
- PostgreSQL - via @stackpress/inquire-pg (Node PostGres pg)
- SQLite - via @stackpress/inquire-sqlite3 (Better SQLite3)
- PGLite - via @stackpress/inquire-pglite (PGLite)
- CockroachDB - Compatible with PostgreSQL adapter
- NeonDB - Compatible with PostgreSQL adapter
- Vercel Postgres - Compatible with PostgreSQL adapter
- Supabase - Compatible with PostgreSQL adapter
Install the core library:
``bash`
npm install @stackpress/inquire
Then install the appropriate database adapter:
`bashFor MySQL
npm install @stackpress/inquire-mysql2 mysql2
Quick Start
$3
`typescript
import mysql from 'mysql2/promise';
import connect from '@stackpress/inquire-mysql2';// Create the raw database connection
const resource = await mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'inquire',
});
// Map the resource to the Inquire engine
const engine = connect(resource);
`$3
`typescript
import { Client, Pool } from 'pg';
import connect from '@stackpress/inquire-pg';// Using a Pool
const pool = new Pool({
database: 'inquire',
user: 'postgres'
});
const connection = await pool.connect();
// Or using a Client
const client = new Client({
database: 'inquire',
user: 'postgres'
});
await client.connect();
// Map the resource to the Inquire engine
const engine = connect(connection); // or connect(client)
`$3
`typescript
import sqlite from 'better-sqlite3';
import connect from '@stackpress/inquire-sqlite3';// Create the raw database connection
const resource = sqlite(':memory:');
// Map the resource to the Inquire engine
const engine = connect(resource);
`Basic Usage
Once you have an engine instance, you can start building and executing queries:
`typescript
// Create a table
await engine.create('users')
.addField('id', { type: 'INTEGER', autoIncrement: true })
.addField('name', { type: 'VARCHAR', length: 255 })
.addField('email', { type: 'VARCHAR', length: 255 })
.addPrimaryKey('id');// Insert data
await engine
.insert('users')
.values({ name: 'John Doe', email: 'john@example.com' });
// Select data
const users = await engine
.select('*')
.from('users')
.where('name = ?', ['John Doe']);
console.log(users);
// Update data
await engine
.update('users')
.set({ email: 'john.doe@example.com' })
.where('id = ?', [1]);
// Delete data
await engine
.delete('users')
.where('id = ?', [1]);
`Query Builders
Inquire provides comprehensive query builders for all common SQL operations:
- Create - Create tables and schemas
- Alter - Modify existing tables
- Select - Query data with joins, conditions, and aggregations
- Insert - Insert single or multiple records
- Update - Update existing records
- Delete - Delete records with conditions
Template String Queries
For complex queries, you can use type-safe template strings:
`typescript
type User = {
id: number;
name: string;
email: string;
};const userId = 123;
const results = await engine.sql
;
// results is typed as User[]
`Transactions
Execute multiple queries in a transaction:
`typescript
const result = await engine.transaction(async (trx) => {
await trx.insert('users').values({ name: 'Alice' });
await trx.insert('posts').values({ title: 'Hello World', user_id: 1 });
return 'success';
});
`Type Safety
Inquire is designed with TypeScript in mind, providing full type safety:
`typescript
type User = {
id: number;
name: string;
email: string;
};// Type-safe queries
const users = await engine.select('*').from('users');
// users is now typed as User[]
const user = await engine.select('*')
.from('users')
.where('id = ?', [1])
.limit(1);
// user is typed as User[]
``For detailed API documentation, see:
- Engine - Core engine class and methods
- Connection Classes - Database-specific connection implementations
- Query Builders - Detailed documentation for all query builders
- SQL Dialects - Detailed documentation for all SQL dialects
- Examples - Comprehensive usage examples
Check out the examples directory for complete working examples with different database engines:
- MySQL Example
- PostgreSQL Example
- SQLite Example
- PGLite Example