CREATE TABLE test
(
id SERIAL PRIMARY KEY NOT NULL,
comment text
);
INSERT INTO test(comment)
VALUES ('abc'), ('def');
CREATE OR REPLACE FUNCTION get_count(table_name text)
RETURNS jsonb
LANGUAGE plv8 IMMUTABLE AS
$$
const sql = `SELECT COUNT(*) AS cnt FROM "${table_name}"`;
const data = plv8.execute(sql);
return data[0];
$$;
SELECT * FROM get_count('test');