@@ -8,11 +8,14 @@ const {
88 mergeUserTypes,
99 arraySerializer,
1010 arrayParser,
11+ fromPascal,
12+ fromCamel,
13+ fromKebab,
1114 inferType,
1215 toPascal,
13- entries,
1416 toCamel,
1517 toKebab,
18+ entries,
1619 escape,
1720 types,
1821 END
@@ -33,6 +36,9 @@ Object.assign(Postgres, {
3336 toPascal,
3437 toCamel,
3538 toKebab,
39+ fromPascal,
40+ fromCamel,
41+ fromKebab,
3642 BigInt : {
3743 to : 20 ,
3844 from : [ 20 ] ,
@@ -52,6 +58,7 @@ function Postgres(a, b) {
5258 const options = parseOptions ( a , b )
5359
5460 const max = Math . max ( 1 , options . max )
61+ , transform = options . transform
5562 , connections = Queue ( )
5663 , all = [ ]
5764 , queries = Queue ( )
@@ -537,7 +544,9 @@ function Postgres(a, b) {
537544 function selectHelper ( first , columns , xargs , types ) {
538545 return entries ( first ) . reduce ( ( acc , [ k , v ] ) =>
539546 acc + ( ! columns . length || columns . indexOf ( k ) > - 1
540- ? ( acc ? ',' : '' ) + parseValue ( v , xargs , types ) + ' as ' + escape ( k )
547+ ? ( acc ? ',' : '' ) + parseValue ( v , xargs , types ) + ' as ' + escape (
548+ transform . column . to ? transform . column . to ( k ) : k
549+ )
541550 : ''
542551 ) ,
543552 ''
@@ -558,13 +567,17 @@ function Postgres(a, b) {
558567
559568 function equalsHelper ( first , columns , xargs , types ) {
560569 return ( columns . length ? columns : Object . keys ( first ) ) . reduce ( ( acc , k ) =>
561- acc + ( acc ? ',' : '' ) + escape ( k ) + ' = ' + parseValue ( first [ k ] , xargs , types ) ,
570+ acc + ( acc ? ',' : '' ) + escape (
571+ transform . column . to ? transform . column . to ( k ) : k
572+ ) + ' = ' + parseValue ( first [ k ] , xargs , types ) ,
562573 ''
563574 )
564575 }
565576
566577 function escapeHelper ( xs ) {
567- return xs . reduce ( ( acc , x ) => acc + ( acc ? ',' : '' ) + escape ( x ) , '' )
578+ return xs . reduce ( ( acc , x ) => acc + ( acc ? ',' : '' ) + escape (
579+ transform . column . to ? transform . column . to ( x ) : x
580+ ) , '' )
568581 }
569582
570583 function parseValue ( x , xargs , types ) {
@@ -628,7 +641,7 @@ function parseOptions(a, b) {
628641 prepare : 'prepare' in o ? o . prepare : 'no_prepare' in o ? ! o . no_prepare : true ,
629642 onnotice : o . onnotice ,
630643 onparameter : o . onparameter ,
631- transform : Object . assign ( { } , o . transform ) ,
644+ transform : parseTransform ( o . transform || { } ) ,
632645 connection : Object . assign ( { application_name : 'postgres.js' } , o . connection ) ,
633646 target_session_attrs : o . target_session_attrs || url . query . target_session_attrs || env . PGTARGETSESSIONATTRS ,
634647 debug : o . debug ,
@@ -638,6 +651,23 @@ function parseOptions(a, b) {
638651 )
639652}
640653
654+ function parseTransform ( x ) {
655+ return {
656+ column : {
657+ from : typeof x . column === 'function' ? x . column : x . column && x . column . from ,
658+ to : x . column && x . column . to
659+ } ,
660+ value : {
661+ from : typeof x . value === 'function' ? x . value : x . value && x . value . from ,
662+ to : x . value && x . value . to
663+ } ,
664+ row : {
665+ from : typeof x . row === 'function' ? x . row : x . row && x . row . from ,
666+ to : x . row && x . row . to
667+ }
668+ }
669+ }
670+
641671function parseSSL ( x ) {
642672 return x !== 'disable' && x !== 'false' && x
643673}
0 commit comments