doix-db 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/query/DbQuery.js +29 -0
- package/package.json +1 -1
package/lib/query/DbQuery.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const DbQueryTable = require ('./DbQueryTable.js')
|
|
2
|
+
const DbQueryColumn = require ('./DbQueryColumn.js')
|
|
2
3
|
|
|
3
4
|
class DbQuery {
|
|
4
5
|
|
|
@@ -39,6 +40,34 @@ class DbQuery {
|
|
|
39
40
|
return this.lang.toParamsSql (this)
|
|
40
41
|
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
toQueryCount () {
|
|
45
|
+
|
|
46
|
+
const q = new DbQuery (this.model)
|
|
47
|
+
|
|
48
|
+
new DbQueryColumn (q, 'COUNT(*)', 'cnt')
|
|
49
|
+
|
|
50
|
+
for (const table of this.tables) {
|
|
51
|
+
|
|
52
|
+
if (table.join === 'LEFT') continue
|
|
53
|
+
|
|
54
|
+
const o = {columns: [], as: table.alias}
|
|
55
|
+
|
|
56
|
+
if (!table.isFirst) {
|
|
57
|
+
|
|
58
|
+
o.join = table.join
|
|
59
|
+
|
|
60
|
+
if (table.on) o.on = table.on
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
q.addTable (table.relation ? table.relation.name : table.expr, o)
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return q
|
|
69
|
+
|
|
70
|
+
}
|
|
42
71
|
|
|
43
72
|
}
|
|
44
73
|
|