Skip to content

Commit 9e39f8c

Browse files
author
Josh Vanderwillik
committed
Fix bug that caused out of order keys to fail
1 parent cfa28cc commit 9e39f8c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,13 @@ class MysqlData {
103103
}
104104

105105
put (data) {
106-
var keys = []
107-
var values = []
108-
Object.keys(data).forEach(key => {
109-
keys.push(key)
110-
values.push(data[key])
111-
})
112-
113106
return this._connection().then(conn => {
114-
return conn.queryAsync(this.INSERT_RECORD_SQL, values).then(() => {
107+
return conn.queryAsync(this.INSERT_RECORD_SQL, [
108+
data.id || null,
109+
data.name || null,
110+
data.size || null,
111+
data.mimeType || null
112+
]).then(() => {
115113
conn.end()
116114
})
117115
})

test/test-lib.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('MysqlData', function(){
99
var record = {
1010
id: TEST_KEY,
1111
name: 'cats.png',
12-
size: 4444,
13-
mimeType: 'image/png'
12+
mimeType: 'image/png',
13+
size: 4444
1414
}
1515

1616
var db = makeDb()
@@ -44,7 +44,7 @@ describe('MysqlData', function(){
4444
it('should getAll() successfully', () => {
4545
return plugin.getAll().then(fetched => {
4646
assert(Array.isArray(fetched), 'Returned data is not in array form')
47-
assert(typeof fetched[0] !== 'object', 'Returned records are objects')
47+
assert.equal(typeof fetched[0], 'object')
4848
})
4949
})
5050

0 commit comments

Comments
 (0)