Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch]: allow to use postgres pool instance on PostgresRecordManager #5677

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libs/langchain-community/src/indexes/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

export type PostgresRecordManagerOptions = {
postgresConnectionOptions: PoolConfig;
pool?: Pool;
tableName?: string;
schema?: string;
};
Expand All @@ -23,9 +24,9 @@ export class PostgresRecordManager implements RecordManagerInterface {
finalTableName: string;

constructor(namespace: string, config: PostgresRecordManagerOptions) {
const { postgresConnectionOptions, tableName } = config;
const { postgresConnectionOptions, tableName, pool } = config;
this.namespace = namespace;
this.pool = new pg.Pool(postgresConnectionOptions);
this.pool = pool || new pg.Pool(postgresConnectionOptions);
this.tableName = tableName || "upsertion_records";
this.finalTableName = config.schema
? `"${config.schema}"."${tableName}"`
Expand Down
12 changes: 11 additions & 1 deletion libs/langchain-community/src/indexes/tests/postgres.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test, jest } from "@jest/globals";
import { PoolConfig } from "pg";
import pg, { PoolConfig } from "pg";
import {
PostgresRecordManager,
PostgresRecordManagerOptions,
Expand Down Expand Up @@ -36,6 +36,16 @@ describe.skip("PostgresRecordManager", () => {
await recordManager.end();
});

test("Test provided postgres pool instance", async () => {
const pool = new pg.Pool(config.postgresConnectionOptions);
const providedPoolRecordManager = new PostgresRecordManager("test", {
...config,
pool,
});

expect(providedPoolRecordManager.pool).toBe(pool);
});

test("Test explicit schema definition", async () => {
// configure explicit schema with record manager
config.schema = "newSchema";
Expand Down
Loading