Skip to content

Commit a71f6cb

Browse files
committed
Updated documentation
1 parent e0139d3 commit a71f6cb

23 files changed

Lines changed: 14915 additions & 182 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,7 @@ packages/*/tests/database
133133

134134
yarn.lock
135135
cjs/
136-
esm/
136+
esm/
137+
138+
# AI
139+
.clinerules

README.md

Lines changed: 193 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,119 +8,232 @@
88

99
Super lightweight generic typed SQL query builder, SQL dialects and composite engine. Schema builder, but no ORM. Bring your own database library.
1010

11-
- Node MySQL2
12-
- Better SQLite3
13-
- Node PostGres (pg)
14-
- PGLite
15-
- CockroachDB
16-
- NeonDB
17-
- Vercel Postgres
11+
## What is Inquire?
1812

19-
## Install
13+
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.
14+
15+
## Key Features
16+
17+
- **🪶 Lightweight**: No ORM overhead - just pure query building
18+
- **🔧 Generic Typed**: Full TypeScript support with generic types for enhanced type safety
19+
- **🗄️ Multi-Database**: Same expressive query builder pattern for all SQL engines
20+
- **🔄 Unified Interface**: Consistent API across different database engines
21+
- **📝 Schema Builder**: Create and modify database schemas programmatically
22+
- **🔗 Template Strings**: Support for type-safe template string query building
23+
- **⚡ Transaction Support**: Common transaction pattern across all engines
24+
- **🎯 Dialect Agnostic**: Query builders work with any supported SQL dialect
25+
26+
## Supported Databases
27+
28+
Inquire supports a wide range of database engines through dedicated connection packages:
29+
30+
- **MySQL** - via `@stackpress/inquire-mysql2` (Node MySQL2)
31+
- **PostgreSQL** - via `@stackpress/inquire-pg` (Node PostGres pg)
32+
- **SQLite** - via `@stackpress/inquire-sqlite3` (Better SQLite3)
33+
- **PGLite** - via `@stackpress/inquire-pglite` (PGLite)
34+
- **CockroachDB** - Compatible with PostgreSQL adapter
35+
- **NeonDB** - Compatible with PostgreSQL adapter
36+
- **Vercel Postgres** - Compatible with PostgreSQL adapter
37+
- **Supabase** - Compatible with PostgreSQL adapter
38+
39+
## Installation
40+
41+
Install the core library:
2042

2143
```bash
22-
$ npm i @stackpress/inquire
44+
npm install @stackpress/inquire
2345
```
2446

25-
## MySQL Connection
47+
Then install the appropriate database adapter:
48+
49+
```bash
50+
# For MySQL
51+
npm install @stackpress/inquire-mysql2 mysql2
52+
53+
# For PostgreSQL
54+
npm install @stackpress/inquire-pg pg
55+
56+
# For SQLite
57+
npm install @stackpress/inquire-sqlite3 better-sqlite3
58+
59+
# For PGLite
60+
npm install @stackpress/inquire-pglite @electric-sql/pglite
61+
```
2662

27-
```js
63+
## Quick Start
64+
65+
### MySQL Connection
66+
67+
```typescript
2868
import mysql from 'mysql2/promise';
2969
import connect from '@stackpress/inquire-mysql2';
3070

31-
//this is the raw resource, anything you want
71+
// Create the raw database connection
3272
const resource = await mysql.createConnection({
3373
host: 'localhost',
3474
user: 'root',
3575
database: 'inquire',
3676
});
37-
//this maps the resource to the engine
77+
78+
// Map the resource to the Inquire engine
3879
const engine = connect(resource);
3980
```
4081

41-
## PostGreSQL Connection
82+
### PostgreSQL Connection
4283

43-
```js
84+
```typescript
4485
import { Client, Pool } from 'pg';
4586
import connect from '@stackpress/inquire-pg';
4687

47-
//this is the raw resource, anything you want
48-
const connection = usePool
49-
? await (async () => {
50-
const pool = new Pool({
51-
database: 'inquire',
52-
user: 'postgres'
53-
});
54-
return await pool.connect();
55-
})()
56-
: await (async () => {
57-
const resource = new Client({
58-
database: 'inquire',
59-
user: 'postgres'
60-
});
61-
await resource.connect();
62-
return resource;
63-
})();
64-
65-
//this maps the resource to the engine
66-
const engine = connect(connection);
88+
// Using a Pool
89+
const pool = new Pool({
90+
database: 'inquire',
91+
user: 'postgres'
92+
});
93+
const connection = await pool.connect();
94+
95+
// Or using a Client
96+
const client = new Client({
97+
database: 'inquire',
98+
user: 'postgres'
99+
});
100+
await client.connect();
101+
102+
// Map the resource to the Inquire engine
103+
const engine = connect(connection); // or connect(client)
67104
```
68105

69-
## SQLite Connection
106+
### SQLite Connection
70107

71-
```js
108+
```typescript
72109
import sqlite from 'better-sqlite3';
73110
import connect from '@stackpress/inquire-sqlite3';
74111

75-
//this is the raw resource, anything you want
112+
// Create the raw database connection
76113
const resource = sqlite(':memory:');
77-
//this maps the resource to the engine
114+
115+
// Map the resource to the Inquire engine
78116
const engine = connect(resource);
79117
```
80118

81-
## Usage
119+
## Basic Usage
120+
121+
Once you have an engine instance, you can start building and executing queries:
82122

83-
```js
84-
const create = engine.create('profile')
85-
.addField('id', { type: 'INTEGER' })
123+
```typescript
124+
// Create a table
125+
await engine.create('users')
126+
.addField('id', { type: 'INTEGER', autoIncrement: true })
86127
.addField('name', { type: 'VARCHAR', length: 255 })
128+
.addField('email', { type: 'VARCHAR', length: 255 })
87129
.addPrimaryKey('id');
88-
console.log(create.query());
89-
console.log(await create);
90-
91-
const insert = engine
92-
.insert('profile')
93-
.values({ id: '1', name: 'John Doe' });
94-
console.log(insert.query());
95-
console.log(JSON.stringify(await insert, null, 2));
96-
97-
const select = engine.select('*').from('profile');
98-
console.log(select.query());
99-
console.log(JSON.stringify(await select, null, 2));
100-
101-
const update = engine
102-
.update('profile')
103-
.set({ name: 'Jane Doe' })
104-
.where('id = ?', [ '1' ]);
105-
console.log(update.query());
106-
console.log(JSON.stringify(await update, null, 2));
107-
console.log(JSON.stringify(await select, null, 2));
108-
109-
const remove = engine
110-
.delete('profile')
111-
.where('id = ?', [ '1' ]);
112-
console.log(remove.query());
113-
console.log(JSON.stringify(await remove, null, 2));
114-
console.log(JSON.stringify(await select, null, 2));
115-
116-
if (usePool && connection instanceof Client === false) {
117-
connection.release();
118-
}
119-
120-
if (connection instanceof Client) {
121-
await connection.end();
122-
}
130+
131+
// Insert data
132+
await engine
133+
.insert('users')
134+
.values({ name: 'John Doe', email: 'john@example.com' });
135+
136+
// Select data
137+
const users = await engine
138+
.select('*')
139+
.from('users')
140+
.where('name = ?', ['John Doe']);
141+
142+
console.log(users);
143+
144+
// Update data
145+
await engine
146+
.update('users')
147+
.set({ email: 'john.doe@example.com' })
148+
.where('id = ?', [1]);
149+
150+
// Delete data
151+
await engine
152+
.delete('users')
153+
.where('id = ?', [1]);
123154
```
124155

125-
See [examples](https://github.com/stackpress/inquire/tree/main/examples)
126-
for other ways to use.
156+
## Query Builders
157+
158+
Inquire provides comprehensive query builders for all common SQL operations:
159+
160+
- **[Create](./docs/builders/Create.md)** - Create tables and schemas
161+
- **[Alter](./docs/builders/Alter.md)** - Modify existing tables
162+
- **[Select](./docs/builders/Select.md)** - Query data with joins, conditions, and aggregations
163+
- **[Insert](./docs/builders/Insert.md)** - Insert single or multiple records
164+
- **[Update](./docs/builders/Update.md)** - Update existing records
165+
- **[Delete](./docs/builders/Delete.md)** - Delete records with conditions
166+
167+
## Template String Queries
168+
169+
For complex queries, you can use type-safe template strings:
170+
171+
```typescript
172+
type User = {
173+
id: number;
174+
name: string;
175+
email: string;
176+
};
177+
178+
const userId = 123;
179+
const results = await engine.sql<User>`
180+
SELECT u.*, p.title
181+
FROM users u
182+
LEFT JOIN posts p ON u.id = p.user_id
183+
WHERE u.id = ${userId}
184+
`;
185+
// results is typed as User[]
186+
```
187+
188+
## Transactions
189+
190+
Execute multiple queries in a transaction:
191+
192+
```typescript
193+
const result = await engine.transaction(async (trx) => {
194+
await trx.insert('users').values({ name: 'Alice' });
195+
await trx.insert('posts').values({ title: 'Hello World', user_id: 1 });
196+
return 'success';
197+
});
198+
```
199+
200+
## Type Safety
201+
202+
Inquire is designed with TypeScript in mind, providing full type safety:
203+
204+
```typescript
205+
type User = {
206+
id: number;
207+
name: string;
208+
email: string;
209+
};
210+
211+
// Type-safe queries
212+
const users = await engine.select<User>('*').from('users');
213+
// users is now typed as User[]
214+
215+
const user = await engine.select<User>('*')
216+
.from('users')
217+
.where('id = ?', [1])
218+
.limit(1);
219+
// user is typed as User[]
220+
```
221+
222+
## API Documentation
223+
224+
For detailed API documentation, see:
225+
226+
- **[Engine](./docs/Engine.md)** - Core engine class and methods
227+
- **[Connection Classes](./docs/Connections.md)** - Database-specific connection implementations
228+
- **[Query Builders](./docs/builders/README.md)** - Detailed documentation for all query builders
229+
- **[SQL Dialects](./docs/dialects/README.md)** - Detailed documentation for all SQL dialects
230+
- **[Examples](./docs/Examples.md)** - Comprehensive usage examples
231+
232+
## Examples
233+
234+
Check out the [examples directory](./examples) for complete working examples with different database engines:
235+
236+
- [MySQL Example](./examples/with-mysql2)
237+
- [PostgreSQL Example](./examples/with-pg)
238+
- [SQLite Example](./examples/with-sqlite3)
239+
- [PGLite Example](./examples/with-pglite)

context7.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://context7.com/schema/context7.json",
3+
"projectTitle": "Inquire",
4+
"description": "Super lightweight generic typed SQL query builder, SQL dialects and composite engine.",
5+
"folders": [],
6+
"excludeFolders": [],
7+
"excludeFiles": [ "Context.md" ],
8+
"rules": [],
9+
"previousVersions": []
10+
}

0 commit comments

Comments
 (0)