Class PgConnector

Description

PostgreSQL raw connector

Features:

  • connector manager for PostgreSQL

Example

import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { PgConnector, IPgConnector } from '@biorate/pg';

class Root extends Core() {
@inject(PgConnector) public connector: IPgConnector;
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<IPgConnector>(PgConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
Pg: [
{
name: 'connection',
options: {
user: 'postgres',
host: 'localhost',
database: 'postgres',
password: 'postgres',
port: 5432,
},
},
],
});

(async () => {
const root = container.get<Root>(Root);
await root.$run();
await root.connector!.current?.query(
`CREATE TABLE test (
count int,
text varchar(20)
);`,
);
await root.connector!.current?.query(
`INSERT INTO test (count, text) VALUES (1, 'test1'), (2, 'test2'), (3, 'test3');`,
);
console.log((await root.connector!.current?.query(`SELECT * FROM test;`))!.rows);
// [
// {
// "count": 1,
// "text": "test1",
// },
// {
// "count": 2,
// "text": "test2",
// },
// {
// "count": 3,
// "text": "test3",
// },
// ]
})();

Hierarchy

Constructors

Properties

#connections: Map<string, Client>

Description

Private connections storage

#connections: Map<string, Client> = ...

Description

Private connections storage

#current: Client

Description

Private link to selected (used) connection

#current: Client = undefined

Description

Private link to selected (used) connection

config: IConfig

Description

Config dependency

namespace: "Pg" = 'Pg'

Description

Namespace path for fetching configuration

Accessors

Methods

  • Parameters

    • name: string
    • query: string
    • Optional values: any[]
      Optional
    • Optional config: CursorQueryConfig
      Optional

    Returns Cursor<any>

    Description

    Create cursor

  • Parameters

    • name: string
    • query: string
    • Optional values: any[]
      Optional
    • Optional config: CursorQueryConfig
      Optional

    Returns QueryStream

    Description

    Create stream

Generated using TypeDoc