Table of contents
  1. One Clause
    1. From Select
  2. Two Clauses
    1. In two calls
    2. In one call
import { table } from "../../src";

We will use this table

CREATE TABLE t0(x INTEGER, y INTEGER)

Which is defined in typescript as

const t0 = table(["x", "y"], "t0");

One Clause

t0.selectStar()
    .groupBy((f) => f.x)
    .having((f) => f.x)
    .stringify();
SELECT
  *
FROM
  `t0`
GROUP BY
  `x`
HAVING
  `x`

From Select

t0.select((f) => ({ it: f.x }))
    .groupBy((f) => f.y)
    .having((f) => f.y)
    .stringify();
SELECT
  `x` AS `it`
FROM
  `t0`
GROUP BY
  `y`
HAVING
  `y`

Two Clauses

In two calls

t0.selectStar()
    .groupBy((f) => f.x)
    .having((f) => f.x)
    .groupBy((f) => f.y)
    .having((f) => f.y)
    .stringify();
SELECT
  *
FROM
  `t0`
GROUP BY
  `x`,
  `y`
HAVING
  `x`
  AND `y`
t0.selectStar()
    .groupBy(["x"])
    .having(["x"])
    .groupBy(["y"])
    .having(["y"])
    .stringify();
SELECT
  *
FROM
  `t0`
GROUP BY
  `x`,
  `y`
HAVING
  `x`
  AND `y`

In one call

t0.selectStar()
    .groupBy((f) => [f.x, f.y])
    .having((f) => [f.x, f.y])
    .stringify();
SELECT
  *
FROM
  `t0`
GROUP BY
  `x`,
  `y`
HAVING
  `x`
  AND `y`
t0.selectStar().groupBy(["x", "y"]).having(["x", "y"]).stringify();
SELECT
  *
FROM
  `t0`
GROUP BY
  `x`,
  `y`
HAVING
  `x`
  AND `y`

This document used eval-md