Skip to content

Commit 93b34d0

Browse files
committed
feat: 更新 IDataEngine 接口,添加批量操作、向量查找和聚合功能,重构数据访问方法
1 parent 3f03cfc commit 93b34d0

2 files changed

Lines changed: 219 additions & 270 deletions

File tree

packages/core/src/contracts/data-engine.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1-
import { QueryAST } from '@objectstack/spec/data';
2-
import { DriverOptions } from '@objectstack/spec/system';
1+
import {
2+
DataEngineQueryOptions,
3+
DataEngineInsertOptions,
4+
DataEngineUpdateOptions,
5+
DataEngineDeleteOptions,
6+
DataEngineAggregateOptions,
7+
DataEngineCountOptions,
8+
DataEngineRequest // Added Request type for batch
9+
} from '@objectstack/spec/data';
310

411
/**
512
* IDataEngine - Standard Data Engine Interface
613
*
714
* Abstract interface for data persistence capabilities.
815
* Following the Dependency Inversion Principle - plugins depend on this interface,
916
* not on concrete database implementations.
17+
*
18+
* Aligned with 'src/data/data-engine.zod.ts' in @objectstack/spec.
1019
*/
1120

12-
export interface DataEngineFilter {
13-
[key: string]: any;
14-
}
15-
16-
export interface DataEngineQueryOptions {
17-
/** Filter conditions */
18-
filter?: DataEngineFilter;
19-
/** Fields to select */
20-
select?: string[];
21-
/** Sort order */
22-
sort?: Record<string, 1 | -1 | 'asc' | 'desc'>;
23-
/** Limit number of results */
24-
limit?: number;
25-
/** Skip number of results */
26-
skip?: number;
27-
/** Maximum number of results */
28-
top?: number;
29-
}
30-
3121
export interface IDataEngine {
32-
insert(objectName: string, data: any): Promise<any>;
3322
find(objectName: string, query?: DataEngineQueryOptions): Promise<any[]>;
34-
update(objectName: string, id: any, data: any): Promise<any>;
35-
delete(objectName: string, id: any): Promise<boolean>;
23+
findOne(objectName: string, query?: DataEngineQueryOptions): Promise<any>;
24+
insert(objectName: string, data: any | any[], options?: DataEngineInsertOptions): Promise<any>;
25+
update(objectName: string, data: any, options?: DataEngineUpdateOptions): Promise<any>;
26+
delete(objectName: string, options?: DataEngineDeleteOptions): Promise<any>;
27+
count(objectName: string, query?: DataEngineCountOptions): Promise<number>;
28+
aggregate(objectName: string, query: DataEngineAggregateOptions): Promise<any[]>;
29+
30+
/**
31+
* Vector Search (AI/RAG)
32+
*/
33+
vectorFind?(objectName: string, vector: number[], options?: { filter?: any, limit?: number, select?: string[], threshold?: number }): Promise<any[]>;
34+
35+
/**
36+
* Batch Operations (Transactional)
37+
*/
38+
batch?(requests: DataEngineRequest[], options?: { transaction?: boolean }): Promise<any[]>;
39+
40+
* Execute raw command (Escape hatch)
41+
*/
42+
execute?(command: any, options?: Record<string, any>): Promise<any>;
3643
}
3744

3845
export interface DriverInterface {

0 commit comments

Comments
 (0)