-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-query.coffee
27 lines (27 loc) · 1 KB
/
parse-query.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(module or {}).exports = @SQL =
select : (fields, table, whereC) ->
fields = fields?.split(",") or fields
@selector = (data) =>
res=data.results or data
(d[f] for f in fields for d in res)
@done = (data) =>
if ("string" is typeof data) then data = JSON.parse(data) or data
@data = data
console?.info 'Got ' + (data?.results?.length)
@selector(data)
if table
@from(table,whereC)
else
this
from : (table,whereC) ->
(cb) =>
if require?
wrapcb = (err,req,data) => cb(err,@done(data))
parse ?= require('./node/node-parse').init(require('./init'))
parse.get(table, whereC, wrapcb)
else if jQuery?
wrapcb = (data) => cb(@done(data))
$.parse.get(table, whereC, wrapcb)
else
console?.warn "requires jQuery.parse or node-parse"
this