Skip to content

Commit 74a5b2a

Browse files
committed
Update transformer types and documentation
1 parent 2915105 commit 74a5b2a

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ You can use either a `postgres://` url connection string or the options to defin
4545

4646
```js
4747
const sql = postgres('postgres://username:password@host:port/database', {
48-
host : '', // Postgres ip address[s] or domain name[s]
49-
port : 5432, // Postgres server port[s]
50-
path : '', // unix socket path (usually '/tmp')
51-
database : '', // Name of database to connect to
52-
username : '', // Username of database user
53-
password : '', // Password of database user
54-
ssl : false, // true, prefer, require, tls.connect options
55-
max : 10, // Max number of connections
56-
idle_timeout : 0, // Idle connection timeout in seconds
57-
connect_timeout : 30, // Connect timeout in seconds
58-
no_prepare : false, // No automatic creation of prepared statements
59-
types : [], // Array of custom types, see more below
60-
onnotice : fn, // Defaults to console.log
61-
onparameter : fn, // (key, value) when server param change
62-
debug : fn, // Is called with (connection, query, params)
48+
host : '', // Postgres ip address[s] or domain name[s]
49+
port : 5432, // Postgres server port[s]
50+
path : '', // unix socket path (usually '/tmp')
51+
database : '', // Name of database to connect to
52+
username : '', // Username of database user
53+
password : '', // Password of database user
54+
ssl : false, // true, prefer, require, tls.connect options
55+
max : 10, // Max number of connections
56+
idle_timeout : 0, // Idle connection timeout in seconds
57+
connect_timeout : 30, // Connect timeout in seconds
58+
no_prepare : false, // No automatic creation of prepared statements
59+
types : [], // Array of custom types, see more below
60+
onnotice : fn, // Defaults to console.log
61+
onparameter : fn, // (key, value) when server param change
62+
debug : fn, // Is called with (connection, query, params)
6363
transform : {
64-
column : fn, // Transforms incoming column names
65-
value : fn, // Transforms incoming row values
66-
row : fn // Transforms entire rows
64+
column : {to?: fn, from?: fn}, // Transforms incoming or outgoing column names
65+
value : {to?: fn, from?: fn}, // Transforms incoming or outgoing row values
66+
row : {to?: fn, from?: fn}, // Transforms entire incoming or outgoing rows
6767
},
6868
connection : {
69-
application_name : 'postgres.js', // Default application_name
70-
... // Other connection parameters
69+
application_name : 'postgres.js', // Default application_name
70+
... // Other connection parameters
7171
},
72-
target_session_attrs : null, // Use 'read-write' with multiple hosts to
73-
// ensure only connecting to primary
74-
fetch_array_types : true, // Disable automatically fetching array types
75-
// on initial connection.
72+
target_session_attrs : null, // Use 'read-write' with multiple hosts to
73+
// ensure only connecting to primary
74+
fetch_array_types : true, // Disable automatically fetching array types
75+
// on initial connection.
7676
})
7777
```
7878

types/index.d.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ interface BaseOptions<T extends JSToPostgresTypeMap> {
5252
debug: boolean | ((connection: number, query: string, parameters: any[]) => void);
5353
/** Transform hooks */
5454
transform: {
55-
/** Transforms incoming column names */
56-
column?: (column: string) => string;
57-
/** Transforms incoming row values */
58-
value?: (value: any) => any;
59-
/** Transforms entire rows */
60-
row?: (row: postgres.Row) => any;
55+
/** Transforms incoming and outgoing column names. */
56+
column?: (column: string) => string | { from?: (column: string) => string, to?: (column: string) => string };
57+
/** Transforms incoming and outgoing row values. */
58+
value?: (value: any) => any | { from?: (value: any) => any, to?: (value: any) => any };
59+
/** Transforms entire incoming and outgoing rows. */
60+
row?: (row: postgres.Row) => any | { from?: (row: postgres.Row) => any, to?: (row: postgres.Row) => any };
6161
};
6262
/** Connection parameters */
6363
connection: Partial<postgres.ConnectionParameters>;
@@ -109,21 +109,40 @@ declare namespace postgres {
109109
export const PostgresError: PostgresErrorType;
110110

111111
/**
112-
* Convert a string to Pascal case.
113-
* @param str THe string to convert
114-
* @returns The new string in Pascal case
112+
* Convert a string from PascalCase to snake_case.
113+
* @param str The PascalCase string to convert.
114+
* @returns The new string in snake_case.
115+
*/
116+
function fromPascal(str: string): string;
117+
/**
118+
* Convert a camelCase string to snake_case.
119+
* @param str The camelCase string to convert.
120+
* @returns The new string in snake_case.
121+
*/
122+
function fromCamel(str: string): string;
123+
/**
124+
* Convert a kebab-case string to snake_case.
125+
* @param str The kebab-case string to convert.
126+
* @returns The new string in snake_case.
127+
*/
128+
function fromKebab(str: string): string;
129+
130+
/**
131+
* Convert a snake_case string to PascalCase.
132+
* @param str The snake_case string to convert.
133+
* @returns The new string in PascalCase.
115134
*/
116135
function toPascal(str: string): string;
117136
/**
118-
* Convert a string to Camel case.
119-
* @param str THe string to convert
120-
* @returns The new string in Camel case
137+
* Convert a snake_case string to camelCase.
138+
* @param str The snake_case string to convert.
139+
* @returns The new string in camelCase.
121140
*/
122141
function toCamel(str: string): string;
123142
/**
124-
* Convert a string to Kebab case.
125-
* @param str THe string to convert
126-
* @returns The new string in Kebab case
143+
* Convert a snake_case string to kebab-case.
144+
* @param str The snake_case string to convert.
145+
* @returns The new string in kebab-case.
127146
*/
128147
function toKebab(str: string): string;
129148

0 commit comments

Comments
 (0)