From 265f4a96911ecdf6e8222fd5d47bae658aeeac6c Mon Sep 17 00:00:00 2001 From: Jonathan V Date: Fri, 24 Jan 2025 16:11:56 +0100 Subject: [PATCH] Make postgresConnectionOptions optional in PostgresRecordManager Make postgresConnectionOptions optional in PostgresRecordManager to be more in line with PGVectorStore --- libs/langchain-community/src/indexes/postgres.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/langchain-community/src/indexes/postgres.ts b/libs/langchain-community/src/indexes/postgres.ts index 5229882782e5..d7cfe63a32f1 100644 --- a/libs/langchain-community/src/indexes/postgres.ts +++ b/libs/langchain-community/src/indexes/postgres.ts @@ -6,7 +6,7 @@ import { } from "./base.js"; export type PostgresRecordManagerOptions = { - postgresConnectionOptions: PoolConfig; + postgresConnectionOptions?: PoolConfig; pool?: Pool; tableName?: string; schema?: string; @@ -26,7 +26,10 @@ export class PostgresRecordManager implements RecordManagerInterface { constructor(namespace: string, config: PostgresRecordManagerOptions) { const { postgresConnectionOptions, tableName, pool } = config; this.namespace = namespace; - this.pool = pool || new pg.Pool(postgresConnectionOptions); + if (!postgresConnectionOptions && !pool) { + throw new Error("You must provide either a `postgresConnectionOptions` object or a `pool` instance."); + } + this.pool = pool ?? new pg.Pool(postgresConnectionOptions); this.tableName = tableName || "upsertion_records"; this.finalTableName = config.schema ? `"${config.schema}"."${this.tableName}"`