Skip to content

Commit

Permalink
fix #30 by conditionally collapsing arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Dec 12, 2019
1 parent 333e236 commit 45a0954
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
21 changes: 5 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ const pick = (obj,values) => Object.keys(obj).reduce((acc,x) =>
values.includes(x) ? Object.assign(acc,{ [x]: obj[x] }) : acc
,{})

// Utility function for flattening arrays - deprecated
// const flatten = arr => arr.reduce((acc,x) => acc.concat(x),[])
// Utility function for flattening arrays
const flatten = arr => arr.reduce((acc,x) => acc.concat(x),[])

// Normize parameters so that they are all in standard format
const normalizeParams = params => params.reduce((acc,p) =>
Expand All @@ -112,15 +112,6 @@ const normalizeParams = params => params.reduce((acc,p) =>
: acc.concat(splitParams(p))
,[]) // end reduce

// // Annotate parameters with correct types
// const annotateParams = params => params.reduce((acc,p) =>
// Array.isArray(p) ? acc.concat([annotateParams(p)])
// : Object.keys(p).length === 2 && p.name && p.value ? acc.concat(p)
// : acc.concat(
// formatParam(Object.keys(p)[0],Object.values(p)[0])
// )
// ,[]) // end reduce


// Prepare parameters
const processParams = (sql,sqlParams,params,row=0) => {
Expand Down Expand Up @@ -294,10 +285,10 @@ const mergeConfig = (initialConfig,args) =>
/********************************************************************/

// Query function (use standard form for `this` context)
const query = async function(config,...args) {
const query = async function(config,..._args) {

// Deprecated this since it was collapsing batches
// const args = flatten(_args)
// Flatten array if nested arrays (fixes #30)
const args = Array.isArray(_args[0]) ? flatten(_args) : _args

// Parse and process sql
const sql = parseSQL(args)
Expand Down Expand Up @@ -339,8 +330,6 @@ const query = async function(config,...args) {
let result = await (isBatch ? config.RDS.batchExecuteStatement(params).promise()
: config.RDS.executeStatement(params).promise())

// FOR DEBUGGING: console.log(JSON.stringify(result,null,2))

// Format and return the results
return formatResults(
result,
Expand Down
11 changes: 5 additions & 6 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ describe('utility', () => {
expect(result).toEqual({ a: 1, c: 3 })
})

// Deprecated
// test('flatten', async () => {
// const flatten = dataApiClient.__get__('flatten')
// let result = flatten([[1,2,3],4,[5,6],7,8])
// expect(result).toEqual([1,2,3,4,5,6,7,8])
// })
test('flatten', async () => {
const flatten = dataApiClient.__get__('flatten')
let result = flatten([[1,2,3],4,[5,6],7,8])
expect(result).toEqual([1,2,3,4,5,6,7,8])
})

}) // end utility

Expand Down

0 comments on commit 45a0954

Please sign in to comment.