Skip to content

Commit

Permalink
chore: allow to use postgres pool instance on PostgresRecordManager (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
josemussa authored Jun 11, 2024
1 parent c338b38 commit e177b2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit e177b2f

Please sign in to comment.