container.js | |
/* Crypton Server, Copyright 2013 SpiderOak, Inc.
*
* This file is part of Crypton Server.
*
* Crypton Server is free software: you can redistribute it and/or modify it
* under the terms of the Affero GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Crypton Server is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Affero GNU General Public
* License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* along with Crypton Server. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
var datastore = require('./');
var connect = datastore.connect; | |
¶ getContainerRecords(containerNameHmac, callback)Retrieve all records for given Calls back with array of records and without error if successful Calls back with error if unsuccessful Params containerNameHmacString callbackFunction | exports.getContainerRecords = function (containerNameHmac, callback) {
connect(function (client, done) {
var query = {
// TODO limit to to_account_id
/*jslint multistr: true*/
text: '\
select * from readable_container_records_by_account \
where container_id=( \
select container_id from container where name_hmac=$1 \
) order by container_record_id',
/*jslint multistr: false*/
values: [
containerNameHmac
]
};
client.query(query, function (err, result) {
done();
if (err) {
callback(err);
return;
}
// massage
var records = [];
result.rows.forEach(function (row) {
Object.keys(row).forEach(function (key) {
if (Buffer.isBuffer(row[key])) {
row[key] = row[key].toString();
}
});
row = datastore.util.camelizeObject(row);
records.push(row);
});
callback(null, records);
});
});
};
|