@@ -8,11 +8,14 @@ const {
8
8
mergeUserTypes,
9
9
arraySerializer,
10
10
arrayParser,
11
+ fromPascal,
12
+ fromCamel,
13
+ fromKebab,
11
14
inferType,
12
15
toPascal,
13
- entries,
14
16
toCamel,
15
17
toKebab,
18
+ entries,
16
19
escape,
17
20
types,
18
21
END
@@ -33,6 +36,9 @@ Object.assign(Postgres, {
33
36
toPascal,
34
37
toCamel,
35
38
toKebab,
39
+ fromPascal,
40
+ fromCamel,
41
+ fromKebab,
36
42
BigInt : {
37
43
to : 20 ,
38
44
from : [ 20 ] ,
@@ -52,6 +58,7 @@ function Postgres(a, b) {
52
58
const options = parseOptions ( a , b )
53
59
54
60
const max = Math . max ( 1 , options . max )
61
+ , transform = options . transform
55
62
, connections = Queue ( )
56
63
, all = [ ]
57
64
, queries = Queue ( )
@@ -537,7 +544,9 @@ function Postgres(a, b) {
537
544
function selectHelper ( first , columns , xargs , types ) {
538
545
return entries ( first ) . reduce ( ( acc , [ k , v ] ) =>
539
546
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
+ )
541
550
: ''
542
551
) ,
543
552
''
@@ -558,13 +567,17 @@ function Postgres(a, b) {
558
567
559
568
function equalsHelper ( first , columns , xargs , types ) {
560
569
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 ) ,
562
573
''
563
574
)
564
575
}
565
576
566
577
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
+ ) , '' )
568
581
}
569
582
570
583
function parseValue ( x , xargs , types ) {
@@ -628,7 +641,7 @@ function parseOptions(a, b) {
628
641
prepare : 'prepare' in o ? o . prepare : 'no_prepare' in o ? ! o . no_prepare : true ,
629
642
onnotice : o . onnotice ,
630
643
onparameter : o . onparameter ,
631
- transform : Object . assign ( { } , o . transform ) ,
644
+ transform : parseTransform ( o . transform || { } ) ,
632
645
connection : Object . assign ( { application_name : 'postgres.js' } , o . connection ) ,
633
646
target_session_attrs : o . target_session_attrs || url . query . target_session_attrs || env . PGTARGETSESSIONATTRS ,
634
647
debug : o . debug ,
@@ -638,6 +651,23 @@ function parseOptions(a, b) {
638
651
)
639
652
}
640
653
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
+
641
671
function parseSSL ( x ) {
642
672
return x !== 'disable' && x !== 'false' && x
643
673
}
0 commit comments