import { S as SchemaProvisioning, d as FulltextStrategy, V as VectorStrategy, B as BundledBackendCapabilityOverrides, A as AdapterBackend } from './types-BynPp5kU.js'; import { S as SerializedResourceDeclaration, a as SqlEngineProfile } from './profile-Ch5SSewK.js'; import { a as PostgresTables } from './postgres-DhZixg92.js'; import { A as AnyPgDatabase, a as AnyPgTransaction } from './postgres-execution-fKW0qRiN.js'; /** * PostgreSQL engine profile for TypeGraph. * * `createPostgresBackend` builds a `SqlEngineProfile` * (`buildPostgresEngineProfile`) and hands it to `createSqlBackend` * (`./engine`), which assembles the mirrored member groups — fulltext, * vector, contribution, identity, graph-template, base-schema, * index-materialization, kind-removal, schema-version — that this file * shares with `sqlite.ts` through `./engine/members/*.ts`. What stays here * is the PostgreSQL-owned island `createSqlBackend` cannot share: the * execution adapter and its driver-shape detection, the advisory-lock write * fence, the GUC-wrapped vector search path, transaction framing * (`EngineLateMembers.transactions` / `fence` / `rawSql` / `maintenance` / * `trustedImport` / `extensions`), the DDL and extension provisioning * `EngineProvisioning` wires through, the dialect's own operation-backend * construction (deferred, via `assembleEngine`'s `buildOperations`, until * the contribution materializer exists), and `hybridSearch` (an * embedding-adjacent member kept inline on both dialects rather than part * of the shared assembly). * * Works with any Drizzle PostgreSQL database instance. Tested against: * - `drizzle-orm/node-postgres` (pg Pool / Client) * - `drizzle-orm/postgres-js` (postgres-js tagged-template client) * - `drizzle-orm/neon-serverless` (@neondatabase/serverless Pool / Client) * - `drizzle-orm/neon-http` (@neondatabase/serverless `neon(url)`) — * transactions are auto-disabled because HTTP can't hold a session; * use `drizzle-orm/neon-serverless` if you need transactional writes. * * - `drizzle-orm/pglite` (PGlite, Postgres-in-WASM) — the execution * fast path detects PGlite and routes it correctly (its `.query` has no * named-statement form). For a batteries-included in-process setup, see * `createLocalPgliteBackend` in `@nicia-ai/typegraph/adapters/drizzle/postgres/pglite`. * * Other pg-protocol Drizzle adapters (Vercel Postgres, Supabase via pg) * work unchanged because they all expose a compatible `db.execute()` / * `db.transaction()` surface. * * @example * ```typescript * import { drizzle } from "drizzle-orm/node-postgres"; * import { Pool } from "pg"; * import { createPostgresBackend, tables } from "@nicia-ai/typegraph/adapters/drizzle/postgres"; * * const pool = new Pool({ connectionString: process.env.DATABASE_URL }); * const db = drizzle(pool); * const backend = createPostgresBackend(db, { tables }); * ``` */ /** * Options for creating a PostgreSQL backend. */ type PostgresBackendOptions = Readonly<{ /** Opt in to transactional DDL in a caller-owned schema transaction. */ schemaProvisioning?: SchemaProvisioning; /** * Custom table definitions. Use createPostgresTables() to customize table names. * Defaults to standard TypeGraph table names. */ tables?: PostgresTables; /** * Fulltext strategy override. Defaults to `tsvectorStrategy` * (Postgres built-in `tsvector` + GIN). Pass a custom strategy here to * swap the entire fulltext stack — DDL, MATCH condition, rank * expression, and snippet generation — for alternate Postgres * backends like ParadeDB (`pg_search`), pg_trgm similarity, or * pgroonga without forking TypeGraph. * * Pass `false` to disable fulltext support entirely. The backend then * advertises no `capabilities.fulltext` and omits the fulltext CRUD/ * search methods, mirroring `vector: false`. A fulltext predicate, a * `searchable()` field, `store.search.fulltext`, and hybrid search all * refuse with a typed error instead of running SQL against a table * this backend never creates. */ fulltext?: FulltextStrategy | false; /** * Vector strategy override. Defaults to `pgvectorStrategy` (pgvector's * `vector(N)` columns + HNSW/IVFFlat). The strategy owns per-`(kind, * field)` typed storage — DDL, upsert, delete, similarity search, and * ANN index lifecycle — and advertises `strategy.capabilities` as * `capabilities.vector`. Pass a custom strategy to swap the entire * vector stack for an alternate Postgres extension without forking * TypeGraph. * * Pass `false` to disable vector support entirely. The backend then * advertises no `capabilities.vector` and omits the embedding/search * methods, mirroring a SQLite connection without sqlite-vec. Required * for an in-process Postgres (e.g. PGlite) built without the pgvector * extension: the default `pgvectorStrategy` assumes `vector(N)` exists, * so any embedding write or `CREATE EXTENSION vector` would otherwise * hard-fail at runtime. */ vector?: VectorStrategy | false; /** * Override specific backend capabilities. Useful when the underlying * driver doesn't support a feature TypeGraph would otherwise assume — * for example, an HTTP-only Postgres driver that can't hold a session * across statements would need * `{ execution: { interactiveTransactions: false } }` so TypeGraph refuses * paths that require an interactive transaction. Root atomic-batch support * is transport-derived and cannot be overridden here. * * `drizzle-orm/neon-http` is auto-detected and has interactive transactions * disabled without an explicit override; this option exists for * other HTTP-style drivers and for tests that need to simulate a * capability gap. */ capabilities?: BundledBackendCapabilityOverrides; /** * Use server-side prepared statements (named statements cached per * pg connection) on the node-postgres / neon-serverless fast path. * Defaults to `true`. Set to `false` when pooling through pgbouncer * in transaction-pool mode — pgbouncer routes successive statements * over different backend connections, and a `name` registered on one * is invisible on the next. * * No effect on `drizzle-orm/postgres-js` (handles preparation * internally) or `drizzle-orm/neon-http` (no fast path). */ prepareStatements?: boolean; /** * Cap on the number of distinct SQL strings retained in TypeGraph's * in-process SQL-to-statement-name lookup. Defaults to 256. Eviction never * reuses a name, so this does not deallocate or bound prepared statements * retained on live PostgreSQL connections. Set `prepareStatements: false` * for high-cardinality SQL text when server-side statement retention is not * acceptable. Ignored when `prepareStatements` is `false`. */ preparedStatementCacheMax?: number; /** * Declare the connection this backend serializes every statement onto, when * TypeGraph's driver predicates cannot see it (Bun `SQL` at `{ max: 1 }`, * `pg-proxy`, a postgres-js client capped through a non-numeric string the * driver does not coerce) — or declare that it serializes on nothing, when * detection is wrong for your topology. * * Defaults to `{ mode: "detect" }`. See * {@link SerializedResourceDeclaration} for what each mode means and for the * one refusal it cannot lift (`same-sqlite-backend`, which is SQLite-only and * therefore never reached from here). */ serializedResource?: SerializedResourceDeclaration; }>; /** * Creates a TypeGraph backend for PostgreSQL databases. * * Works with any Drizzle PostgreSQL instance regardless of the underlying driver. * * @param db - A Drizzle PostgreSQL database instance * @param options - Backend configuration * @returns A GraphBackend implementation */ declare function createPostgresBackend(db: AnyPgDatabase, options?: PostgresBackendOptions): AdapterBackend; /** * Builds the PostgreSQL {@link SqlEngineProfile} `createSqlBackend` (from * `./engine`) assembles into a backend: the head data and dialect-owned * late members (`transactions`, `fence`, `rawSql`, `maintenance`, * `trustedImport`, `extensions`) only PostgreSQL supplies, plus the runtime * deps (`contributionRuntime`, `identityRuntime`, `graphTemplateRuntime`, * `baseSchemaRuntime`, `indexMaterializationRuntime`, `kindRemovalRuntime`) * `createSqlBackend` uses to assemble the mirrored member groups from * `members/*.ts`. */ declare function buildPostgresEngineProfile(db: AnyPgDatabase, options?: PostgresBackendOptions): SqlEngineProfile; export { type PostgresBackendOptions as P, buildPostgresEngineProfile as b, createPostgresBackend as c };