Skip to content

Commit 346bf3f

Browse files
committed
Add column name transform
1 parent 7a02b94 commit 346bf3f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ import {
88
arraySerializer,
99
arrayParser,
1010
inferType,
11+
toPascal,
12+
toCamel,
13+
toKebab,
1114
errors,
1215
types
1316
} from './types.js'
1417

18+
Object.assign(Postgres, {
19+
toPascal,
20+
toCamel,
21+
toKebab
22+
})
23+
1524
export default function Postgres(url, options) {
1625
options = parseOptions(url, options)
1726

lib/types.js

+16
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ function arrayParserLoop(s, x, parser) {
145145
return xs
146146
}
147147

148+
export const toCamel = x => {
149+
let str = x[0]
150+
for (let i = 1; i < x.length; i++)
151+
str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
152+
return str
153+
}
154+
155+
export const toPascal = x => {
156+
let str = x[0].toUpperCase()
157+
for (let i = 1; i < x.length; i++)
158+
str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
159+
return str
160+
}
161+
162+
export const toKebab = x => x.replace(/_/g, '-')
163+
148164
export const errors = {
149165
connection: (x, options) => Object.assign(
150166
new Error('write CONNECTION_' + x + ' ' + options.path || (options.host + ':' + options.port)),

0 commit comments

Comments
 (0)