[LIQ] Extend with group by and having with aggregators (#1843)
* [LIQ] Extend with `group by` and `having` support Also update documentation with extensive examples and add some parser tests. Note: `make generate` JS files included. Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Merge `liq-add-support-for-aggregators` branch Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Fix link, remove `_` example Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Wrap example LIQ queries inside `query [[ .. ]]` and replace `sql` code block type to `lua` Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Example self-consistency fix Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Fixed some queries * Add experimental tags to LIQ aggregation/grouping --------- Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> Co-authored-by: Zef Hemel <zef@zef.me>
This commit is contained in:
co-authored by
Zef Hemel
parent
f4bd2c3abc
commit
13c61ebab7
@@ -19,7 +19,7 @@ import {
|
||||
import { strPackFn, strPackSizeFn, strUnpackFn } from "./string_pack.ts";
|
||||
|
||||
function capturesToLua(caps: CaptureResult[]): any {
|
||||
if (caps.length === 0) {return null;}
|
||||
if (caps.length === 0) return null;
|
||||
if (caps.length === 1) {
|
||||
const c = caps[0];
|
||||
return "s" in c ? c.s : c.position;
|
||||
@@ -33,8 +33,8 @@ export const stringApi = new LuaTable({
|
||||
byte: new LuaBuiltinFunction((_sf, s: string, i?: number, j?: number) => {
|
||||
i = i ?? 1;
|
||||
j = j ?? i;
|
||||
if (j > s.length) {j = s.length;}
|
||||
if (i < 1) {i = 1;}
|
||||
if (j > s.length) j = s.length;
|
||||
if (i < 1) i = 1;
|
||||
const result = [];
|
||||
for (let k = i; k <= j; k++) {
|
||||
result.push(s.charCodeAt(k - 1));
|
||||
@@ -47,7 +47,7 @@ export const stringApi = new LuaTable({
|
||||
find: new LuaBuiltinFunction(
|
||||
(_sf, s: string, pattern: string, init = 1, plain = false) => {
|
||||
const r = patternFind(s, pattern, init, plain);
|
||||
if (!r) {return null;}
|
||||
if (!r) return null;
|
||||
const result: any[] = [r.start, r.end];
|
||||
for (const c of r.captures) {
|
||||
result.push("s" in c ? c.s : c.position);
|
||||
@@ -66,7 +66,7 @@ export const stringApi = new LuaTable({
|
||||
const iter = patternGmatch(s, pattern, init);
|
||||
return () => {
|
||||
const caps = iter();
|
||||
if (!caps) {return;}
|
||||
if (!caps) return;
|
||||
return capturesToLua(caps);
|
||||
};
|
||||
},
|
||||
@@ -85,7 +85,7 @@ export const stringApi = new LuaTable({
|
||||
} else if (repl instanceof LuaTable) {
|
||||
callbacks.replTable = (key: string) => {
|
||||
const v = repl.get(key);
|
||||
if (v === null || v === undefined || v === false) {return null;}
|
||||
if (v === null || v === undefined || v === false) return null;
|
||||
return String(v);
|
||||
};
|
||||
} else if (repl.call) {
|
||||
@@ -122,12 +122,12 @@ export const stringApi = new LuaTable({
|
||||
match: new LuaBuiltinFunction(
|
||||
(_sf, s: string, pattern: string, init = 1) => {
|
||||
const caps = patternMatch(s, pattern, init);
|
||||
if (!caps) {return null;}
|
||||
if (!caps) return null;
|
||||
return capturesToLua(caps);
|
||||
},
|
||||
),
|
||||
rep: new LuaBuiltinFunction((_sf, s: string, n: number, sep?: string) => {
|
||||
if (n <= 0) {return "";}
|
||||
if (n <= 0) return "";
|
||||
sep = sep ?? "";
|
||||
const parts: string[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
|
||||
Reference in New Issue
Block a user