formatting.ctf

Namespace for ES6 symbols used by Custom Type Formatting, available from pgp.as.ctf before and after initializing the library.

It was added to avoid explicit/enumerable extension of types that need to be used as formatting parameters, to keep their type signature intact.

Properties:
Name Type Description
toPostgres external:Symbol

Property name for the Custom Type Formatting callback function toPostgres.

rawType external:Symbol

Property name for the Custom Type Formatting flag rawType.

Source:

Example

const {toPostgres, rawType} = pgp.as.ctf; // Custom Type Formatting symbols

class MyType {
    constructor() {
        this[rawType] = true; // set it only when toPostgres returns a pre-formatted result
    }

    [toPostgres](self) {
        // self = this

        // return the custom/actual value here
    }
}

const a = new MyType();

const s = pgp.as.format('$1', a); // will be custom-formatted