forked from CartoDB/cdb-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
records.js
43 lines (33 loc) · 981 Bytes
/
records.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
api.factory('Record', ["SQLClient", function (SQLClient) {
return function (recordFromDB) {
angular.extend(this, recordFromDB);
this.api = new SQLClient();
};
}]);
cdbmanager.service("records", ["SQLClient", "Record", function (SQLClient, Record) {
let self = this;
this.api = new SQLClient();
this.get = function (table, limit, offset, action, error, extraQuery) {
let _action = function () {
if (self.api && self.api.items) {
for (let i = 0; i < self.api.items.length; i++) {
self.api.items[i] = new Record(self.api.items[i], self);
}
if (action) {
action();
}
}
};
let query = "select *, count (*) over () as total_rows from " + table.relname;
if (extraQuery) {
query += " " + extraQuery;
}
if (limit) {
query += " limit " + limit;
}
if (offset) {
query += " offset " + offset;
}
self.api.send(query, _action, error);
};
}]);