/** * PgQuintStore - PostgreSQL implementation of QuintStore * * 支持两种连接方式: * - PGLite: 嵌入式 PostgreSQL,用于测试 * - pg (node-postgres): 真正的 PostgreSQL 连接,用于生产 * * PostgreSQL 不支持 TEXT 字段中的 \0 (null) 字符, * 所以我们需要对序列化的字符串进行转换。 */ import type { Term } from '@rdfjs/types'; import { BaseQuintStore, type SqlExecutor } from './BaseQuintStore'; import type { AttributeMap, CompoundPattern, QuintStoreOptions, Quint, QuintPattern, QueryOptions, TermMatch } from './types'; import { type PredicateObjectDataType } from './value-types'; /** * PostgreSQL 连接配置 */ export interface PgQuintStoreOptions extends QuintStoreOptions { /** * 连接方式: * - 'pglite': 使用 PGLite 嵌入式数据库(测试用) * - 'pg': 使用 node-postgres 连接真正的 PostgreSQL(生产用) */ driver?: 'pglite' | 'pg'; /** PGLite 数据目录,仅当 driver='pglite' 时使用 */ dataDir?: string; /** PostgreSQL 连接字符串,仅当 driver='pg' 时使用 */ connectionString?: string; /** PostgreSQL 连接配置,仅当 driver='pg' 时使用 */ host?: string; port?: number; database?: string; user?: string; password?: string; /** * 共享的 pg Pool 实例(避免多个组件创建独立连接池导致死锁) * 如果提供,将忽略其他连接配置 */ pool?: any; } /** * PostgreSQL QuintStore 实现 */ export declare class PgQuintStore extends BaseQuintStore { private pglite; private pgPool; private pgOptions; private sharedPoolConfig; constructor(options: PgQuintStoreOptions); protected createExecutor(): Promise; protected closeExecutor(): Promise; /** * 重写 open 方法,处理 PostgreSQL 特定的语法 */ open(): Promise; protected openOnce(): Promise; /** * 重写 put 方法,避免长文本对象进入 PostgreSQL btree 唯一键 */ put(quint: Quint): Promise; /** * 重写 multiPut 方法,使用同一事务保持批量写入幂等 */ multiPut(quintList: Quint[]): Promise; multiDel(quintList: Quint[]): Promise; getAttributes(subjects: string[], predicates: string[], graph?: Term): Promise; protected buildWhereClause(pattern: QuintPattern): { whereClause: string; params: any[]; }; private addPgCondition; protected addAliasedConditions(conditions: string[], params: any[], alias: string, pattern: any): void; protected buildCompoundQuery(compound: CompoundPattern, options?: QueryOptions): { sql: string; params: any[]; }; protected buildSelectQuery(pattern: QuintPattern, options?: QueryOptions): { sql: string; params: any[]; }; count(pattern: QuintPattern): Promise; stats(): Promise; private ensureTypedObjectSchema; private backfillMissingObjectIndexFields; private quintToPgRow; private objectIndexForTerm; private objectIndexForSerialized; private objectDigestForIndex; private writeStatementsForRow; private addObjectConditions; private addObjectExactCondition; private addObjectExactValueCondition; private addObjectExactSerializedCondition; private addObjectComparableCondition; private addObjectTextCondition; private addObjectLexicalStringCondition; private objectLexicalSql; private addObjectLanguageCondition; private objectPredicateForOperatorValue; private objectFieldsForTerm; private objectFieldsForSerialized; private objectFieldsForPrefix; private assertComparableObject; private addAliasedObjectConditions; protected extractExactPredicate(match: TermMatch | undefined): string | undefined; protected resolveObjectDataTypeForPattern(pattern: QuintPattern): PredicateObjectDataType | undefined; private addAliasedPgCondition; private addFallbackAliasedCondition; }