diff --git a/README.md b/README.md index ef6b6cc6..eb2ca415 100644 --- a/README.md +++ b/README.md @@ -45,34 +45,34 @@ You can use either a `postgres://` url connection string or the options to defin ```js const sql = postgres('postgres://username:password@host:port/database', { - host : '', // Postgres ip address[s] or domain name[s] - port : 5432, // Postgres server port[s] - path : '', // unix socket path (usually '/tmp') - database : '', // Name of database to connect to - username : '', // Username of database user - password : '', // Password of database user - ssl : false, // true, prefer, require, tls.connect options - max : 10, // Max number of connections - idle_timeout : 0, // Idle connection timeout in seconds - connect_timeout : 30, // Connect timeout in seconds - no_prepare : false, // No automatic creation of prepared statements - types : [], // Array of custom types, see more below - onnotice : fn, // Defaults to console.log - onparameter : fn, // (key, value) when server param change - debug : fn, // Is called with (connection, query, params) + host : '', // Postgres ip address[s] or domain name[s] + port : 5432, // Postgres server port[s] + path : '', // unix socket path (usually '/tmp') + database : '', // Name of database to connect to + username : '', // Username of database user + password : '', // Password of database user + ssl : false, // true, prefer, require, tls.connect options + max : 10, // Max number of connections + idle_timeout : 0, // Idle connection timeout in seconds + connect_timeout : 30, // Connect timeout in seconds + no_prepare : false, // No automatic creation of prepared statements + types : [], // Array of custom types, see more below + onnotice : fn, // Defaults to console.log + onparameter : fn, // (key, value) when server param change + debug : fn, // Is called with (connection, query, params) transform : { - column : fn, // Transforms incoming column names - value : fn, // Transforms incoming row values - row : fn // Transforms entire rows + column : {to?: fn, from?: fn}, // Transforms incoming or outgoing column names + value : {to?: fn, from?: fn}, // Transforms incoming or outgoing row values + row : {to?: fn, from?: fn}, // Transforms entire incoming or outgoing rows }, connection : { - application_name : 'postgres.js', // Default application_name - ... // Other connection parameters + application_name : 'postgres.js', // Default application_name + ... // Other connection parameters }, - target_session_attrs : null, // Use 'read-write' with multiple hosts to - // ensure only connecting to primary - fetch_array_types : true, // Disable automatically fetching array types - // on initial connection. + target_session_attrs : null, // Use 'read-write' with multiple hosts to + // ensure only connecting to primary + fetch_array_types : true, // Disable automatically fetching array types + // on initial connection. }) ``` diff --git a/types/index.d.ts b/types/index.d.ts index 4f2c2a6d..8246041e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -52,12 +52,12 @@ interface BaseOptions { debug: boolean | ((connection: number, query: string, parameters: any[]) => void); /** Transform hooks */ transform: { - /** Transforms incoming column names */ - column?: (column: string) => string; - /** Transforms incoming row values */ - value?: (value: any) => any; - /** Transforms entire rows */ - row?: (row: postgres.Row) => any; + /** Transforms incoming and outgoing column names. */ + column?: ((column: string) => string) | { from?: (column: string) => string, to?: (column: string) => string }; + /** Transforms incoming and outgoing row values. */ + value?: ((value: any) => any) | { from?: (value: any) => any, to?: (value: any) => any }; + /** Transforms entire incoming and outgoing rows. */ + row?: ((row: postgres.Row) => any) | { from?: (row: postgres.Row) => any, to?: (row: any) => any }; }; /** Connection parameters */ connection: Partial; @@ -109,21 +109,40 @@ declare namespace postgres { export const PostgresError: PostgresErrorType; /** - * Convert a string to Pascal case. - * @param str THe string to convert - * @returns The new string in Pascal case + * Convert a string from PascalCase to snake_case. + * @param str The PascalCase string to convert. + * @returns The new string in snake_case. + */ + function fromPascal(str: string): string; + /** + * Convert a camelCase string to snake_case. + * @param str The camelCase string to convert. + * @returns The new string in snake_case. + */ + function fromCamel(str: string): string; + /** + * Convert a kebab-case string to snake_case. + * @param str The kebab-case string to convert. + * @returns The new string in snake_case. + */ + function fromKebab(str: string): string; + + /** + * Convert a snake_case string to PascalCase. + * @param str The snake_case string to convert. + * @returns The new string in PascalCase. */ function toPascal(str: string): string; /** - * Convert a string to Camel case. - * @param str THe string to convert - * @returns The new string in Camel case + * Convert a snake_case string to camelCase. + * @param str The snake_case string to convert. + * @returns The new string in camelCase. */ function toCamel(str: string): string; /** - * Convert a string to Kebab case. - * @param str THe string to convert - * @returns The new string in Kebab case + * Convert a snake_case string to kebab-case. + * @param str The snake_case string to convert. + * @returns The new string in kebab-case. */ function toKebab(str: string): string;