You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
922 B
JavaScript
28 lines
922 B
JavaScript
"use strict";
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
const required = require("@validatem/required");
|
|
|
|
const node = require("../ast-node");
|
|
|
|
module.exports = function count(operations) {
|
|
const isTable = require("../validators/operations/is-table")(operations);
|
|
|
|
return function count(_table) {
|
|
let [ table ] = validateArguments(arguments, {
|
|
table: [ isTable ]
|
|
});
|
|
|
|
// TODO: Investigate whether this can be made more performant by counting a specific column rather than *. That would probably require stateful knowledge of the database schema, though.
|
|
let columnReference = (table != null)
|
|
? operations.foreignColumn({ table: table, column: "*" }) // FIXME: Make sure not to break this (internally) when making column name checks more strict
|
|
: operations.column("*");
|
|
|
|
return node({
|
|
type: "aggregrateFunction",
|
|
functionName: "count",
|
|
args: [ columnReference ]
|
|
});
|
|
};
|
|
};
|