Skip to content

Commit

Permalink
Please eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Jan 3, 2023
1 parent 4467d11 commit 7ac131e
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 89 deletions.
12 changes: 11 additions & 1 deletion cjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,18 @@ function parseUrl(url) {
host = host.slice(host.indexOf('://') + 3).split(/[?/]/)[0]
host = decodeURIComponent(host.slice(host.indexOf('@') + 1))

const urlObj = new URL(url.replace(host, host.split(',')[0]))

return {
url: new URL(url.replace(host, host.split(',')[0])),
url: {
username: decodeURIComponent(urlObj.username),
password: decodeURIComponent(urlObj.password),
host: urlObj.host,
hostname: urlObj.hostname,
port: urlObj.port,
pathname: urlObj.pathname,
searchParams: urlObj.searchParams
},
multihost: host.indexOf(',') > -1 && host
}
}
Expand Down
2 changes: 1 addition & 1 deletion cjs/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const builders = Object.entries({
update(first, rest, parameters, types, options) {
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
'=' + handleValue(first[x], parameters, types, options)
'=' + stringifyValue('values', first[x], parameters, types, options)
)
},

Expand Down
59 changes: 31 additions & 28 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ t('Connect using uri', async() =>
})]
)

t('Options from uri with special characters in user and pass', async() => {
const opt = postgres({ user: 'öla', pass: 'pass^word' }).options
return [[opt.user, opt.pass].toString(), 'öla,pass^word']
})

t('Fail with proper error on no host', async() =>
['ECONNREFUSED', (await new Promise((resolve, reject) => {
const sql = postgres('postgres://localhost:33333/' + options.db, {
Expand Down Expand Up @@ -540,7 +545,7 @@ t('Connection end does not cancel query', async() => {

const promise = sql`select 1 as x`.execute()

sql.end()
await sql.end()

return [1, (await promise)[0].x]
})
Expand Down Expand Up @@ -616,39 +621,37 @@ t('Transform deeply nested json object in arrays', async() => {
...options,
transform: postgres.camel
})
return ['childObj_deeplyNestedObj_grandchildObj', (await sql`select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x`)[0].x
.map((x) => {
let result;
for (const key in x) {
const result1 = Object.keys(x[key]);
const result2 = Object.keys(x[key].deeplyNestedObj);

result = [...result1, ...result2];
}

return result;
})[0]
.join('_')]
return [
'childObj_deeplyNestedObj_grandchildObj',
(await sql`
select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x
`)[0].x.map(x => {
let result
for (const key in x)
result = [...Object.keys(x[key]), ...Object.keys(x[key].deeplyNestedObj)]
return result
})[0]
.join('_')
]
})

t('Transform deeply nested json array in arrays', async() => {
const sql = postgres({
...options,
transform: postgres.camel
})
return ['childArray_deeplyNestedArray_grandchildArray', (await sql`select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x`)[0].x
.map((x) => {
let result;
for (const key in x) {
const result1 = Object.keys(x[key][0]);
const result2 = Object.keys(x[key][0].deeplyNestedArray[0]);

result = [...result1, ...result2];
}

return result;
})[0]
.join('_')]
return [
'childArray_deeplyNestedArray_grandchildArray',
(await sql`
select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x
`)[0].x.map((x) => {
let result
for (const key in x)
result = [...Object.keys(x[key][0]), ...Object.keys(x[key][0].deeplyNestedArray[0])]
return result
})[0]
.join('_')
]
})

t('Bypass transform for json primitive', async() => {
Expand Down Expand Up @@ -1630,7 +1633,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
err = e.message
})
server.close()
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
})

t('requests works after single connect_timeout', async() => {
Expand Down
12 changes: 11 additions & 1 deletion deno/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,18 @@ function parseUrl(url) {
host = host.slice(host.indexOf('://') + 3).split(/[?/]/)[0]
host = decodeURIComponent(host.slice(host.indexOf('@') + 1))

const urlObj = new URL(url.replace(host, host.split(',')[0]))

return {
url: new URL(url.replace(host, host.split(',')[0])),
url: {
username: decodeURIComponent(urlObj.username),
password: decodeURIComponent(urlObj.password),
host: urlObj.host,
hostname: urlObj.hostname,
port: urlObj.port,
pathname: urlObj.pathname,
searchParams: urlObj.searchParams
},
multihost: host.indexOf(',') > -1 && host
}
}
Expand Down
2 changes: 1 addition & 1 deletion deno/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const builders = Object.entries({
update(first, rest, parameters, types, options) {
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
'=' + handleValue(first[x], parameters, types, options)
'=' + stringifyValue('values', first[x], parameters, types, options)
)
},

Expand Down
59 changes: 31 additions & 28 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ t('Connect using uri', async() =>
})]
)

t('Options from uri with special characters in user and pass', async() => {
const opt = postgres({ user: 'öla', pass: 'pass^word' }).options
return [[opt.user, opt.pass].toString(), 'öla,pass^word']
})

t('Fail with proper error on no host', async() =>
['ECONNREFUSED', (await new Promise((resolve, reject) => {
const sql = postgres('postgres://localhost:33333/' + options.db, {
Expand Down Expand Up @@ -542,7 +547,7 @@ t('Connection end does not cancel query', async() => {

const promise = sql`select 1 as x`.execute()

sql.end()
await sql.end()

return [1, (await promise)[0].x]
})
Expand Down Expand Up @@ -618,39 +623,37 @@ t('Transform deeply nested json object in arrays', async() => {
...options,
transform: postgres.camel
})
return ['childObj_deeplyNestedObj_grandchildObj', (await sql`select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x`)[0].x
.map((x) => {
let result;
for (const key in x) {
const result1 = Object.keys(x[key]);
const result2 = Object.keys(x[key].deeplyNestedObj);

result = [...result1, ...result2];
}

return result;
})[0]
.join('_')]
return [
'childObj_deeplyNestedObj_grandchildObj',
(await sql`
select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x
`)[0].x.map(x => {
let result
for (const key in x)
result = [...Object.keys(x[key]), ...Object.keys(x[key].deeplyNestedObj)]
return result
})[0]
.join('_')
]
})

t('Transform deeply nested json array in arrays', async() => {
const sql = postgres({
...options,
transform: postgres.camel
})
return ['childArray_deeplyNestedArray_grandchildArray', (await sql`select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x`)[0].x
.map((x) => {
let result;
for (const key in x) {
const result1 = Object.keys(x[key][0]);
const result2 = Object.keys(x[key][0].deeplyNestedArray[0]);

result = [...result1, ...result2];
}

return result;
})[0]
.join('_')]
return [
'childArray_deeplyNestedArray_grandchildArray',
(await sql`
select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x
`)[0].x.map((x) => {
let result
for (const key in x)
result = [...Object.keys(x[key][0]), ...Object.keys(x[key][0].deeplyNestedArray[0])]
return result
})[0]
.join('_')
]
})

t('Bypass transform for json primitive', async() => {
Expand Down Expand Up @@ -1632,7 +1635,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
err = e.message
})
server.close()
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
})

t('requests works after single connect_timeout', async() => {
Expand Down
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const builders = Object.entries({
update(first, rest, parameters, types, options) {
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
'=' + handleValue(first[x], parameters, types, options)
'=' + stringifyValue('values', first[x], parameters, types, options)
)
},

Expand Down
54 changes: 26 additions & 28 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ t('Connection end does not cancel query', async() => {

const promise = sql`select 1 as x`.execute()

sql.end()
await sql.end()

return [1, (await promise)[0].x]
})
Expand Down Expand Up @@ -621,39 +621,37 @@ t('Transform deeply nested json object in arrays', async() => {
...options,
transform: postgres.camel
})
return ['childObj_deeplyNestedObj_grandchildObj', (await sql`select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x`)[0].x
.map((x) => {
let result;
for (const key in x) {
const result1 = Object.keys(x[key]);
const result2 = Object.keys(x[key].deeplyNestedObj);

result = [...result1, ...result2];
}

return result;
})[0]
.join('_')]
return [
'childObj_deeplyNestedObj_grandchildObj',
(await sql`
select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x
`)[0].x.map(x => {
let result
for (const key in x)
result = [...Object.keys(x[key]), ...Object.keys(x[key].deeplyNestedObj)]
return result
})[0]
.join('_')
]
})

t('Transform deeply nested json array in arrays', async() => {
const sql = postgres({
...options,
transform: postgres.camel
})
return ['childArray_deeplyNestedArray_grandchildArray', (await sql`select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x`)[0].x
.map((x) => {
let result;
for (const key in x) {
const result1 = Object.keys(x[key][0]);
const result2 = Object.keys(x[key][0].deeplyNestedArray[0]);

result = [...result1, ...result2];
}

return result;
})[0]
.join('_')]
return [
'childArray_deeplyNestedArray_grandchildArray',
(await sql`
select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x
`)[0].x.map((x) => {
let result
for (const key in x)
result = [...Object.keys(x[key][0]), ...Object.keys(x[key][0].deeplyNestedArray[0])]
return result
})[0]
.join('_')
]
})

t('Bypass transform for json primitive', async() => {
Expand Down Expand Up @@ -1635,7 +1633,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
err = e.message
})
server.close()
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
})

t('requests works after single connect_timeout', async() => {
Expand Down

0 comments on commit 7ac131e

Please sign in to comment.