Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • default

Index

Constructors

Properties

Methods

Constructors

constructor

  • new default(config: string | ClientConfig): default
  • Initalize a database connection.

    It can be initialized with a database url like

    pg://user:password@host:port/database
    

    or a crednetial object:

    {
      "user": "postgres",
      "database": "tester",
      "password": "",
      "host": "localhost",
      "port": 5432
    }
    

    Parameters

    • config: string | ClientConfig

      PostgreSQL database connection string or config object

    Returns default

Properties

Private _db

_db: Pool

Methods

Private _streamQuery

  • _streamQuery<V, T>(queryFn: any, sql: string, values?: V[], cleanup?: any): Observable<T>
  • Type parameters

    • V

    • T

    Parameters

    • queryFn: any
    • sql: string
    • Optional values: V[]
    • Optional cleanup: any

    Returns Observable<T>

end

  • end(): void
  • Close the current database connection.

    Returns void

query

  • query<V, T>(sql: string, values?: V | V[]): Observable<T>
  • Run a query with optional values.

    This function supports the query formatting of pg and you can construct the query like

    pgrx.query('SELECT id FROM user WHERE name = $1::text', ['Tom']);
    

    It will return an observable that emits every row of the query result.

    Type parameters

    • V = any

    • T = any

    Parameters

    • sql: string

      Query SQL

    • Optional values: V | V[]

      Optional query parameters

    Returns Observable<T>

    Observable

tx

  • tx(fn: (txClient: ITxClient) => Observable<any>): Observable<any>
  • Run queries within a transaction.

    The callback function receives an object that has a query() function to run queries within the transaction and return an observable. To pass the data to the following operator, return an observable in the callback function.

    pgrx.tx((t) => {
     const insert1 = t.query('INSERT INTO user (name) VALUES ($1::text) RETURNING id;', ['Tom']);
     const insert2 = t.query('INSERT INTO user (name) VALUES ($1::text) RETURNING id;', ['Joe']);
    
     return insert1.concat(insert2);
    })
    .subscribe((row) => console.log(row));
    

    No data will be emitted if any query in a transaction fails.

    Parameters

    • fn: (txClient: ITxClient) => Observable<any>

      A callback function that returns an observable for database operation.

        • Parameters

          Returns Observable<any>

    Returns Observable<any>

    Observable

Legend

  • Constructor
  • Method
  • Property
  • Private property

Generated using TypeDoc