glutinum-org / binding-requests

0 stars 0 forks source link

Request for pg #5

Open joprice opened 3 weeks ago

joprice commented 3 weeks ago

Description of the package

Non-blocking PostgreSQL client for Node.js. Pure JavaScript and optional native libpq bindings.

Resources

joprice commented 3 weeks ago

On second thought, I may switch to porsager/postgres as it has better performance https://github.com/porsager/postgres-benchmarks?tab=readme-ov-file#results and support for deno and bun. No immediate need for this one until, but it would be nice either way to have bindings for some simple postgres api for various use cases.

MangelMaxime commented 2 weeks ago

Hello @joprice,

in an old project of mine I used node-posgres. I don't know about porsager/postgres but in the past I enjoyed working with node-postgres and F#.

The bindings can be outdated perhaps and don't use the latest goodies coming with Glutinum but if needed here they are:

Pg.fs

module rec Pg

open System
open Fable.Core
open Fable.Core.JS
open Node

type Array<'T> = System.Collections.Generic.IList<'T>
type Error = System.Exception

module Pg =
    type ConnectionOptions = obj //Tls.ConnectionOptions
    let [<Import("types","pg")>] types: obj = jsNative
    let [<Import("*","pg")>] defaults: IExports = jsNative
    let [<Import("native","pg")>] native: obj option = jsNative

    type [<AllowNullLiteral>] IExports =
        abstract Connection: ConnectionStatic
        abstract Pool: PoolStatic
        abstract ClientBase: ClientBaseStatic
        abstract Client: ClientStatic
        abstract Query: QueryStatic
        abstract Events: EventsStatic

    type [<AllowNullLiteral>] ClientConfig =
        abstract user: string with get, set
        abstract database: string with get, set
        abstract password: U2<string, (unit -> U2<string, Promise<string>>)> with get, set
        abstract port: int with get, set
        abstract host: string with get, set
        abstract connectionString: string with get, set
        abstract keepAlive: bool with get, set
//        abstract stream: Stream.Duplex option with get, set
        abstract statement_timeout: int with get, set
        abstract parseInputDatesAsUTC: bool with get, set
        abstract ssl: U2<bool, ConnectionOptions> with get, set
        abstract query_timeout: int with get, set
        abstract keepAliveInitialDelayMillis: int with get, set
        abstract idle_in_transaction_session_timeout: int with get, set
        abstract application_name: string with get, set
        abstract connectionTimeoutMillis: int with get, set

    type ConnectionConfig =
        ClientConfig

    type [<AllowNullLiteral>] Defaults =
        inherit ClientConfig
        abstract poolSize: float option with get, set
        abstract poolIdleTimeout: float option with get, set
        abstract reapIntervalMillis: float option with get, set
        abstract binary: bool option with get, set
        abstract parseInt8: bool option with get, set

    type [<AllowNullLiteral>] PoolConfig =
        inherit ClientConfig
        abstract max: int with get, set
        abstract min: int with get, set
        abstract idleTimeoutMillis: int with get, set
        abstract log: (ResizeArray<obj option> -> unit) option with get, set
        abstract Promise: (*PromiseConstructorLike*) PromiseConstructor option with get, set

    type QueryConfig =
        QueryConfig<obj>

    type [<AllowNullLiteral>] QueryConfig<'I> =
        abstract name: string option with get, set
        abstract text: string with get, set
        abstract values: 'I option with get, set

    type [<AllowNullLiteral>] Submittable =
        abstract submit: (Connection -> unit) with get, set

    type QueryArrayConfig =
        QueryArrayConfig<obj>

    type [<AllowNullLiteral>] QueryArrayConfig<'I> =
        inherit QueryConfig<'I>
        abstract rowMode: string with get, set

    type [<AllowNullLiteral>] FieldDef =
        abstract name: string with get, set
        abstract tableID: float with get, set
        abstract columnID: float with get, set
        abstract dataTypeID: int with get, set
        abstract dataTypeSize: float with get, set
        abstract dataTypeModifier: float with get, set
        abstract format: string with get, set

    type [<AllowNullLiteral>] QueryResultBase =
        abstract command: string with get, set
        abstract rowCount: int with get, set
        abstract oid: float with get, set
        abstract fields: ResizeArray<FieldDef> with get, set

    type [<AllowNullLiteral>] QueryResultRow =
        [<Emit "$0[$1]{{=$2}}">] abstract Item: column: string -> obj option with get, set

    type QueryResult =
        QueryResult<obj>

    type [<AllowNullLiteral>] QueryResult<'R> =
        inherit QueryResultBase
        abstract rows: ResizeArray<'R> with get, set

    type QueryArrayResult =
        QueryArrayResult<obj>

    type [<AllowNullLiteral>] QueryArrayResult<'R> =
        inherit QueryResultBase
        abstract rows: ResizeArray<'R> with get, set

    type [<AllowNullLiteral>] Notification =
        abstract processId: float with get, set
        abstract channel: string with get, set
        abstract payload: string option with get, set

    type ResultBuilder =
        ResultBuilder<obj>

    type [<AllowNullLiteral>] ResultBuilder<'R> =
        inherit QueryResult<'R>
        abstract addRow: row: 'R -> unit

    type [<AllowNullLiteral>] QueryParse =
        abstract name: string with get, set
        abstract text: string with get, set
        abstract types: ResizeArray<string> with get, set

    type [<AllowNullLiteral>] BindConfig =
        abstract portal: string option with get, set
        abstract statement: string option with get, set
        abstract binary: string option with get, set
        abstract values: Array<U2<Buffer, string> option> option with get, set

    type [<AllowNullLiteral>] ExecuteConfig =
        abstract portal: string option with get, set
        abstract rows: string option with get, set

    type [<AllowNullLiteral>] MessageConfig =
        abstract ``type``: string with get, set
        abstract name: string option with get, set

    type [<AllowNullLiteral>] Connection =
        inherit Events.EventEmitter
//        abstract stream: Stream.Duplex
        abstract bind: config: BindConfig option * more: bool -> unit
        abstract execute: config: ExecuteConfig option * more: bool -> unit
        abstract parse: query: QueryParse * more: bool -> unit
        abstract query: text: string -> unit
        abstract describe: msg: MessageConfig * more: bool -> unit
        abstract close: msg: MessageConfig * more: bool -> unit
        abstract flush: unit -> unit
        abstract sync: unit -> unit
        abstract ``end``: unit -> unit

    type [<AllowNullLiteral>] ConnectionStatic =
        [<Emit "new $0($1...)">] abstract Create: ?config: ConnectionConfig -> Connection

    /// {@link https://node-postgres.com/api/pool}
    type [<AllowNullLiteral>] Pool =
        inherit Events.EventEmitter
        abstract totalCount: float
        abstract idleCount: float
        abstract waitingCount: float
        abstract connect: unit -> Promise<PoolClient>
        abstract connect: callback: (Error -> PoolClient -> (obj -> unit) -> unit) -> unit
        abstract ``end``: unit -> Promise<unit>
        abstract ``end``: callback: (unit -> unit) -> unit
        abstract query: queryStream: 'T -> 'T
        abstract query: queryConfig: QueryArrayConfig<'I> * ?values: 'I -> Promise<QueryArrayResult<'R>>
        abstract query: queryConfig: QueryConfig<'I> -> Promise<QueryResult<'R>>
        // abstract query: queryTextOrConfig: U2<string, QueryConfig<'I>> * ?values: 'I -> Promise<QueryResult<'R>>
        abstract query: queryText: string * ?values: 'I -> Promise<QueryResult<'R>>
        abstract query: queryConfig: QueryConfig<'I> * ?values: 'I -> Promise<QueryResult<'R>>
        abstract query: queryConfig: QueryArrayConfig<'I> * callback: (Error -> QueryArrayResult<'R> -> unit) -> unit
        abstract query: queryTextOrConfig: U2<string, QueryConfig<'I>> * callback: (Error -> QueryResult<'R> -> unit) -> unit
        abstract query: queryText: string * values: 'I * callback: (Error -> QueryResult<'R> -> unit) -> unit
        [<Emit "$0.on('error',$1)">] abstract on_error: listener: (Error -> PoolClient -> unit) -> Pool
        abstract on: ``event``: PoolOnEvent * listener: (PoolClient -> unit) -> Pool

    type [<StringEnum>] [<RequireQualifiedAccess>] PoolOnEvent =
        | Connect
        | Acquire
        | Remove

    /// {@link https://node-postgres.com/api/pool}
    type [<AllowNullLiteral>] PoolStatic =
        /// Every field of the config object is entirely optional.
        /// The config passed to the pool is also passed to every client
        /// instance within the pool when the pool creates that client.
        [<Emit "new $0($1...)">] abstract Create: ?config: PoolConfig -> Pool

    type [<AllowNullLiteral>] ClientBase =
        inherit Events.EventEmitter
        abstract connect: unit -> Promise<unit>
        abstract connect: callback: (Error -> unit) -> unit
        abstract query: queryStream: 'T -> Promise<'T>
        abstract query: queryConfig: QueryArrayConfig<'I> * ?values: 'I -> Promise<QueryArrayResult<'R>>
        abstract query: queryConfig: QueryConfig<'I> -> Promise<QueryResult<'R>>
        abstract query<'I, 'R> : queryTextOrConfig: string * ?values: 'I -> Promise<QueryResult<'R>>
        abstract query<'I, 'R> : queryTextOrConfig: QueryConfig<'I> * ?values: 'I -> Promise<QueryResult<'R>>
        abstract query: queryConfig: QueryArrayConfig<'I> * callback: (Error -> QueryArrayResult<'R> -> unit) -> unit
        abstract query: queryTextOrConfig: U2<string, QueryConfig<'I>> * callback: (Error -> QueryResult<'R> -> unit) -> unit
        abstract query: queryText: string * values: ResizeArray<obj option> * callback: (Error -> QueryResult<'R> -> unit) -> unit
        abstract copyFrom: queryText: string -> Stream.Writable<'T>
        abstract copyTo: queryText: string -> Stream.Readable<'T>
        abstract pauseDrain: unit -> unit
        abstract resumeDrain: unit -> unit
        abstract escapeIdentifier: str: string -> string
        abstract escapeLiteral: str: string -> string
        [<Emit "$0.on('drain',$1)">] abstract on_drain: listener: (unit -> unit) -> ClientBase
        abstract on: ``event``: ClientBaseOnEvent * listener: (Error -> unit) -> ClientBase
        [<Emit "$0.on('notification',$1)">] abstract on_notification: listener: (Notification -> unit) -> ClientBase
        [<Emit "$0.on('end',$1)">] abstract on_end: listener: (unit -> unit) -> ClientBase

    type [<StringEnum>] [<RequireQualifiedAccess>] ClientBaseOnEvent =
        | Error
        | Notice

    type [<AllowNullLiteral>] ClientBaseStatic =
        [<Emit "new $0($1...)">] abstract Create: ?config: U2<string, ClientConfig> -> ClientBase

    type [<AllowNullLiteral>] Client =
        inherit ClientBase
        abstract user: string option with get, set
        abstract database: string option with get, set
        abstract port: float with get, set
        abstract host: string with get, set
        abstract password: string option with get, set
        abstract ssl: bool with get, set
        abstract ``end``: unit -> Promise<unit>
        abstract ``end``: callback: (Error -> unit) -> unit

    type [<AllowNullLiteral>] ClientStatic =
        [<Emit "new $0($1...)">] abstract Create: unit -> Client
        [<Emit "new $0($1...)">] abstract Create: config: string -> Client
        [<Emit "new $0($1...)">] abstract Create: config: ClientConfig -> Client

    type [<AllowNullLiteral>] PoolClient =
        inherit ClientBase
        abstract release: ?err: U2<Error, bool> -> unit

    type Query<'I> =
        Query<obj, 'I>

    type Query =
        Query<obj, obj>

    type [<AllowNullLiteral>] Query<'R, 'I> =
        inherit Events.EventEmitter
        inherit Submittable
        abstract submit: (Connection -> unit) with get, set
        [<Emit "$0.on('row',$1)">] abstract on_row: listener: ('R -> ResultBuilder<'R> -> unit) -> Query<'R, 'I>
        [<Emit "$0.on('error',$1)">] abstract on_error: listener: (Error -> unit) -> Query<'R, 'I>
        [<Emit "$0.on('end',$1)">] abstract on_end: listener: (ResultBuilder<'R> -> unit) -> Query<'R, 'I>

    type [<AllowNullLiteral>] QueryStatic =
        [<Emit "new $0($1...)">] abstract Create: ?queryTextOrConfig: U2<string, QueryConfig<'I>> * ?values: 'I -> Query<'R, 'I>

    type [<AllowNullLiteral>] Events =
        inherit Events.EventEmitter
        [<Emit "$0.on('error',$1)">] abstract on_error: listener: (Error -> Client -> unit) -> Events

    type [<AllowNullLiteral>] EventsStatic =
        [<Emit "new $0($1...)">] abstract Create: unit -> Events

PgMinify

// ts2fable 0.8.0
module rec PgMinify

open System
open Fable.Core
open Fable.Core.JS

type Error = System.Exception

let [<Import("*","pg-minify")>] pgMinify: PgMinify.IExports = jsNative

type [<AllowNullLiteral>] IExports =
    abstract pgMinify: sql: string * ?options: PgMinify.IMinifyOptions -> string

module PgMinify =

    type [<AllowNullLiteral>] IExports =
        abstract SQLParsingError: SQLParsingErrorStatic

    type [<AllowNullLiteral>] IMinifyOptions =
        abstract compress: bool option with get, set
        abstract removeAll: bool option with get, set

    type [<AllowNullLiteral>] IErrorPosition =
        abstract line: float with get, set
        abstract column: float with get, set

    type [<RequireQualifiedAccess>] parsingErrorCode =
        | UnclosedMLC = 0
        | UnclosedText = 1
        | UnclosedQI = 2
        | MultiLineQI = 3

    type [<AllowNullLiteral;AbstractClass>] SQLParsingError =
        inherit Error
        abstract name: string with get, set
        abstract message: string with get, set
        abstract stack: string with get, set
        abstract error: string with get, set
        abstract code: parsingErrorCode with get, set
        abstract position: IErrorPosition with get, set

    type [<AllowNullLiteral>] SQLParsingErrorStatic =
        [<EmitConstructor>] abstract Create: unit -> SQLParsingError

PgMonitor

// ts2fable 0.8.0
module rec PgMonitor

open System
open Fable.Core
open Fable.Core.JS

type Array<'T> = System.Collections.Generic.IList<'T>

let [<Import("detailed","pg-monitor")>] detailed: bool = jsNative

let [<Import("default", "pg-monitor")>] e : IExports = jsNative

type [<AllowNullLiteral>] IExports =
    abstract attach: options: obj * ?events: Array<LogEvent> * ?``override``: bool -> unit
    abstract detach: unit -> unit
    abstract isAttached: unit -> bool
    abstract setTheme: theme: U2<ThemeName, IColorTheme> -> unit
    abstract setLog: log: (string -> IEventInfo -> unit) -> unit
    abstract setDetailed: value: bool -> unit
    abstract connect: client: obj * dc: obj option * useCount: float * ?detailed: bool -> unit
    abstract disconnect: client: obj * dc: obj option * ?detailed: bool -> unit
    abstract query: e: obj * ?detailed: bool -> unit
    abstract task: e: obj -> unit
    abstract transact: e: obj -> unit
    abstract error: err: obj option * e: obj * ?detailed: bool -> unit

type [<AllowNullLiteral>] ITaskContext =
    abstract context: obj option
    abstract parent: ITaskContext option
    abstract connected: bool
    abstract inTransaction: bool
    abstract level: float
    abstract useCount: float
    abstract isTX: bool
    abstract start: DateTime
    abstract tag: obj option
    abstract dc: obj option
    abstract finish: DateTime option
    abstract duration: float option
    abstract success: bool option
    abstract result: obj option
    abstract txLevel: float option

type [<AllowNullLiteral>] ColorFunction =
    [<Emit "$0($1...)">] abstract Invoke: [<ParamArray>] values: obj option[] -> string

type [<AllowNullLiteral>] IColorTheme =
    abstract time: ColorFunction with get, set
    abstract value: ColorFunction with get, set
    abstract cn: ColorFunction with get, set
    abstract tx: ColorFunction with get, set
    abstract paramTitle: ColorFunction with get, set
    abstract errorTitle: ColorFunction with get, set
    abstract query: ColorFunction with get, set
    abstract special: ColorFunction with get, set
    abstract error: ColorFunction with get, set

type [<StringEnum>] [<RequireQualifiedAccess>] LogEvent =
    | Connect
    | Disconnect
    | Query
    | Task
    | Transact
    | Error

type [<StringEnum>] [<RequireQualifiedAccess>] ThemeName =
    | Dimmed
    | Bright
    | Monochrome
    | Minimalist
    | Matrix
    | InvertedMonochrome
    | InvertedContrast

type [<AllowNullLiteral>] IEventInfo =
    abstract time: DateTime option with get, set
    abstract colorText: string with get, set
    abstract text: string with get, set
    abstract ``event``: LogEvent with get, set
    abstract display: bool with get, set
    abstract ctx: ITaskContext option with get, set

PgPromise

// ts2fable 0.8.0
module rec PgPromise

open System
open Fable.Core
open Fable.Core.JS
open Node

module Pg = PgSubset.Pg
module SpexLib = Spex.Spex
module PgMinify = PgMinify.PgMinify

type Array<'T> = System.Collections.Generic.IList<'T>
type Error = System.Exception
type Symbol = obj

let [<Import("default","pg-promise")>] pgPromise: PgPromise.IExports = jsNative

type [<AllowNullLiteral>] IExports =
    [<Emit("$0($1)")>]
    abstract Invoke: ?options: PgPromise.IInitOptions<'Ext, 'C> -> PgPromise.IMain<'Ext, 'C> when 'C :> Pg.IClient

let [<Import("default", "pg-promise")>] e : IExports = jsNative

type XPromise<'T> =
    Promise<'T>

module PgPromise =
    let [<Import("errors","module/pgPromise")>] errors: Errors.IExports = jsNative

    type [<AllowNullLiteral>] IExports =
        abstract TableName: TableNameStatic
        abstract Column: ColumnStatic
        abstract ColumnSet: ColumnSetStatic
        abstract minify: obj
        abstract PreparedStatement: PreparedStatementStatic
        abstract ParameterizedQuery: ParameterizedQueryStatic
        // abstract QueryFile: QueryFileStatic
        [<Emit("new $0.QueryFile($1...)")>]
        abstract QueryFile: file: string * ?options: IQueryFileOptions -> QueryFile
        abstract txMode: ITXMode
        abstract utils: IUtils
        abstract ``as``: IFormatting
        abstract TransactionMode: TransactionModeStatic

    type [<AllowNullLiteral>] IQueryFileOptions =
        abstract debug: bool with get, set
        abstract minify: U2<bool, string> with get, set
        abstract compress: bool with get, set
        abstract ``params``: obj with get, set
        abstract noWarnings: bool with get, set

    type [<AllowNullLiteral>] IFormattingOptions =
        abstract capSQL: bool option with get, set
        abstract partial: bool option with get, set
        abstract def: obj option with get, set

    type ILostContext =
        ILostContext<Pg.IClient>

    type [<AllowNullLiteral>] ILostContext<'C when 'C :> Pg.IClient> =
        abstract cn: string with get, set
        abstract dc: obj option with get, set
        abstract start: DateTime with get, set
        abstract client: 'C with get, set

    type IConnectionOptions =
        IConnectionOptions<Pg.IClient>

    type [<AllowNullLiteral>] IConnectionOptions<'C when 'C :> Pg.IClient> =
        abstract direct: bool option with get, set
        abstract onLost: err: obj option * e: ILostContext<'C> -> unit

    type [<AllowNullLiteral>] IPreparedStatement =
        abstract name: string option with get, set
        abstract text: U2<string, QueryFile> option with get, set
        abstract values: ResizeArray<obj option> option with get, set
        abstract binary: bool option with get, set
        abstract rowMode: U2<unit, string> option with get, set
        abstract rows: float option with get, set

    type [<AllowNullLiteral>] IParameterizedQuery =
        abstract text: U2<string, QueryFile> option with get, set
        abstract values: ResizeArray<obj option> option with get, set
        abstract binary: bool option with get, set
        abstract rowMode: U2<unit, string> option with get, set

    type [<AllowNullLiteral>] IPreparedParsed =
        abstract name: string with get, set
        abstract text: string with get, set
        abstract values: ResizeArray<obj option> with get, set
        abstract binary: bool with get, set
        abstract rowMode: U2<unit, string> with get, set
        abstract rows: float with get, set

    type [<AllowNullLiteral>] IParameterizedParsed =
        abstract text: string with get, set
        abstract values: ResizeArray<obj option> with get, set
        abstract binary: bool with get, set
        abstract rowMode: U2<unit, string> with get, set

    type [<AllowNullLiteral>] IColumnDescriptor<'T> =
        abstract source: 'T with get, set
        abstract name: string with get, set
        abstract value: obj option with get, set
        abstract exists: bool with get, set

    type [<AllowNullLiteral>] IColumnConfig<'T> =
        abstract name: string with get, set
        abstract prop: string option with get, set
        abstract ``mod``: FormattingFilter option with get, set
        abstract cast: string option with get, set
        abstract cnd: bool option with get, set
        abstract def: obj option with get, set
        abstract init: col: IColumnDescriptor<'T> -> obj option
        abstract skip: col: IColumnDescriptor<'T> -> bool

    type [<AllowNullLiteral>] IColumnSetOptions =
        abstract table: U3<string, ITable, TableName> option with get, set
        abstract ``inherit``: bool option with get, set

    type [<AllowNullLiteral>] ITable =
        abstract table: string with get, set
        abstract schema: string option with get, set

    type [<AllowNullLiteral>] IPromiseConfig =
        abstract create: resolve: (obj -> unit) * ?reject: (obj -> unit) -> XPromise<obj option>
        abstract resolve: ?value: obj -> unit
        abstract reject: ?reason: obj -> unit
        abstract all: iterable: obj option -> XPromise<obj option>

    type [<StringEnum>] [<RequireQualifiedAccess>] FormattingFilter =
        | [<CompiledName "^">] Filter_pow
        | [<CompiledName "~">] Filter_tild
        | [<CompiledName "#">] Filter_hash
        | [<CompiledName ":raw">] Filter_raw
        | [<CompiledName ":alias">] Filter_alias
        | [<CompiledName ":name">] Filter_name
        | [<CompiledName ":json">] Filter_json
        | [<CompiledName ":csv">] Filter_csv
        | [<CompiledName ":list">] Filter_list
        | [<CompiledName ":value">] Filter_value

    type QueryColumns<'T> =
        U3<Column<'T>, ColumnSet<'T>, Array<U3<string, IColumnConfig<'T>, Column<'T>>>>

    type QueryParam =
        U6<string, QueryFile, IPreparedStatement, IParameterizedQuery, PreparedStatement, ParameterizedQuery> //, (obj -> QueryParam)>

    type ValidSchema =
        U3<string, ResizeArray<string>, unit> option

    type [<AllowNullLiteral>] TableName =
        abstract name: string
        abstract table: string
        abstract schema: string
        abstract toString: unit -> string

    type [<AllowNullLiteral>] TableNameStatic =
        [<EmitConstructor>] abstract Create: table: U2<string, ITable> -> TableName

    type Column =
        Column<obj>

    type [<AllowNullLiteral>] Column<'T> =
        abstract name: string
        abstract prop: string
        abstract ``mod``: FormattingFilter
        abstract cast: string
        abstract cnd: bool
        abstract def: obj option
        abstract castText: string
        abstract escapedName: string
        abstract init: (IColumnDescriptor<'T> -> obj option)
        abstract skip: (IColumnDescriptor<'T> -> bool)
        abstract toString: ?level: float -> string

    type [<AllowNullLiteral>] ColumnStatic =
        [<EmitConstructor>] abstract Create: col: U2<string, IColumnConfig<'T>> -> Column<'T>

    type ColumnSet =
        ColumnSet<obj>

    type [<AllowNullLiteral>] ColumnSet<'T> =
        abstract columns: ResizeArray<Column<'T>>
        abstract names: string
        abstract table: TableName
        abstract variables: string
        abstract assign: ?source: ColumnSetAssignSource -> string
        abstract assignColumns: ?options: ColumnSetAssignColumnsOptions -> string
        abstract extend: columns: U3<Column<'T>, ColumnSet<'T>, Array<U3<string, IColumnConfig<'T>, Column<'T>>>> -> ColumnSet<'S>
        abstract merge: columns: U3<Column<'T>, ColumnSet<'T>, Array<U3<string, IColumnConfig<'T>, Column<'T>>>> -> ColumnSet<'S>
        abstract prepare: obj: obj -> obj
        abstract toString: ?level: float -> string
        [<EmitConstructor>] abstract Create: columns: Column<'T> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: ResizeArray<U3<string, IColumnConfig<'T>, Column<'T>>> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: ResizeArray<string> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: ResizeArray<IColumnConfig<'T>> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: ResizeArray<Column<'T>> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: obj * ?options: IColumnSetOptions -> ColumnSet<'T>

    type [<AllowNullLiteral>] ColumnSetAssignSource =
        abstract source: obj option with get, set
        abstract prefix: string option with get, set

    type [<AllowNullLiteral>] ColumnSetAssignColumnsOptions =
        abstract from: string option with get, set
        abstract ``to``: string option with get, set
        abstract skip: U3<string, ResizeArray<string>, (Column<'T> -> bool)> option with get, set

    type [<AllowNullLiteral>] ColumnSetStatic =
        [<EmitConstructor>] abstract Create: columns: Column<'T> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: Array<U3<string, IColumnConfig<'T>, Column<'T>>> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: Array<string> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: Array<IColumnConfig<'T>> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: Array<Column<'T>> * ?options: IColumnSetOptions -> ColumnSet<'T>
        [<EmitConstructor>] abstract Create: columns: obj * ?options: IColumnSetOptions -> ColumnSet<'T>

    type [<RequireQualifiedAccess>] queryResult =
        | One = 1
        | Many = 2
        | None = 4
        | Any = 6

    type [<AllowNullLiteral>] PreparedStatement =
        abstract name: string with get, set
        abstract text: U2<string, QueryFile> with get, set
        abstract values: ResizeArray<obj option> with get, set
        abstract binary: bool with get, set
        abstract rowMode: U2<unit, string> with get, set
        abstract rows: float with get, set
        abstract parse: unit -> U2<IPreparedParsed, Errors.PreparedStatementError>
        abstract toString: ?level: float -> string

    type [<AllowNullLiteral>] PreparedStatementStatic =
        [<EmitConstructor>] abstract Create: ?options: IPreparedStatement -> PreparedStatement

    type [<AllowNullLiteral>] ParameterizedQuery =
        abstract text: U2<string, QueryFile> with get, set
        abstract values: ResizeArray<obj option> with get, set
        abstract binary: bool with get, set
        abstract rowMode: U2<unit, string> with get, set
        abstract parse: unit -> U2<IParameterizedParsed, Errors.ParameterizedQueryError>
        abstract toString: ?level: float -> string

    type [<AllowNullLiteral>] ParameterizedQueryStatic =
        [<EmitConstructor>] abstract Create: ?options: U3<string, QueryFile, IParameterizedQuery> -> ParameterizedQuery

    type [<AllowNullLiteral>] QueryFile =
        abstract error: Error option
        abstract file: string
        abstract options: obj option
        abstract prepare: unit -> unit
        abstract toString: ?level: float -> string

    type [<AllowNullLiteral>] QueryFileStatic =
        [<EmitConstructor>] abstract Create: file: string * ?options: IQueryFileOptions -> QueryFile

    type [<AllowNullLiteral>] PromiseAdapter =
        interface end

    type [<AllowNullLiteral>] PromiseAdapterStatic =
        [<EmitConstructor>] abstract Create: api: IPromiseConfig -> PromiseAdapter

    type IDatabase<'Ext> =
        IDatabase<'Ext, Pg.IClient>

    type [<AllowNullLiteral>] IDatabase<'Ext, 'C when 'C :> Pg.IClient> =
        inherit IBaseProtocol<'Ext>
        abstract connect: ?options: IConnectionOptions<'C> -> XPromise<IConnected<'Ext, 'C>>
        abstract ``$config``: ILibConfig<'Ext, 'C>
        abstract ``$cn``: U2<string, Pg.IConnectionParameters<'C>>
        abstract ``$dc``: obj option
        abstract ``$pool``: Pg.IPool

    type [<AllowNullLiteral>] IResultExt =
        inherit Pg.IResult
        abstract duration: float option with get, set

    type IMain =
        IMain<obj, Pg.IClient>

    type IMain<'Ext> =
        IMain<'Ext, Pg.IClient>

    type [<AllowNullLiteral>] IMain<'Ext, 'C when 'C :> Pg.IClient> =
        [<Emit "$0($1...)">] abstract Invoke: cn: Pg.IConnectionParameters<'C> * ?dc: obj -> IDatabase<'Ext, 'C>
        [<Emit "$0($1...)">] abstract Invoke: cn: string * ?dc: obj -> IDatabase<'Ext, 'C>
        abstract PromiseAdapter: obj
        abstract PreparedStatement: obj
        abstract ParameterizedQuery: obj
        abstract QueryFile: obj
        abstract queryResult: obj
        abstract minify: obj
        abstract spex: SpexLib.ISpex
        abstract errors: obj
        abstract utils: IUtils
        abstract txMode: ITXMode
        abstract helpers: IHelpers
        abstract ``as``: IFormatting
        abstract pg: obj
        abstract ``end``: unit -> unit

    type [<AllowNullLiteral>] ITask<'Ext> =
        inherit IBaseProtocol<'Ext>
        inherit SpexLib.ISpexBase
        abstract ctx: ITaskContext

    type [<AllowNullLiteral>] IBaseProtocol<'Ext> =
        abstract query: query: QueryParam * ?values: obj * ?qrm: queryResult -> XPromise<'T>
        abstract query: query: QueryFile * ?values: obj * ?qrm: queryResult -> XPromise<'T>
        abstract query: query: string * ?values: obj * ?qrm: queryResult -> XPromise<'T>
        // abstract none: query: QueryParam * ?values: obj -> XPromise<obj>
        abstract none: query: QueryParam * ?values: obj -> XPromise<unit> // Make none return unit as it as more sense in F# than null
        abstract none: query: QueryFile * ?values: obj -> XPromise<unit> // Make none return unit as it as more sense in F# than null
        abstract none: query: string * ?values: obj -> XPromise<unit> // Make none return unit as it as more sense in F# than null
        abstract one: query: QueryParam * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T>
        abstract one: query: string * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T>
        abstract one: query: QueryFile * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T>
        abstract oneOrNone: query: QueryParam * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T option>
        abstract oneOrNone: query: string * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T option>
        abstract oneOrNone: query: QueryFile * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T option>
        abstract oneOrNone: query: PreparedStatement * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T option>
        abstract many: query: QueryParam * ?values: obj -> XPromise<ResizeArray<'T>>
        abstract many: query: string * ?values: obj -> XPromise<ResizeArray<'T>>
        abstract many: query: QueryFile * ?values: obj -> XPromise<ResizeArray<'T>>
        abstract manyOrNone: query: QueryParam * ?values: obj -> XPromise<ResizeArray<'T>>
        abstract manyOrNone: query: string * ?values: obj -> XPromise<ResizeArray<'T>>
        abstract manyOrNone: query: QueryFile * ?values: obj -> XPromise<ResizeArray<'T>>
        abstract any: query: QueryParam * ?values: obj -> XPromise<ResizeArray<'T>>

        abstract result: query: QueryParam * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>
        abstract result: query: string * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>
        abstract result: query: QueryFile * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>
        abstract result: query: IPreparedStatement * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>
        abstract result: query: IParameterizedQuery * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>
        abstract result: query: PreparedStatement * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>
        abstract result: query: ParameterizedQuery * ?values: obj * ?cb: (IResultExt -> 'T) * ?thisArg: obj -> XPromise<IResultExt>

        abstract multiResult: query: QueryParam * ?values: obj -> XPromise<ResizeArray<Pg.IResult>>
        abstract multi: query: QueryParam * ?values: obj -> XPromise<Array<ResizeArray<'T>>>
        abstract stream: qs: Stream.Stream * init: (Stream.Stream -> unit) -> XPromise<IBaseProtocolStreamXPromise>
        abstract func: funcName: string * ?values: obj * ?qrm: queryResult -> XPromise<'T>
        abstract proc: procName: string * ?values: obj * ?cb: (obj option -> 'T) * ?thisArg: obj -> XPromise<'T option>
        abstract map: query: QueryParam * values: obj option * cb: (obj option -> float -> ResizeArray<obj option> -> 'T) * ?thisArg: obj -> XPromise<ResizeArray<'T>>
        abstract each: query: QueryParam * values: obj option * cb: (obj option -> float -> ResizeArray<obj option> -> unit) * ?thisArg: obj -> XPromise<ResizeArray<'T>>
        // abstract task: cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        // abstract task: cb: (ITask<#obj> -> 'T) -> XPromise<'T>
        abstract task: cb: (ITask<#obj> -> XPromise<'T>) -> XPromise<'T>
        // abstract task: tag: U2<string, float> * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract task: tag: string * cb: (ITask<#obj> -> XPromise<'T>) -> XPromise<'T>
        abstract task: tag: float * cb: (ITask<#obj> -> XPromise<'T>) -> XPromise<'T>
        abstract task: options: IBaseProtocolTaskOptions * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract taskIf: cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract taskIf: tag: U2<string, float> * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract taskIf: options: IBaseProtocolTaskIfOptions * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        // abstract tx: cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        // abstract tx: cb: (ITask<obj> -> 'T) -> XPromise<'T>
        abstract tx : cb: (ITask<obj> -> XPromise<'T>) -> XPromise<'T>
        abstract tx: tag: U2<string, float> * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        // abstract tx: tag: float * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract tx: tag: float * cb: (ITask<obj> -> XPromise<'T>) -> XPromise<'T>
        // abstract tx: tag: string * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract tx: tag: string * cb: (ITask<obj> -> XPromise<'T>) -> XPromise<'T>
        abstract tx: options: IBaseProtocolTxOptions * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract txIf: cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract txIf: tag: U2<string, float> * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>
        abstract txIf: options: IBaseProtocolTxIfOptions * cb: (obj -> U2<'T, XPromise<'T>>) -> XPromise<'T>

    type [<AllowNullLiteral>] IBaseProtocolTaskOptions =
        abstract tag: obj option with get, set

    type [<AllowNullLiteral>] IBaseProtocolTaskIfOptions =
        abstract tag: obj option with get, set
        abstract cnd: U2<bool, (obj -> bool)> option with get, set

    type [<AllowNullLiteral>] IBaseProtocolTxOptions =
        abstract tag: obj option with get, set
        abstract mode: TransactionMode option with get, set

    type [<AllowNullLiteral>] IBaseProtocolTxIfOptions =
        abstract tag: obj option with get, set
        abstract mode: TransactionMode option with get, set
        abstract reusable: U2<bool, (obj -> bool)> option with get, set
        abstract cnd: U2<bool, (obj -> bool)> option with get, set

    type [<AllowNullLiteral>] IConnected<'Ext, 'C when 'C :> Pg.IClient> =
        inherit IBaseProtocol<'Ext>
        inherit SpexLib.ISpexBase
        abstract client: 'C
        abstract ``done``: ?kill: bool -> unit

    type [<AllowNullLiteral>] ITaskContext =
        abstract context: obj option
        abstract parent: ITaskContext option
        abstract connected: bool
        abstract inTransaction: bool
        abstract level: float
        abstract useCount: float
        abstract isTX: bool
        abstract start: DateTime
        abstract tag: obj option
        abstract dc: obj option
        abstract finish: DateTime option
        abstract duration: float option
        abstract success: bool option
        abstract result: obj option
        abstract txLevel: float option
        abstract serverVersion: string

    type IEventContext =
        IEventContext<Pg.IClient>

    type [<AllowNullLiteral>] IEventContext<'C when 'C :> Pg.IClient> =
        abstract client: 'C with get, set
        abstract cn: obj option with get, set
        abstract dc: obj option with get, set
        abstract query: obj option with get, set
        abstract ``params``: obj option with get, set
        abstract ctx: ITaskContext with get, set

    module Errors =

        type [<AllowNullLiteral>] IExports =
            abstract QueryResultError: QueryResultErrorStatic
            abstract QueryFileError: QueryFileErrorStatic
            abstract PreparedStatementError: PreparedStatementErrorStatic
            abstract ParameterizedQueryError: ParameterizedQueryErrorStatic

        type [<AllowNullLiteral;AbstractClass>] QueryResultError =
            inherit Error
            abstract name: string with get, set
            abstract message: string with get, set
            abstract stack: string with get, set
            abstract result: Pg.IResult with get, set
            abstract received: float with get, set
            abstract code: queryResultErrorCode with get, set
            abstract query: string with get, set
            abstract values: obj option with get, set
            abstract toString: unit -> string

        type [<AllowNullLiteral>] QueryResultErrorStatic =
            [<EmitConstructor>] abstract Create: unit -> QueryResultError

        type [<AllowNullLiteral;AbstractClass>] QueryFileError =
            inherit Error
            abstract name: string with get, set
            abstract message: string with get, set
            abstract stack: string with get, set
            abstract file: string with get, set
            abstract options: IQueryFileOptions with get, set
            abstract error: PgMinify.SQLParsingError with get, set
            abstract toString: ?level: float -> string

        type [<AllowNullLiteral>] QueryFileErrorStatic =
            [<EmitConstructor>] abstract Create: unit -> QueryFileError

        type [<AllowNullLiteral;AbstractClass>] PreparedStatementError =
            inherit Error
            abstract name: string with get, set
            abstract message: string with get, set
            abstract stack: string with get, set
            abstract error: QueryFileError with get, set
            abstract toString: ?level: float -> string

        type [<AllowNullLiteral>] PreparedStatementErrorStatic =
            [<EmitConstructor>] abstract Create: unit -> PreparedStatementError

        type [<AllowNullLiteral;AbstractClass>] ParameterizedQueryError =
            inherit Error
            abstract name: string with get, set
            abstract message: string with get, set
            abstract stack: string with get, set
            abstract error: QueryFileError with get, set
            abstract toString: ?level: float -> string

        type [<AllowNullLiteral>] ParameterizedQueryErrorStatic =
            [<EmitConstructor>] abstract Create: unit -> ParameterizedQueryError

        type [<RequireQualifiedAccess>] queryResultErrorCode =
            | NoData = 0
            | NotEmpty = 1
            | Multiple = 2

    type [<RequireQualifiedAccess>] isolationLevel =
        | None = 0
        | Serializable = 1
        | RepeatableRead = 2
        | ReadCommitted = 3

    type [<AllowNullLiteral>] TransactionMode =
        abstract ``begin``: ?cap: bool -> string

    type [<AllowNullLiteral>] TransactionModeStatic =
        [<EmitConstructor>] abstract Create: ?options: TransactionModeStaticOptions -> TransactionMode

    type [<AllowNullLiteral>] TransactionModeStaticOptions =
        abstract tiLevel: isolationLevel option with get, set
        abstract readOnly: bool option with get, set
        abstract deferrable: bool option with get, set

    type IInitOptions =
        IInitOptions<obj, Pg.IClient>

    type IInitOptions<'Ext> =
        IInitOptions<'Ext, Pg.IClient>

    type [<AllowNullLiteral>] IInitOptions<'Ext, 'C when 'C :> Pg.IClient> =
        abstract noWarnings: bool option with get, set
        abstract pgFormatting: bool option with get, set
        abstract pgNative: bool option with get, set
        abstract promiseLib: obj option with get, set
        abstract noLocking: bool option with get, set
        abstract capSQL: bool option with get, set
        abstract schema: U2<ValidSchema, (obj option -> ValidSchema)> option with get, set
        abstract connect: client: 'C * dc: obj option * useCount: float -> unit
        abstract disconnect: client: 'C * dc: obj option -> unit
        abstract query: e: IEventContext<'C> -> unit
        abstract receive: data: ResizeArray<obj option> * result: IResultExt * e: IEventContext<'C> -> unit with get, set
        abstract task: e: IEventContext<'C> -> unit
        abstract transact: e: IEventContext<'C> -> unit
        abstract error: err: obj option * e: IEventContext<'C> -> unit
        abstract extend: obj: obj * dc: obj option -> unit

    type ILibConfig<'Ext> =
        ILibConfig<'Ext, Pg.IClient>

    type [<AllowNullLiteral>] ILibConfig<'Ext, 'C when 'C :> Pg.IClient> =
        abstract version: string with get, set
        abstract promiseLib: obj option with get, set
        abstract promise: IGenericPromise with get, set
        abstract options: IInitOptions<'Ext, 'C> with get, set
        abstract pgp: IMain<'Ext, 'C> with get, set
        abstract ``$npm``: obj option with get, set

    type [<AllowNullLiteral>] ICTFObject =
        abstract toPostgres: a: obj option -> obj option

    type [<AllowNullLiteral>] IFormatting =
        abstract ctf: IFormattingCtf with get, set
        abstract alias: name: U2<string, (unit -> string)> -> string
        abstract array: arr: U2<ResizeArray<obj option>, (unit -> ResizeArray<obj option>)> * ?options: IFormattingArrayOptions -> string
        abstract bool: value: U2<obj option, (unit -> obj option)> -> string
        abstract buffer: obj: U2<obj, (unit -> obj)> * ?raw: bool -> string
        abstract csv: values: U2<obj option, (unit -> obj option)> -> string
        abstract date: d: U2<DateTime, (unit -> DateTime)> * ?raw: bool -> string
        // abstract format: query: U3<string, QueryFile, ICTFObject> * ?values: obj * ?options: IFormattingOptions -> string
        abstract format: query: string * ?values: obj * ?options: IFormattingOptions -> string
        abstract format: query: string * ?values: ResizeArray<obj> * ?options: IFormattingOptions -> string
        abstract format: query: QueryFile * ?values: obj * ?options: IFormattingOptions -> string
        abstract format: query: QueryFile * ?values: ResizeArray<obj> * ?options: IFormattingOptions -> string
        abstract format: query: ICTFObject * ?values: obj * ?options: IFormattingOptions -> string
        abstract format: query: ICTFObject * ?values: ResizeArray<obj> * ?options: IFormattingOptions -> string
        abstract func: func: (obj option -> obj option) * ?raw: bool * ?cc: obj -> string
        abstract json: data: U2<obj option, (unit -> obj option)> * ?raw: bool -> string
        abstract name: name: U2<obj option, (unit -> obj option)> -> string
        abstract number: value: U3<float, obj, (unit -> U2<float, obj>)> -> string
        abstract text: value: U2<obj option, (unit -> obj option)> * ?raw: bool -> string
        abstract value: value: U2<obj option, (unit -> obj option)> -> string

    type [<AllowNullLiteral>] IFormattingArrayOptions =
        abstract capSQL: bool option with get, set

    type [<AllowNullLiteral>] ITXMode =
        abstract isolationLevel: obj with get, set
        abstract TransactionMode: obj with get, set

    type [<AllowNullLiteral>] IArguments =
        interface end

    type [<AllowNullLiteral>] ITaskArguments<'T> =
        inherit IArguments
        abstract options: obj with get, set
        abstract cb: unit -> obj option

    type [<AllowNullLiteral>] IUtils =
        abstract camelize: text: string -> string
        abstract camelizeVar: text: string -> string
        abstract enumSql: dir: string * ?options: IUtilsEnumSqlOptions * ?cb: (string -> string -> string -> obj option) -> obj option
        abstract taskArgs: args: IArguments -> ITaskArguments<'T>

    type [<AllowNullLiteral>] IUtilsEnumSqlOptions =
        abstract recursive: bool option with get, set
        abstract ignoreErrors: bool option with get, set

    type [<AllowNullLiteral>] IHelpers =
        abstract concat: queries: Array<U3<string, QueryFile, IHelpersConcatArray>> -> string
        // abstract insert: data: U2<obj, ResizeArray<obj>> * ?columns: QueryColumns<obj option> * ?table: U3<string, ITable, TableName> -> string
        abstract insert: data: ResizeArray<#obj> * ?columns: QueryColumns<obj option> * ?table: U3<string, ITable, TableName> -> string
        abstract insert: data: ResizeArray<#obj> * ?columns: ColumnSet<'T> * ?table: U3<string, ITable, TableName> -> string
        // abstract update: data: U2<obj, ResizeArray<obj>> * ?columns: QueryColumns<obj option> * ?table: U3<string, ITable, TableName> * ?options: IHelpersUpdateOptions -> obj option
        // abstract update: data: obj * ?columns: QueryColumns<obj option> * ?table: U3<string, ITable, TableName> * ?options: IHelpersUpdateOptions -> obj option
        // abstract update: data: ResizeArray<obj> * ?columns: QueryColumns<obj option> * ?table: U3<string, ITable, TableName> * ?options: IHelpersUpdateOptions -> obj option
        abstract update: data: ResizeArray<#obj> * ?columns: ColumnSet<'T> * ?table: U3<string, ITable, TableName> * ?options: IHelpersUpdateOptions -> string
        abstract values: data: U2<obj, ResizeArray<obj>> * ?columns: QueryColumns<obj option> -> string
        abstract values: data: obj * ?columns: QueryColumns<obj option> -> string
        abstract values: data: ResizeArray<#obj> * ?columns: QueryColumns<obj option> -> string
        abstract values: data: ResizeArray<#obj> * ?columns: ColumnSet<'T> -> string
        abstract sets: data: obj * ?columns: QueryColumns<obj option> -> string
        abstract Column: obj with get, set
        abstract ColumnSet: ColumnSet
        abstract TableName: obj with get, set

    type [<AllowNullLiteral>] IHelpersUpdateOptions =
        abstract tableAlias: string option with get, set
        abstract valueAlias: string option with get, set
        abstract emptyUpdate: obj option with get, set

    type [<AllowNullLiteral>] IGenericPromise =
        [<Emit "$0($1...)">] abstract Invoke: cb: ((obj -> unit) -> (obj -> unit) -> unit) -> XPromise<obj option>
        abstract resolve: ?value: obj -> unit
        abstract reject: ?reason: obj -> unit
        abstract all: iterable: obj option -> XPromise<obj option>

    type [<AllowNullLiteral>] IBaseProtocolStreamXPromise =
        abstract processed: float with get, set
        abstract duration: float with get, set

    type [<AllowNullLiteral>] IFormattingCtf =
        abstract toPostgres: Symbol with get, set
        abstract rawType: Symbol with get, set

    type [<AllowNullLiteral>] IHelpersConcatArray =
        abstract query: U2<string, QueryFile> with get, set
        abstract values: obj option with get, set
        abstract options: IFormattingOptions option with get, set

PgProtocol

// ts2fable 0.8.0
module rec PgProtocol

open Fable.Core
open Fable.Core.JsInterop

let DatabaseError : Message.DatabaseErrorStatic = import "DatabaseError" "pg-protocol"

module Message =

    type [<StringEnum>] [<RequireQualifiedAccess>] MessageName =
        | ParseComplete
        | BindComplete
        | CloseComplete
        | NoData
        | PortalSuspended
        | ReplicationStart
        | EmptyQuery
        | CopyDone
        | CopyData
        | RowDescription
        | ParameterDescription
        | ParameterStatus
        | BackendKeyData
        | Notification
        | ReadyForQuery
        | CommandComplete
        | DataRow
        | CopyInResponse
        | CopyOutResponse
        | AuthenticationOk
        | AuthenticationMD5Password
        | AuthenticationCleartextPassword
        | AuthenticationSASL
        | AuthenticationSASLContinue
        | AuthenticationSASLFinal
        | Error
        | Notice

    type [<ImportMember("pg-protocol"); AllowNullLiteral; AbstractClass>] DatabaseError =
        inherit System.Exception
        // inherit NoticeOrError
        abstract length: float
        abstract name: MessageName
        abstract severity: string option
        abstract code: string option
        abstract detail: string option
        abstract hint: string option
        abstract position: string option
        abstract internalPosition: string option
        abstract internalQuery: string option
        abstract where: string option
        abstract schema: string option
        abstract table: string option
        abstract column: string option
        abstract dataType: string option
        abstract ``constraint``: string option
        abstract file: string option
        abstract line: string option
        abstract routine: string option

    type [<AllowNullLiteral>] DatabaseErrorStatic =
        [<EmitConstructor>] abstract Create: message: string * length: float * name: MessageName -> DatabaseError

PgSubset

// ts2fable 0.8.0
module rec PgSubset
open System
open Fable.Core
open Fable.Core.JS
open Node

type Array<'T> = System.Collections.Generic.IList<'T>
type Error = System.Exception
type Function = System.Action

type EventEmitter = Events.EventEmitter
// type checkServerIdentity = Tls. checkServerIdentity
// let [<Import("*","module")>] pg: Pg.IExports = jsNative

module Pg =

    type [<AllowNullLiteral>] IExports =
        abstract defaults: IDefaults
        abstract types: ITypes
        abstract Client: obj

    type [<AllowNullLiteral>] IColumn =
        abstract name: string with get, set
        abstract oid: float with get, set
        abstract dataTypeID: int with get, set
        abstract tableID: float with get, set
        abstract columnID: float with get, set
        abstract dataTypeSize: float with get, set
        abstract dataTypeModifier: float with get, set
        abstract format: string with get, set

    type [<AllowNullLiteral>] IResult =
        abstract command: string with get, set
        abstract rowCount: float with get, set
        abstract rows: ResizeArray<obj option> with get, set
        abstract fields: ResizeArray<IColumn> with get, set
        abstract rowAsArray: bool with get, set
        abstract _types: IResult_types with get, set
        abstract _parsers: Array<Function> with get, set

    type [<AllowNullLiteral>] ISSLConfig =
        abstract ca: U3<string, Buffer, Array<U2<string, Buffer>>> option with get, set
        abstract pfx: U3<string, Buffer, Array<U3<string, Buffer, obj>>> option with get, set
        abstract cert: U3<string, Buffer, Array<U2<string, Buffer>>> option with get, set
        abstract key: U3<string, Buffer, Array<U2<Buffer, obj>>> option with get, set
        abstract passphrase: string option with get, set
        abstract rejectUnauthorized: bool option with get, set
        abstract checkServerIdentity: obj option with get, set
        abstract secureOptions: float option with get, set
        abstract NPNProtocols: U5<ResizeArray<string>, Buffer, ResizeArray<Buffer>, Uint8Array, ResizeArray<Uint8Array>> option with get, set

    type DynamicPassword =
        U3<string, (unit -> string), (unit -> Promise<string>)>

    type IConnectionParameters =
        IConnectionParameters<IClient>

    type [<AllowNullLiteral>] IConnectionParameters<'C when 'C :> IClient> =
        abstract connectionString: string option with get, set
        abstract host: string option with get, set
        abstract database: string option with get, set
        abstract user: string option with get, set
        abstract password: DynamicPassword option with get, set
        abstract port: float option with get, set
        abstract ssl: U2<bool, ISSLConfig> option with get, set
        abstract binary: bool option with get, set
        abstract client_encoding: string option with get, set
        abstract encoding: string option with get, set
        abstract application_name: string option with get, set
        abstract fallback_application_name: string option with get, set
        abstract isDomainSocket: bool option with get, set
        abstract max: float option with get, set
        abstract maxUses: float option with get, set
        abstract idleTimeoutMillis: float option with get, set
        abstract parseInputDatesAsUTC: bool option with get, set
        abstract rows: float option with get, set
        abstract statement_timeout: U2<bool, float> option with get, set
        abstract query_timeout: U2<bool, float> option with get, set
        abstract connectionTimeoutMillis: float option with get, set
        abstract keepAliveInitialDelayMillis: float option with get, set
        abstract keepAlive: bool option with get, set
        abstract keepalives: float option with get, set
        abstract keepalives_idle: float option with get, set
        abstract Client: obj option with get, set
        abstract Promise: obj option with get, set
        abstract types: ITypeOverrides option with get, set

    type [<RequireQualifiedAccess>] TypeId =
        | BOOL = 16
        | BYTEA = 17
        | CHAR = 18
        | INT8 = 20
        | INT2 = 21
        | INT4 = 23
        | REGPROC = 24
        | TEXT = 25
        | OID = 26
        | TID = 27
        | XID = 28
        | CID = 29
        | JSON = 114
        | XML = 142
        | PG_NODE_TREE = 194
        | SMGR = 210
        | PATH = 602
        | POLYGON = 604
        | CIDR = 650
        | FLOAT4 = 700
        | FLOAT8 = 701
        | ABSTIME = 702
        | RELTIME = 703
        | TINTERVAL = 704
        | CIRCLE = 718
        | MACADDR8 = 774
        | MONEY = 790
        | MACADDR = 829
        | INET = 869
        | ACLITEM = 1033
        | BPCHAR = 1042
        | VARCHAR = 1043
        | DATE = 1082
        | TIME = 1083
        | TIMESTAMP = 1114
        | TIMESTAMPTZ = 1184
        | INTERVAL = 1186
        | TIMETZ = 1266
        | BIT = 1560
        | VARBIT = 1562
        | NUMERIC = 1700
        | REFCURSOR = 1790
        | REGPROCEDURE = 2202
        | REGOPER = 2203
        | REGOPERATOR = 2204
        | REGCLASS = 2205
        | REGTYPE = 2206
        | UUID = 2950
        | TXID_SNAPSHOT = 2970
        | PG_LSN = 3220
        | PG_NDISTINCT = 3361
        | PG_DEPENDENCIES = 3402
        | TSVECTOR = 3614
        | TSQUERY = 3615
        | GTSVECTOR = 3642
        | REGCONFIG = 3734
        | REGDICTIONARY = 3769
        | JSONB = 3802
        | REGNAMESPACE = 4089
        | REGROLE = 4096

    type [<StringEnum>] [<RequireQualifiedAccess>] ParserFormat =
        | Text
        | Binary

    type [<AllowNullLiteral>] ITypeOverrides =
        abstract setTypeParser: id: TypeId * parseFn: U2<string, (string -> obj option)> -> unit
        abstract setTypeParser: id: TypeId * format: ParserFormat * parseFn: U2<string, (string -> obj option)> -> unit
        abstract getTypeParser: id: TypeId * ?format: ParserFormat -> obj option

    type [<AllowNullLiteral>] ITypes =
        inherit ITypeOverrides
        abstract arrayParser: source: string * transform: (obj option -> obj option) -> ResizeArray<obj option>
        abstract builtins: obj with get, set

    type [<AllowNullLiteral>] IDefaults =
        abstract connectionString: string with get, set
        abstract host: string with get, set
        abstract user: string with get, set
        abstract database: string with get, set
        abstract password: DynamicPassword with get, set
        abstract port: float with get, set
        abstract rows: float with get, set
        abstract binary: bool with get, set
        abstract max: float with get, set
        abstract client_encoding: string with get, set
        abstract ssl: U2<bool, ISSLConfig> with get, set
        abstract application_name: string with get, set
        abstract fallback_application_name: string with get, set
        abstract parseInputDatesAsUTC: bool with get, set
        abstract statement_timeout: U2<bool, float> with get, set
        abstract query_timeout: U2<bool, float> with get, set
        abstract keepalives: float with get, set
        abstract keepalives_idle: float with get, set

    type [<AllowNullLiteral>] IPool =
        inherit EventEmitter
        abstract ``end``: unit -> Promise<obj>
        abstract ``end``: cb: (Error -> obj option) -> obj option
        abstract options: IPoolOptions
        abstract ended: bool
        abstract ending: bool
        abstract waitingCount: float
        abstract idleCount: float
        abstract totalCount: float

    type [<AllowNullLiteral>] IQuery =
        interface end

    type [<AllowNullLiteral>] IConnection =
        inherit EventEmitter
        abstract stream: Net.Socket with get, set

    type [<AllowNullLiteral>] IClient =
        inherit EventEmitter
        abstract query: config: obj option * values: ResizeArray<obj option> * callback: (Error -> IResult -> unit) -> obj
        abstract query: config: obj option * callback: (Error -> IResult -> unit) -> obj
        abstract query: config: obj option * values: ResizeArray<obj option> -> Promise<IResult>
        abstract query: config: obj option -> Promise<IResult>
        abstract connectionParameters: IConnectionParameters with get, set
        abstract database: string with get, set
        abstract user: string with get, set
        abstract password: DynamicPassword with get, set
        abstract port: float with get, set
        abstract host: string with get, set
        abstract serverVersion: string
        abstract connection: IConnection with get, set
        abstract queryQueue: ResizeArray<IQuery> with get, set
        abstract binary: bool with get, set
        abstract ssl: U2<bool, ISSLConfig> with get, set
        abstract secretKey: float with get, set
        abstract processID: float with get, set
        abstract encoding: string with get, set
        abstract readyForQuery: bool with get, set
        abstract activeQuery: IQuery with get, set

    type [<AllowNullLiteral>] IResult_types =
        abstract _types: obj option with get, set
        abstract text: obj option with get, set
        abstract binary: obj option with get, set

    type [<AllowNullLiteral>] IPoolOptions =
        [<EmitIndexer>] abstract Item: name: string -> obj option with get, set
joprice commented 2 weeks ago

Thank you for the bindings. I wasn't aware of these other projects around node-postgres. Often good tooling beats performance especially when prototyping quickly. I'll have to try them out and reconsider.

MangelMaxime commented 2 weeks ago

Often good tooling beats performance especially when prototyping quickly. I'll have to try them out and reconsider.

Indeed and also, is the performance a real worry 😇

I mean in a lot of project I worked on people worried about the performance but never reached the potential bottle neck far from it. I don't want to assume anything regarding your project.