mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-21 03:55:51 +08:00
Rename formatResult, don't assume it's an array
This commit is contained in:
parent
6b144b867d
commit
d842428880
4 changed files with 8 additions and 7 deletions
|
@ -101,7 +101,7 @@ describe "ModelQuery", ->
|
|||
q.where({accountId: 'abcd'}).count()
|
||||
|
||||
raw = [{count:"12"}]
|
||||
expect(q.formatResultObjects(q.inflateResult(raw))).toBe(12)
|
||||
expect(q.formatResult(q.inflateResult(raw))).toBe(12)
|
||||
|
||||
describe "sql", ->
|
||||
beforeEach ->
|
||||
|
|
|
@ -178,7 +178,7 @@ class QuerySubscription
|
|||
if @_options.asResultSet
|
||||
@_lastResult = @_set.immutableClone()
|
||||
else
|
||||
@_lastResult = @_query.formatResultObjects(@_set.models())
|
||||
@_lastResult = @_query.formatResult(@_set.models())
|
||||
|
||||
@_callbacks.forEach (callback) =>
|
||||
callback(@_lastResult)
|
||||
|
|
|
@ -231,9 +231,10 @@ class ModelQuery
|
|||
throw new Error("Query could not parse the database result. Query: #{@sql()}, Error: #{jsonError.toString()}")
|
||||
return objects
|
||||
|
||||
formatResultObjects: (objects) ->
|
||||
return objects[0] if @_returnOne
|
||||
return [].concat(objects)
|
||||
formatResult: (inflated) ->
|
||||
return inflated[0] if @_returnOne
|
||||
return inflated if @_count
|
||||
return [].concat(inflated)
|
||||
|
||||
# Query SQL Building
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ COMMIT = 'COMMIT'
|
|||
TXINDEX = 0
|
||||
|
||||
class JSONBlobQuery extends ModelQuery
|
||||
formatResultObjects: (objects) =>
|
||||
formatResult: (objects) =>
|
||||
return objects[0]?.json || null
|
||||
|
||||
|
||||
|
@ -402,7 +402,7 @@ class DatabaseStore extends NylasStore
|
|||
run: (modelQuery, options = {format: true}) =>
|
||||
@_query(modelQuery.sql(), []).then (result) =>
|
||||
result = modelQuery.inflateResult(result)
|
||||
result = modelQuery.formatResultObjects(result) unless options.format is false
|
||||
result = modelQuery.formatResult(result) unless options.format is false
|
||||
Promise.resolve(result)
|
||||
|
||||
findJSONBlob: (id) ->
|
||||
|
|
Loading…
Add table
Reference in a new issue