Skip to content

Commit 50969ee

Browse files
committed
feat: 更新内存驱动,添加流式查找和合并功能,优化查询参数
1 parent 39f4c77 commit 50969ee

File tree

4 files changed

+47
-559
lines changed

4 files changed

+47
-559
lines changed

packages/driver-memory/src/memory-driver.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ export class InMemoryDriver implements DriverInterface {
2626
queryFilters: false, // TODO: Not implemented - basic find() doesn't handle filters
2727
queryAggregations: false, // TODO: Not implemented - count() only returns total
2828
querySorting: false, // TODO: Not implemented - find() doesn't handle sorting
29-
queryPagination: true, // Basic pagination via 'top' is implemented
29+
queryPagination: true, // Basic pagination via 'limit' is implemented
3030
queryWindowFunctions: false, // TODO: Not implemented
3131
querySubqueries: false, // TODO: Not implemented
3232
joins: false, // TODO: Not implemented
3333

3434
// Advanced Features
3535
fullTextSearch: false, // TODO: Not implemented
36+
vectorSearch: false, // TODO: Not implemented
37+
geoSpatial: false, // TODO: Not implemented
3638
jsonFields: true, // Native JS object support
3739
arrayFields: true, // Native JS array support
3840
};
@@ -79,15 +81,22 @@ export class InMemoryDriver implements DriverInterface {
7981
let results = [...table];
8082

8183
// Simple limiting for demonstration
82-
if (query.top) {
83-
results = results.slice(0, query.top);
84+
if (query.limit) {
85+
results = results.slice(0, query.limit);
8486
}
8587

8688
return results;
8789
}
8890

91+
async *findStream(object: string, query: QueryInput, options?: DriverOptions) {
92+
const results = await this.find(object, query, options);
93+
for (const record of results) {
94+
yield record;
95+
}
96+
}
97+
8998
async findOne(object: string, query: QueryInput, options?: DriverOptions) {
90-
const results = await this.find(object, { ...query, top: 1 }, options);
99+
const results = await this.find(object, { ...query, limit: 1 }, options);
91100
return results[0] || null;
92101
}
93102

@@ -124,6 +133,23 @@ export class InMemoryDriver implements DriverInterface {
124133
return updatedRecord;
125134
}
126135

136+
async upsert(object: string, data: Record<string, any>, conflictKeys?: string[], options?: DriverOptions) {
137+
const table = this.getTable(object);
138+
let existingRecord: any = null;
139+
140+
if (data.id) {
141+
existingRecord = table.find(r => r.id === data.id);
142+
} else if (conflictKeys && conflictKeys.length > 0) {
143+
existingRecord = table.find(r => conflictKeys.every(key => r[key] === data[key]));
144+
}
145+
146+
if (existingRecord) {
147+
return this.update(object, existingRecord.id, data, options);
148+
} else {
149+
return this.create(object, data, options);
150+
}
151+
}
152+
127153
async delete(object: string, id: string | number, options?: DriverOptions) {
128154
const table = this.getTable(object);
129155
const index = table.findIndex(r => r.id == id);

packages/objectql/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { QueryAST } from '@objectstack/spec/data';
2-
import { DriverInterface, DriverOptions, ObjectStackManifest } from '@objectstack/spec/system';
2+
import { ObjectStackManifest } from '@objectstack/spec/system';
3+
import { DriverInterface, DriverOptions } from '@objectstack/spec/driver';
34
import { SchemaRegistry } from './registry';
45

56
// Export Registry for consumers
@@ -158,9 +159,9 @@ export class ObjectQL {
158159
object, // Add missing required field
159160
// Pass through if it looks like AST, otherwise empty
160161
// In this demo, we assume the caller passes a simplified object or raw AST
161-
filters: filters.filters || undefined,
162-
top: filters.top || 100,
163-
sort: filters.sort || []
162+
where: filters.filters || filters.where || undefined,
163+
limit: filters.limit || filters.top || 100,
164+
orderBy: filters.orderBy || filters.sort || []
164165
};
165166

166167
return driver.find(object, ast, options);

packages/spec/package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"types": "./dist/index.d.ts",
1010
"default": "./dist/index.js"
1111
},
12+
"./driver": {
13+
"types": "./dist/driver/index.d.ts",
14+
"default": "./dist/driver/index.js"
15+
},
1216
"./data": {
1317
"types": "./dist/data/index.d.ts",
1418
"default": "./dist/data/index.js"
1519
},
16-
"./ui": {
17-
"types": "./dist/ui/index.d.ts",
18-
"default": "./dist/ui/index.js"
19-
},
2020
"./system": {
2121
"types": "./dist/system/index.d.ts",
2222
"default": "./dist/system/index.js"
@@ -25,9 +25,17 @@
2525
"types": "./dist/ai/index.d.ts",
2626
"default": "./dist/ai/index.js"
2727
},
28+
"./automation": {
29+
"types": "./dist/automation/index.d.ts",
30+
"default": "./dist/automation/index.js"
31+
},
2832
"./api": {
2933
"types": "./dist/api/index.d.ts",
3034
"default": "./dist/api/index.js"
35+
},
36+
"./ui": {
37+
"types": "./dist/ui/index.d.ts",
38+
"default": "./dist/ui/index.js"
3139
}
3240
},
3341
"files": [

0 commit comments

Comments
 (0)