@dmgt/google-ad-manager-api
Version:
Typed Google Ad Manager API
30 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pql = pql;
const Object_1 = require("../lang/Object");
const is_1 = require("./condition/is");
const condition_1 = require("./condition/condition");
function pql({ limit, offset, orderBy, where: conditions, }) {
const pqlParts = [];
if (conditions) {
pqlParts.push(`WHERE ${Array.isArray(conditions)
? `(${conditions.map(where).join(') OR (')})`
: where(conditions)}`);
}
if (orderBy) {
pqlParts.push(`ORDER BY ${orderBy.format()}`);
}
if (limit) {
pqlParts.push(`LIMIT ${limit}`);
}
if (offset) {
pqlParts.push(`OFFSET ${offset}`);
}
return pqlParts.join(' ');
function where(condition) {
return (0, Object_1.requiredEntries)(condition)
.map(([key, condition]) => (condition instanceof condition_1.Condition ? condition : (0, is_1.Is)(condition)).format(key.toString()))
.join(' AND ');
}
}
//# sourceMappingURL=pql.js.map