Table of contents
  1. One Clause
  2. Two Clauses
    1. One call
    2. Two calls
import { table, dsql as sql, SafeString } from "../../src";

We will use this table

CREATE TABLE users(id int, age int, name string);

Which is defined in typescript as

const users = table(["id", "age", "name"], "users");

const lowercase = (it: SafeString): SafeString => sql`lowerCase(${it})`;

One Clause

users
    .selectStar()
    .groupBy((f) => lowercase(f.name))
    .stringify();
SELECT
  *
FROM
  `users`
GROUP BY
  lowerCase(`name`)
users.selectStar().groupBy(["name"]).stringify();
SELECT
  *
FROM
  `users`
GROUP BY
  `name`

Two Clauses

One call

users
    .selectStar()
    .groupBy((f) => [f.name, f.id])
    .stringify();
SELECT
  *
FROM
  `users`
GROUP BY
  `name`,
  `id`
users.selectStar().groupBy(["name", "id"]).stringify();
SELECT
  *
FROM
  `users`
GROUP BY
  `name`,
  `id`

Two calls

users
    .selectStar()
    .groupBy((f) => f.name)
    .groupBy((f) => f.id)
    .stringify();
SELECT
  *
FROM
  `users`
GROUP BY
  `name`,
  `id`
users.selectStar().groupBy(["name"]).groupBy(["id"]).stringify();
SELECT
  *
FROM
  `users`
GROUP BY
  `name`,
  `id`

This document used eval-md