Skip to content

Commit 384671b

Browse files
committed
重构文档结构,更新导航和侧边栏标题,添加微服务与查询数据的指南
1 parent 28c08d3 commit 384671b

6 files changed

Lines changed: 273 additions & 67 deletions

File tree

docs/.vitepress/config.mts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default defineConfig({
1515
// Top Navigation
1616
nav: [
1717
{ text: 'Guide', link: '/guide/' },
18-
{ text: 'AI', link: '/ai/' },
18+
{ text: 'AI-Native', link: '/ai/' },
1919
{ text: 'Protocol', link: '/spec/' },
2020
],
2121

@@ -24,7 +24,7 @@ export default defineConfig({
2424
// Sidebar for AI section
2525
'/ai/': [
2626
{
27-
text: 'AI Integration',
27+
text: 'AI-Native Ecosystem',
2828
items: [
2929
{ text: 'Overview', link: '/ai/' },
3030
{ text: 'Building AI Apps', link: '/ai/building-apps' },
@@ -36,30 +36,36 @@ export default defineConfig({
3636
// Sidebar for Guide section
3737
'/guide/': [
3838
{
39-
text: 'Core Concepts',
39+
text: 'Start Here',
4040
items: [
4141
{ text: 'Introduction', link: '/guide/' },
42-
{ text: 'Architecture', link: '/guide/architecture' },
4342
{ text: 'Quick Start', link: '/guide/getting-started' },
44-
{ text: 'Configuration', link: '/guide/configuration' },
45-
{ text: 'Data Modeling', link: '/guide/data-modeling' },
43+
{ text: '🤖 AI Coding Setup', link: '/ai/coding-assistant' },
4644
]
4745
},
4846
{
49-
text: 'Database Drivers',
47+
text: 'Core Fundamentals',
5048
items: [
51-
{ text: 'Overview', link: '/guide/drivers/' },
52-
{ text: 'SQL (Knex)', link: '/guide/drivers/sql' },
53-
{ text: 'MongoDB', link: '/guide/drivers/mongo' },
49+
{ text: 'Data Modeling', link: '/guide/data-modeling' },
50+
{ text: 'Querying Data', link: '/guide/querying' },
51+
{ text: 'Business Logic', link: '/guide/logic-hooks' },
5452
]
5553
},
5654
{
57-
text: 'Building Apps',
55+
text: 'Advanced Features',
5856
items: [
59-
{ text: 'Writing Hooks', link: '/guide/logic-hooks' },
60-
{ text: 'Custom Actions', link: '/guide/logic-actions' },
57+
{ text: 'Microservices & Federation', link: '/guide/microservices' },
58+
{ text: 'Custom Actions (RPC)', link: '/guide/logic-actions' },
6159
{ text: 'Plugin System', link: '/guide/plugins' },
62-
{ text: 'CLI Tools', link: '/guide/cli' }
60+
]
61+
},
62+
{
63+
text: 'Integration & Deployment',
64+
items: [
65+
{ text: 'Server Integration', link: '/guide/server-integration' },
66+
{ text: 'Database Drivers', link: '/guide/drivers/' },
67+
{ text: 'CLI Tools', link: '/guide/cli' },
68+
{ text: 'Configuration', link: '/guide/configuration' },
6369
]
6470
}
6571
],

docs/ai/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AI Integration
1+
# AI-Native Development
22

33
ObjectQL resides at the intersection of Data and Artificial Intelligence. It is designed to be "AI-Native" in two distinct ways:
44

docs/guide/index.md

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,56 @@
1-
# Developer & User Guide
2-
3-
Welcome to the ObjectQL User Guide. This documentation is designed to help you build applications using the ObjectQL platform.
4-
5-
## 1. Core Concepts
6-
* [**Architecture**](./architecture.md): Understand how ObjectQL works under the hood.
7-
* [**Getting Started**](./getting-started.md): Installation and a "Hello World" example.
8-
* [**Data Modeling**](./data-modeling.md): Learn how to define Objects, Fields, and Relationships.
9-
10-
## 2. Database Drivers
11-
ObjectQL connects to your database via drivers.
12-
* [**Driver Overview**](./drivers/index.md)
13-
* [**SQL (Knex)**](./drivers/sql.md): Postgres, MySQL, SQLite, MSSQL.
14-
* [**MongoDB**](./drivers/mongo.md): MongoDB support.
15-
16-
## 3. Building Apps
17-
* [**Server Integration**](./server-integration.md): Running ObjectQL on Node, Express, or Next.js.
18-
* [**Hooks**](./logic-hooks.md): Writing triggers (before/after create, update, delete).
19-
* [**Custom Actions**](./logic-actions.md): Defining custom RPC endpoints.
20-
* [**AI Applications**](./ai.md): Building AI-powered apps.
1+
# Introduction
2+
3+
**ObjectQL** is a protocol-first application engine. It rethinks backend development by treating everything—Data Models, Queries, and Logic—as **structured data** rather than code strings.
4+
5+
## The Core Philosophy
6+
7+
### 1. The JSON Protocol
8+
In traditional development, you write SQL strings (`SELECT * FROM users`) or use fluent builders (`db.select('users')`).
9+
In ObjectQL, the query **IS** the data structure.
10+
11+
```json
12+
// Find users where age > 18
13+
{
14+
"op": "find",
15+
"object": "user",
16+
"args": {
17+
"filters": [["age", ">", 18]]
18+
}
19+
}
20+
```
21+
22+
This makes the protocol:
23+
* **Universal**: Can be generated by any client (JS, Python, Swift, or LLMs).
24+
* **Serialization-ready**: Pass it over HTTP, WebSocket, or save it to a file.
25+
* **Secure**: Zero SQL injection risk by design.
26+
27+
### 2. Metadata as Source of Truth
28+
Instead of defining TypeScript classes or SQL DDL, you define your business domain in declarative YAML.
29+
30+
```yaml
31+
# user.object.yml
32+
name: user
33+
fields:
34+
email: { type: email, unique: true }
35+
role: { type: select, options: [admin, user] }
36+
```
37+
38+
This metadata is loaded at runtime to:
39+
* Auto-generate database schemas (tables/collections).
40+
* Auto-generate TypeScript types.
41+
* Auto-validate incoming requests.
42+
43+
### 3. Logic as Graph
44+
Your application logic isn't hidden inside controller functions. It's attached to the Graph as **Hooks** and **Actions**.
45+
46+
* **Hook**: "When `user` is created, send email."
47+
* **Action**: "Expose RPC `resetPassword` on `user`."
48+
49+
## Why use ObjectQL?
50+
51+
* **For AI**: It demands structured input/output, which fits AI Agent capabilities perfectly.
52+
* **For Low-Code**: The rigorous structure makes it easy to build UI visual editors on top of it.
53+
* **For Microservices**: The federation protocol allows you to stitch multiple services into one graph instantly.
54+
2155

2256
* [**CLI Tool**](./cli.md): Using the command line interface for codegen.

docs/guide/microservices.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Microservices & Federation
2+
3+
ObjectQL provides a built-in mechanism to aggregate data from multiple services into a single unified graph. This is similar to **GraphQL Federation** or Salesforce's **External Objects**, but strictly for the ObjectQL protocol.
4+
5+
## Concept: Remote Remotes
6+
7+
You can configure an ObjectQL instance to act as a **Gateway**. It connects to other ObjectQL instances, downloads their metadata (Schema), and automatically creates proxy drivers for them.
8+
9+
* **Source of Truth**: The microservice defines the object (`user.object.yml`).
10+
* **Proxy**: The gateway sees a virtual object (`user`) and forwards all queries (Find, Update, Actions) to the microservice.
11+
12+
## Configuration
13+
14+
### The Subgraph (Service A)
15+
16+
This is a standard ObjectQL service running standard drivers (SQL/Mongo).
17+
It must expose the metadata API (default in `@objectql/server`).
18+
19+
```typescript
20+
// user-service/index.ts
21+
const app = new ObjectQL({
22+
source: './src/objects', // Defines 'user', 'role'
23+
datasources: { ... }
24+
});
25+
// Exposes http://user-service:3000/api/metadata/objects
26+
```
27+
28+
### The Gateway
29+
30+
The gateway aggregates multiple services.
31+
32+
```typescript
33+
// gateway/index.ts
34+
const app = new ObjectQL({
35+
// No local source needed, just remotes
36+
remotes: [
37+
'http://user-service:3000',
38+
'http://order-service:3000'
39+
]
40+
});
41+
42+
await app.init();
43+
```
44+
45+
### Usage
46+
47+
Once initialized, the Gateway behaves exactly like a monolith.
48+
49+
```typescript
50+
// Code running on Gateway
51+
// Transparently forwards request to User Service via HTTP
52+
const users = await app.object('user').find({
53+
filters: [['status', '=', 'active']]
54+
});
55+
```
56+
57+
## Benefits
58+
59+
1. **Decoupling**: Services manage their own schema migrations and domain logic.
60+
2. **Unity**: Frontend or upper layers see a single API surface.
61+
3. **Hybrid**: A Gateway can *also* have local objects. You can mix "local cache tables" with "remote live tables" in the same application.

docs/guide/querying.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Querying Data
2+
3+
ObjectQL uses a **JSON-based Protocol** for all data operations. Unlike SQL (strings) or Query Builders (chained methods), ObjectQL queries are **Data Structures**.
4+
5+
This design makes it strictly typed, easy to serialise/transport over HTTP, and safe from injection—perfect for both human developers and AI Agents.
6+
7+
## The `find()` Operation
8+
9+
The `find` method recovers a list of records matching specific criteria.
10+
11+
```typescript
12+
const products = await app.object('product').find({
13+
filters: [
14+
['category', '=', 'electronics'],
15+
['price', '>', 500]
16+
],
17+
fields: ['name', 'price', 'category'],
18+
sort: ['-price'], // Descending
19+
skip: 0,
20+
limit: 10
21+
});
22+
```
23+
24+
### Filters
25+
26+
Filters are defined as a 2D array: `[[ field, operator, value ]]`.
27+
28+
**Implicit AND**:
29+
```typescript
30+
filters: [
31+
['status', '=', 'active'],
32+
['stock', '>', 0]
33+
]
34+
// SQL: WHERE status = 'active' AND stock > 0
35+
```
36+
37+
**Explicit OR**:
38+
Use the `_or` special operator in complex filters (see advanced docs).
39+
40+
### Sorting
41+
42+
* `field`: Ascending.
43+
* `-field`: Descending.
44+
45+
## CRUD Operations
46+
47+
### Create (Insert)
48+
49+
```typescript
50+
const id = await app.object('user').insert({
51+
name: "Alice",
52+
email: "alice@example.com",
53+
role: "admin"
54+
});
55+
```
56+
57+
### Update
58+
59+
Updates are always bulk operations targeted by `filters`. To update a single record, filter by ID.
60+
61+
```typescript
62+
// Update specific record
63+
await app.object('user').update(
64+
{ filters: [['_id', '=', '123']] }, // Target
65+
{ doc: { status: 'active' } } // Change
66+
);
67+
68+
// Bulk update
69+
await app.object('product').update(
70+
{ filters: [['stock', '=', 0]] },
71+
{ doc: { status: 'out_of_stock' } }
72+
);
73+
```
74+
75+
### Delete
76+
77+
```typescript
78+
// Delete specific record
79+
await app.object('user').delete({
80+
filters: [['_id', '=', '123']]
81+
});
82+
```
83+
84+
## Relationships (Joins)
85+
86+
ObjectQL handles joins automatically via the `expand` option or dot-notation in `fields` (depending on the driver implementation).
87+
88+
```typescript
89+
// Fetch orders and expand the related 'user'
90+
const orders = await app.object('order').find({
91+
fields: ['id', 'total', 'user.name', 'user.email']
92+
});
93+
```
94+
95+
## Why JSON?
96+
97+
1. **Transportable**: The query IS the HTTP request body. No translation needed.
98+
2. **Secure**: Impossible to inject SQL syntax.
99+
3. **Generatable**: LLMs produce perfect JSON structures naturally.

0 commit comments

Comments
 (0)