/** * BaseQuintStore - 统一的 QuintStore 抽象基类 * * 支持: * - SQLite (via pluggable SQLite runtime + drizzle-orm) * - PGLite (via @electric-sql/pglite + drizzle-orm) * - PostgreSQL (via pg + drizzle-orm) - 未来 * * 设计: * - 所有 SQL 逻辑在基类中实现 * - 子类只负责创建数据库连接和执行原生 SQL */ import { AsyncIterator } from 'asynciterator'; import type { Term } from '@rdfjs/types'; import type { Quint, QuintPattern, QuintStoreOptions, QueryOptions, StoreStats, TermMatch, CompoundPattern, CompoundResult, OperatorValue, AttributeMap } from './types'; import { QuintStore } from './types'; export interface QuintRow { graph: string; subject: string; predicate: string; object: string; vector: string | null; } /** * SQL 执行器接口 - 子类实现 */ export interface SqlExecutor { /** 执行查询,返回行数组 */ query(sql: string, params?: any[]): Promise; /** 执行更新,返回影响行数 */ execute(sql: string, params?: any[]): Promise; /** 执行多条语句(事务内) */ executeInTransaction(statements: { sql: string; params?: any[]; }[]): Promise; /** 执行原生 SQL(建表等) */ exec(sql: string): Promise; } export declare abstract class BaseQuintStore extends QuintStore { protected options: QuintStoreOptions; protected executor: SqlExecutor | null; protected opened: boolean; protected opening: Promise | null; constructor(options: QuintStoreOptions); protected abstract createExecutor(): Promise; protected abstract closeExecutor(): Promise; open(): Promise; protected openOnce(): Promise; close(): Promise; protected ensureOpen(): void; get(pattern: QuintPattern, options?: QueryOptions): Promise; match(subject?: Term | null, predicate?: Term | null, object?: Term | null, graph?: Term | null): AsyncIterator; getByGraphPrefix(prefix: string, options?: QueryOptions): Promise; count(pattern: QuintPattern): Promise; getCompound(compound: CompoundPattern, options?: QueryOptions): Promise; getAttributes(subjects: string[], predicates: string[], graph?: Term): Promise; put(quint: Quint): Promise; multiPut(quintList: Quint[]): Promise; updateEmbedding(pattern: QuintPattern, embedding: number[]): Promise; del(pattern: QuintPattern): Promise; multiDel(quintList: Quint[]): Promise; stats(): Promise; clear(): Promise; protected buildSelectQuery(pattern: QuintPattern, options?: QueryOptions): { sql: string; params: any[]; }; protected buildWhereClause(pattern: QuintPattern): { whereClause: string; params: any[]; }; protected addConditions(conditions: string[], params: any[], column: string, match: TermMatch | undefined, isObject: boolean): void; protected serializeOpValue(value: OperatorValue, isObject: boolean, filterOp: string): any; protected buildCompoundQuery(compound: CompoundPattern, options?: QueryOptions): { sql: string; params: any[]; }; protected quintToRow(quint: Quint): QuintRow; protected rowToQuint(row: QuintRow): Quint; protected deserializeObject(value: string): Term; protected resolveObjectDataTypeForPattern(_pattern: QuintPattern): string | undefined; protected extractExactPredicate(match: TermMatch | undefined): string | undefined; protected addTermConditions(conditions: string[], params: any[], column: string, match: TermMatch | undefined, isObject: boolean): void; protected addAliasedConditions(conditions: string[], params: any[], alias: string, pattern: QuintPattern): void; }