-
Notifications
You must be signed in to change notification settings - Fork 4
/
store-query.js
53 lines (42 loc) · 1.16 KB
/
store-query.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict'
var _ = require('lodash')
var actionRole = 'sql'
var name = 'store-query'
module.exports = function queryBuilder (options) {
var seneca = this
function specificTypes (storeName) {
var sTypes = {
escape: '"',
prepared: '$'
}
sTypes.name = storeName
if (storeName === 'mysql-store') {
sTypes.escape = '`'
sTypes.prepared = '?'
}
return sTypes
}
seneca.ready(function () {
var QueryBuilder = require('./lib/query-builder')(seneca, options)
seneca.add({role: actionRole, hook: 'load'}, function (args, done) {
var qent = args.qent
var sTypes = specificTypes(args.target)
var q = _.clone(args.q)
q.limit$ = 1
QueryBuilder.selectstm(qent, q, sTypes, function (err, query) {
return done(err, {query: query})
})
})
seneca.add({role: actionRole, hook: 'list'}, function (args, done) {
var qent = args.qent
var q = args.q
var sTypes = specificTypes(args.target)
QueryBuilder.buildSelectStatement(qent, q, sTypes, function (err, query) {
return done(err, {query: query})
})
})
})
return {
name: name
}
}