Skip to content

Commit e55ddec

Browse files
Copilothotlong
andcommitted
docs: Update driver README files with plugin usage examples
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a666527 commit e55ddec

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

packages/drivers/memory/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,60 @@ pnpm add @objectql/driver-memory
4949

5050
## Basic Usage
5151

52+
### Plugin-Based Usage (Recommended)
53+
54+
```typescript
55+
import { ObjectQL } from '@objectql/core';
56+
import { createMemoryDriverPlugin } from '@objectql/driver-memory';
57+
58+
const app = new ObjectQL({
59+
plugins: [
60+
createMemoryDriverPlugin({
61+
name: 'default',
62+
config: {
63+
strictMode: false
64+
}
65+
})
66+
]
67+
});
68+
69+
// Register your schema
70+
app.registerObject({
71+
name: 'users',
72+
fields: {
73+
name: { type: 'text', required: true },
74+
email: { type: 'email', unique: true },
75+
role: { type: 'select', options: ['admin', 'user'] }
76+
}
77+
});
78+
79+
await app.init();
80+
81+
// Use it!
82+
const ctx = app.createContext({ isSystem: true });
83+
const repo = ctx.object('users');
84+
85+
// Create
86+
const user = await repo.create({
87+
name: 'Alice',
88+
email: 'alice@example.com',
89+
role: 'admin'
90+
});
91+
92+
// Find
93+
const users = await repo.find({
94+
filters: [['role', '=', 'user']]
95+
});
96+
97+
// Update
98+
await repo.update(user.id, { email: 'alice.new@example.com' });
99+
100+
// Delete
101+
await repo.delete(user.id);
102+
```
103+
104+
### Direct Driver Usage (Legacy)
105+
52106
```typescript
53107
import { ObjectQL } from '@objectql/core';
54108
import { MemoryDriver } from '@objectql/driver-memory';
@@ -96,6 +150,10 @@ await repo.update(user.id, { email: 'alice.new@example.com' });
96150
await repo.delete(user.id);
97151
```
98152

153+
## Plugin Protocol
154+
155+
The Memory driver now supports the @objectstack/spec plugin protocol. See [PLUGIN_PROTOCOL.md](../PLUGIN_PROTOCOL.md) for more details.
156+
99157
## Browser Usage
100158

101159
The Memory Driver works seamlessly in web browsers! Perfect for prototyping, client-side apps, and offline experiences.

packages/drivers/sql/README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,34 @@ npm install @objectql/driver-sql
1010

1111
## Usage
1212

13+
### Plugin-Based Usage (Recommended)
14+
1315
```typescript
16+
import { ObjectQL } from '@objectql/core';
17+
import { createSqlDriverPlugin } from '@objectql/driver-sql';
18+
19+
const app = new ObjectQL({
20+
plugins: [
21+
createSqlDriverPlugin({
22+
name: 'default',
23+
config: {
24+
client: 'sqlite3',
25+
connection: {
26+
filename: './data.db'
27+
},
28+
useNullAsDefault: true
29+
}
30+
})
31+
]
32+
});
33+
34+
await app.init();
35+
```
36+
37+
### Direct Driver Usage (Legacy)
38+
39+
```typescript
40+
import { ObjectQL } from '@objectql/core';
1441
import { SqlDriver } from '@objectql/driver-sql';
1542

1643
const driver = new SqlDriver({
@@ -21,9 +48,14 @@ const driver = new SqlDriver({
2148
useNullAsDefault: true
2249
});
2350

24-
const objectql = new ObjectQL({
51+
const app = new ObjectQL({
2552
datasources: {
2653
default: driver
2754
}
2855
});
2956
```
57+
58+
## Plugin Protocol
59+
60+
The SQL driver now supports the @objectstack/spec plugin protocol. See [PLUGIN_PROTOCOL.md](../PLUGIN_PROTOCOL.md) for more details.
61+

0 commit comments

Comments
 (0)