@cocalc/database
Version:
CoCalc: code for working with our PostgreSQL database
47 lines • 1.45 kB
JavaScript
"use strict";
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = void 0;
// Nice async/await interface to doing basic queries.
const awaiting_1 = require("awaiting");
const { one_result, all_results } = require("../postgres-base");
async function query(opts) {
return await (0, awaiting_1.callback)(opts.one ? one_query : all_query, opts.db, opts.select, opts.table, opts.where, opts.set, opts.query, opts.jsonb_set, opts.jsonb_merge, opts.order_by, opts.limit, opts.params, opts.timeout_s);
}
exports.query = query;
function all_query(db, select, table, where, set, query, jsonb_set, jsonb_merge, order_by, limit, params, timeout_s, cb) {
db._query({
select,
table,
where,
set,
query,
jsonb_set,
jsonb_merge,
order_by,
limit,
params,
timeout_s,
cb: all_results(cb),
});
}
function one_query(db, select, table, where, set, query, jsonb_set, jsonb_merge, order_by, limit, params, timeout_s, cb) {
db._query({
select,
table,
where,
set,
query,
jsonb_set,
jsonb_merge,
order_by,
limit,
params,
timeout_s,
cb: one_result(cb),
});
}
//# sourceMappingURL=query.js.map