Drizzle → Lingua Tungga

41 cases, 41 features, 0 failing. Every value below comes from a real run — lt test --usage on TypeScript, Python, and Go — compared with drizzle-orm@0.44.4. The compiler is pinned to Lingua Tungga v0.6.0.

41 cases 41 features 3 dialects 3 host languages all green
01

Common table expression

cte·cte

with "active" as (...) select ...

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import sql_core { Sql } "./sql_core.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_cte {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    let inner = select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.eq(schema.col(tb, "name"), expr.str("a")))
    let named = select.with_cte(select.create(), "active", inner)
    select.fields(select.from(named, schema.plain("active", [pg_core.integer("id")])), [expr.raw_sql(sql_core.identifier("id"))])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m0 from "./case_cte";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m0.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m0.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m0.q())));
  }
}

main();
stdout · pass
with "active" as (select "id" from "users" where "users"."name" = $1) select "id" from "active"	text:a
with `active` as (select `id` from `users` where `users`.`name` = ?) select `id` from `active`	text:a
with "active" as (select "id" from "users" where "users"."name" = ?) select "id" from "active"	text:a
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.case_cte as m0
import gen.dialect as m4
import gen.support as m6
import gen.select as m8

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m0.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m0.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m0.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
with "active" as (select "id" from "users" where "users"."name" = $1) select "id" from "active"	text:a
with `active` as (select `id` from `users` where `users`.`name` = ?) select `id` from `active`	text:a
with "active" as (select "id" from "users" where "users"."name" = ?) select "id" from "active"	text:a
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_cte"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
with "active" as (select "id" from "users" where "users"."name" = $1) select "id" from "active"	text:a
with `active` as (select `id` from `users` where `users`.`name` = ?) select `id` from `active`	text:a
with "active" as (select "id" from "users" where "users"."name" = ?) select "id" from "active"	text:a
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
with "active" as (select "id" from "users" where "users"."name" = $1) select "id" from "active"	text:a
with "active" as (select "id" from "users" where "users"."name" = $1) select "id" from "active"	text:a
match
mysql
with `active` as (select `id` from `users` where `users`.`name` = ?) select `id` from `active`	text:a
with `active` as (select `id` from `users` where `users`.`name` = ?) select `id` from `active`	text:a
match
sqlite
with "active" as (select "id" from "users" where "users"."name" = ?) select "id" from "active"	text:a
with "active" as (select "id" from "users" where "users"."name" = ?) select "id" from "active"	text:a
match
02

DELETE with WHERE

delete·delete_row

delete from ... where ...

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"
import delete "./delete.lt"

package case_delete_row {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q(d: Dialect) -> Str {
    let tb = t()
    support.render_built(delete.build(delete.set_dialect(delete.where(delete.create(tb), expr.eq(schema.col(tb, "id"), expr.int(1))), d)))
  }

  test "postgres" {
    expect.not_equal(q(dialect.postgres()), "")
  }
  test "mysql" {
    expect.not_equal(q(dialect.mysql()), "")
  }
  test "sqlite" {
    expect.not_equal(q(dialect.sqlite()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m9 from "./case_delete_row";

function main(): void {
  {
    lt.print(m9.q(m4.postgres()));
  }
  {
    lt.print(m9.q(m4.mysql()));
  }
  {
    lt.print(m9.q(m4.sqlite()));
  }
}

main();
stdout · pass
delete from "users" where "users"."id" = $1	int:1
delete from `users` where `users`.`id` = ?	int:1
delete from "users" where "users"."id" = ?	int:1
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_delete_row as m9

def _usage0() -> None:
    _lt.print_value(m9.q(m4.postgres()))

def _usage1() -> None:
    _lt.print_value(m9.q(m4.mysql()))

def _usage2() -> None:
    _lt.print_value(m9.q(m4.sqlite()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
delete from "users" where "users"."id" = $1	int:1
delete from `users` where `users`.`id` = ?	int:1
delete from "users" where "users"."id" = ?	int:1
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_delete_row"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Postgres()))
	}()

	func() {
		lt.Print(Q(m4.Mysql()))
	}()

	func() {
		lt.Print(Q(m4.Sqlite()))
	}()

}
stdout · pass
delete from "users" where "users"."id" = $1	int:1
delete from `users` where `users`.`id` = ?	int:1
delete from "users" where "users"."id" = ?	int:1
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
delete from "users" where "users"."id" = $1	int:1
delete from "users" where "users"."id" = $1	int:1
match
mysql
delete from `users` where `users`.`id` = ?	int:1
delete from `users` where `users`.`id` = ?	int:1
match
sqlite
delete from "users" where "users"."id" = ?	int:1
delete from "users" where "users"."id" = ?	int:1
match
03

ON CONFLICT

insert/conflict·insert_conflict

do nothing / do update.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"
import insert "./insert.lt"

package case_insert_conflict {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q(d: Dialect) -> Str {
    let tb = t()
    support.render_built(insert.build(insert.set_dialect(insert.on_conflict_do_nothing(insert.values(insert.create(tb), [schema.assign("name", expr.str("a"))])), d)))
  }

  test "postgres" {
    expect.not_equal(q(dialect.postgres()), "")
  }
  test "sqlite" {
    expect.not_equal(q(dialect.sqlite()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m11 from "./case_insert_conflict";

function main(): void {
  {
    lt.print(m11.q(m4.postgres()));
  }
  {
    lt.print(m11.q(m4.sqlite()));
  }
}

main();
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default) on conflict do nothing	text:a
insert into "users" ("id", "name", "age") values (null, ?, null) on conflict do nothing	text:a
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_insert_conflict as m11

def _usage0() -> None:
    _lt.print_value(m11.q(m4.postgres()))

def _usage1() -> None:
    _lt.print_value(m11.q(m4.sqlite()))

def main() -> None:
    _usage0()
    _usage1()

if __name__ == "__main__":
    main()
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default) on conflict do nothing	text:a
insert into "users" ("id", "name", "age") values (null, ?, null) on conflict do nothing	text:a
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_insert_conflict"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Postgres()))
	}()

	func() {
		lt.Print(Q(m4.Sqlite()))
	}()

}
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default) on conflict do nothing	text:a
insert into "users" ("id", "name", "age") values (null, ?, null) on conflict do nothing	text:a
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
insert into "users" ("id", "name", "age") values (default, $1, default) on conflict do nothing	text:a
insert into "users" ("id", "name", "age") values (default, $1, default) on conflict do nothing	text:a
match
sqlite
insert into "users" ("id", "name", "age") values (null, ?, null) on conflict do nothing	text:a
insert into "users" ("id", "name", "age") values (null, ?, null) on conflict do nothing	text:a
match
04

ON DUPLICATE KEY UPDATE

insert/duplicate·insert_duplicate

MySQL has no ON CONFLICT.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"
import insert "./insert.lt"

package case_insert_duplicate {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q(d: Dialect) -> Str {
    let tb = t()
    support.render_built(insert.build(insert.set_dialect(insert.on_duplicate_key_update(insert.values(insert.create(tb), [schema.assign("name", expr.str("a"))]), [schema.assign("name", expr.str("b"))]), d)))
  }

  test "mysql" {
    expect.not_equal(q(dialect.mysql()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m13 from "./case_insert_duplicate";

function main(): void {
  {
    lt.print(m13.q(m4.mysql()));
  }
}

main();
stdout · pass
insert into `users` (`id`, `name`, `age`) values (default, ?, default) on duplicate key update `name` = ?	text:a,text:b
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_insert_duplicate as m13

def _usage0() -> None:
    _lt.print_value(m13.q(m4.mysql()))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
insert into `users` (`id`, `name`, `age`) values (default, ?, default) on duplicate key update `name` = ?	text:a,text:b
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_insert_duplicate"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Mysql()))
	}()

}
stdout · pass
insert into `users` (`id`, `name`, `age`) values (default, ?, default) on duplicate key update `name` = ?	text:a,text:b
parity · port vs drizzle 0.44.4
dialectportdrizzle
mysql
insert into `users` (`id`, `name`, `age`) values (default, ?, default) on duplicate key update `name` = ?	text:a,text:b
insert into `users` (`id`, `name`, `age`) values (default, ?, default) on duplicate key update `name` = ?	text:a,text:b
match
05

INSERT ... RETURNING

insert/returning·insert_returning

Drizzle only supports RETURNING on Postgres.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"
import insert "./insert.lt"

package case_insert_returning {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q(d: Dialect) -> Str {
    let tb = t()
    support.render_built(insert.build(insert.set_dialect(insert.returning_all_columns(insert.values(insert.create(tb), [schema.assign("name", expr.str("a"))])), d)))
  }

  test "postgres" {
    expect.not_equal(q(dialect.postgres()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m14 from "./case_insert_returning";

function main(): void {
  {
    lt.print(m14.q(m4.postgres()));
  }
}

main();
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default) returning "id", "name", "age"	text:a
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_insert_returning as m14

def _usage0() -> None:
    _lt.print_value(m14.q(m4.postgres()))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default) returning "id", "name", "age"	text:a
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_insert_returning"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Postgres()))
	}()

}
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default) returning "id", "name", "age"	text:a
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
insert into "users" ("id", "name", "age") values (default, $1, default) returning "id", "name", "age"	text:a
insert into "users" ("id", "name", "age") values (default, $1, default) returning "id", "name", "age"	text:a
match
06

INSERT fills omitted columns

insert/values·insert_values

default (pg/mysql) vs null (sqlite).

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"
import insert "./insert.lt"

package case_insert_values {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q(d: Dialect) -> Str {
    let tb = t()
    support.render_built(insert.build(insert.set_dialect(insert.values(insert.create(tb), [schema.assign("name", expr.str("a"))]), d)))
  }

  test "postgres" {
    expect.not_equal(q(dialect.postgres()), "")
  }
  test "mysql" {
    expect.not_equal(q(dialect.mysql()), "")
  }
  test "sqlite" {
    expect.not_equal(q(dialect.sqlite()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m15 from "./case_insert_values";

function main(): void {
  {
    lt.print(m15.q(m4.postgres()));
  }
  {
    lt.print(m15.q(m4.mysql()));
  }
  {
    lt.print(m15.q(m4.sqlite()));
  }
}

main();
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default)	text:a
insert into `users` (`id`, `name`, `age`) values (default, ?, default)	text:a
insert into "users" ("id", "name", "age") values (null, ?, null)	text:a
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_insert_values as m15

def _usage0() -> None:
    _lt.print_value(m15.q(m4.postgres()))

def _usage1() -> None:
    _lt.print_value(m15.q(m4.mysql()))

def _usage2() -> None:
    _lt.print_value(m15.q(m4.sqlite()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default)	text:a
insert into `users` (`id`, `name`, `age`) values (default, ?, default)	text:a
insert into "users" ("id", "name", "age") values (null, ?, null)	text:a
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_insert_values"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Postgres()))
	}()

	func() {
		lt.Print(Q(m4.Mysql()))
	}()

	func() {
		lt.Print(Q(m4.Sqlite()))
	}()

}
stdout · pass
insert into "users" ("id", "name", "age") values (default, $1, default)	text:a
insert into `users` (`id`, `name`, `age`) values (default, ?, default)	text:a
insert into "users" ("id", "name", "age") values (null, ?, null)	text:a
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
insert into "users" ("id", "name", "age") values (default, $1, default)	text:a
insert into "users" ("id", "name", "age") values (default, $1, default)	text:a
match
mysql
insert into `users` (`id`, `name`, `age`) values (default, ?, default)	text:a
insert into `users` (`id`, `name`, `age`) values (default, ?, default)	text:a
match
sqlite
insert into "users" ("id", "name", "age") values (null, ?, null)	text:a
insert into "users" ("id", "name", "age") values (null, ?, null)	text:a
match
07

UPDATE with RETURNING

update·update_row

SET then WHERE then RETURNING.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"
import update "./update.lt"

package case_update_row {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q(d: Dialect) -> Str {
    let tb = t()
    support.render_built(update.build(update.set_dialect(update.where(update.set(update.create(tb), [schema.assign("name", expr.str("x"))]), expr.eq(schema.col(tb, "id"), expr.int(1))), d)))
  }

  test "postgres" {
    expect.not_equal(q(dialect.postgres()), "")
  }
  test "mysql" {
    expect.not_equal(q(dialect.mysql()), "")
  }
  test "sqlite" {
    expect.not_equal(q(dialect.sqlite()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m16 from "./case_update_row";

function main(): void {
  {
    lt.print(m16.q(m4.postgres()));
  }
  {
    lt.print(m16.q(m4.mysql()));
  }
  {
    lt.print(m16.q(m4.sqlite()));
  }
}

main();
stdout · pass
update "users" set "name" = $1 where "users"."id" = $2	text:x,int:1
update `users` set `name` = ? where `users`.`id` = ?	text:x,int:1
update "users" set "name" = ? where "users"."id" = ?	text:x,int:1
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_update_row as m16

def _usage0() -> None:
    _lt.print_value(m16.q(m4.postgres()))

def _usage1() -> None:
    _lt.print_value(m16.q(m4.mysql()))

def _usage2() -> None:
    _lt.print_value(m16.q(m4.sqlite()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
update "users" set "name" = $1 where "users"."id" = $2	text:x,int:1
update `users` set `name` = ? where `users`.`id` = ?	text:x,int:1
update "users" set "name" = ? where "users"."id" = ?	text:x,int:1
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_update_row"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Postgres()))
	}()

	func() {
		lt.Print(Q(m4.Mysql()))
	}()

	func() {
		lt.Print(Q(m4.Sqlite()))
	}()

}
stdout · pass
update "users" set "name" = $1 where "users"."id" = $2	text:x,int:1
update `users` set `name` = ? where `users`.`id` = ?	text:x,int:1
update "users" set "name" = ? where "users"."id" = ?	text:x,int:1
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
update "users" set "name" = $1 where "users"."id" = $2	text:x,int:1
update "users" set "name" = $1 where "users"."id" = $2	text:x,int:1
match
mysql
update `users` set `name` = ? where `users`.`id` = ?	text:x,int:1
update `users` set `name` = ? where `users`.`id` = ?	text:x,int:1
match
sqlite
update "users" set "name" = ? where "users"."id" = ?	text:x,int:1
update "users" set "name" = ? where "users"."id" = ?	text:x,int:1
match
08

Full join

joins/full·joins_full

Join kind and ON clause must match drizzle.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_joins_full {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.fields(select.full_join(select.from(select.create(), tb), other, expr.eq(schema.col(tb, "id"), schema.col(other, "user_id"))), [schema.field(tb, "id")])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m18 from "./case_joins_full";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m18.q())));
  }
}

main();
stdout · pass
select "users"."id" from "users" full join "posts" on "users"."id" = "posts"."user_id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_joins_full as m18

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m18.q())))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
select "users"."id" from "users" full join "posts" on "users"."id" = "posts"."user_id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_joins_full"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "users"."id" from "users" full join "posts" on "users"."id" = "posts"."user_id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"."id" from "users" full join "posts" on "users"."id" = "posts"."user_id"	
select "users"."id" from "users" full join "posts" on "users"."id" = "posts"."user_id"	
match
09

Inner join

joins/inner·joins_inner

Join kind and ON clause must match drizzle.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_joins_inner {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.fields(select.inner_join(select.from(select.create(), tb), other, expr.eq(schema.col(tb, "id"), schema.col(other, "user_id"))), [schema.field(tb, "id")])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m19 from "./case_joins_inner";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m19.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m19.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m19.q())));
  }
}

main();
stdout · pass
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` inner join `posts` on `users`.`id` = `posts`.`user_id`	
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_joins_inner as m19

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m19.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m19.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m19.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` inner join `posts` on `users`.`id` = `posts`.`user_id`	
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_joins_inner"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` inner join `posts` on `users`.`id` = `posts`.`user_id`	
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
match
mysql
select `users`.`id` from `users` inner join `posts` on `users`.`id` = `posts`.`user_id`	
select `users`.`id` from `users` inner join `posts` on `users`.`id` = `posts`.`user_id`	
match
sqlite
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
select "users"."id" from "users" inner join "posts" on "users"."id" = "posts"."user_id"	
match
10

Left join

joins/left·joins_left

Join kind and ON clause must match drizzle.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_joins_left {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.fields(select.left_join(select.from(select.create(), tb), other, expr.eq(schema.col(tb, "id"), schema.col(other, "user_id"))), [schema.field(tb, "id")])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m20 from "./case_joins_left";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m20.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m20.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m20.q())));
  }
}

main();
stdout · pass
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id`	
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_joins_left as m20

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m20.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m20.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m20.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id`	
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_joins_left"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id`	
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
match
mysql
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id`	
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id`	
match
sqlite
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id"	
match
11

Join with ORDER BY and LIMIT

joins/order-limit·joins_order_limit

Clause order after a join.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_joins_order_limit {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.limit(select.order_by(select.fields(select.left_join(select.from(select.create(), tb), other, expr.eq(schema.col(tb, "id"), schema.col(other, "user_id"))), [schema.field(tb, "id")]), [expr.asc(schema.col(tb, "id"))]), 1)
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m21 from "./case_joins_order_limit";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m21.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m21.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m21.q())));
  }
}

main();
stdout · pass
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit $1	int:1
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id` order by `users`.`id` asc limit ?	int:1
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit ?	int:1
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_joins_order_limit as m21

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m21.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m21.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m21.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit $1	int:1
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id` order by `users`.`id` asc limit ?	int:1
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit ?	int:1
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_joins_order_limit"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit $1	int:1
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id` order by `users`.`id` asc limit ?	int:1
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit ?	int:1
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit $1	int:1
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit $1	int:1
match
mysql
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id` order by `users`.`id` asc limit ?	int:1
select `users`.`id` from `users` left join `posts` on `users`.`id` = `posts`.`user_id` order by `users`.`id` asc limit ?	int:1
match
sqlite
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit ?	int:1
select "users"."id" from "users" left join "posts" on "users"."id" = "posts"."user_id" order by "users"."id" asc limit ?	int:1
match
12

Right join

joins/right·joins_right

Join kind and ON clause must match drizzle.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_joins_right {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.fields(select.right_join(select.from(select.create(), tb), other, expr.eq(schema.col(tb, "id"), schema.col(other, "user_id"))), [schema.field(tb, "id")])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m22 from "./case_joins_right";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m22.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m22.q())));
  }
}

main();
stdout · pass
select "users"."id" from "users" right join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` right join `posts` on `users`.`id` = `posts`.`user_id`	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_joins_right as m22

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m22.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m22.q())))

def main() -> None:
    _usage0()
    _usage1()

if __name__ == "__main__":
    main()
stdout · pass
select "users"."id" from "users" right join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` right join `posts` on `users`.`id` = `posts`.`user_id`	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_joins_right"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "users"."id" from "users" right join "posts" on "users"."id" = "posts"."user_id"	
select `users`.`id` from `users` right join `posts` on `users`.`id` = `posts`.`user_id`	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"."id" from "users" right join "posts" on "users"."id" = "posts"."user_id"	
select "users"."id" from "users" right join "posts" on "users"."id" = "posts"."user_id"	
match
mysql
select `users`.`id` from `users` right join `posts` on `users`.`id` = `posts`.`user_id`	
select `users`.`id` from `users` right join `posts` on `users`.`id` = `posts`.`user_id`	
match
13

BETWEEN and NOT BETWEEN

operators/between·operators_between

between $1 and $2

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_operators_between {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.and([expr.between(schema.col(tb, "age"), expr.int(1), expr.int(10)), expr.not_between(schema.col(tb, "age"), expr.int(1), expr.int(10))]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m23 from "./case_operators_between";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m23.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m23.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m23.q())));
  }
}

main();
stdout · pass
select "id" from "users" where ("users"."age" between $1 and $2 and "users"."age" not between $3 and $4)	int:1,int:10,int:1,int:10
select `id` from `users` where (`users`.`age` between ? and ? and `users`.`age` not between ? and ?)	int:1,int:10,int:1,int:10
select "id" from "users" where ("users"."age" between ? and ? and "users"."age" not between ? and ?)	int:1,int:10,int:1,int:10
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_operators_between as m23

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m23.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m23.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m23.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where ("users"."age" between $1 and $2 and "users"."age" not between $3 and $4)	int:1,int:10,int:1,int:10
select `id` from `users` where (`users`.`age` between ? and ? and `users`.`age` not between ? and ?)	int:1,int:10,int:1,int:10
select "id" from "users" where ("users"."age" between ? and ? and "users"."age" not between ? and ?)	int:1,int:10,int:1,int:10
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_operators_between"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where ("users"."age" between $1 and $2 and "users"."age" not between $3 and $4)	int:1,int:10,int:1,int:10
select `id` from `users` where (`users`.`age` between ? and ? and `users`.`age` not between ? and ?)	int:1,int:10,int:1,int:10
select "id" from "users" where ("users"."age" between ? and ? and "users"."age" not between ? and ?)	int:1,int:10,int:1,int:10
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where ("users"."age" between $1 and $2 and "users"."age" not between $3 and $4)	int:1,int:10,int:1,int:10
select "id" from "users" where ("users"."age" between $1 and $2 and "users"."age" not between $3 and $4)	int:1,int:10,int:1,int:10
match
mysql
select `id` from `users` where (`users`.`age` between ? and ? and `users`.`age` not between ? and ?)	int:1,int:10,int:1,int:10
select `id` from `users` where (`users`.`age` between ? and ? and `users`.`age` not between ? and ?)	int:1,int:10,int:1,int:10
match
sqlite
select "id" from "users" where ("users"."age" between ? and ? and "users"."age" not between ? and ?)	int:1,int:10,int:1,int:10
select "id" from "users" where ("users"."age" between ? and ? and "users"."age" not between ? and ?)	int:1,int:10,int:1,int:10
match
14

Comparison operators

operators/comparison·operators_comparison

<> > >= < <=

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_operators_comparison {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.and([expr.ne(schema.col(tb, "id"), expr.int(1)), expr.gt(schema.col(tb, "age"), expr.int(18)), expr.gte(schema.col(tb, "age"), expr.int(21)), expr.lt(schema.col(tb, "age"), expr.int(65)), expr.lte(schema.col(tb, "age"), expr.int(64))]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m24 from "./case_operators_comparison";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m24.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m24.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m24.q())));
  }
}

main();
stdout · pass
select "id" from "users" where ("users"."id" <> $1 and "users"."age" > $2 and "users"."age" >= $3 and "users"."age" < $4 and "users"."age" <= $5)	int:1,int:18,int:21,int:65,int:64
select `id` from `users` where (`users`.`id` <> ? and `users`.`age` > ? and `users`.`age` >= ? and `users`.`age` < ? and `users`.`age` <= ?)	int:1,int:18,int:21,int:65,int:64
select "id" from "users" where ("users"."id" <> ? and "users"."age" > ? and "users"."age" >= ? and "users"."age" < ? and "users"."age" <= ?)	int:1,int:18,int:21,int:65,int:64
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_operators_comparison as m24

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m24.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m24.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m24.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where ("users"."id" <> $1 and "users"."age" > $2 and "users"."age" >= $3 and "users"."age" < $4 and "users"."age" <= $5)	int:1,int:18,int:21,int:65,int:64
select `id` from `users` where (`users`.`id` <> ? and `users`.`age` > ? and `users`.`age` >= ? and `users`.`age` < ? and `users`.`age` <= ?)	int:1,int:18,int:21,int:65,int:64
select "id" from "users" where ("users"."id" <> ? and "users"."age" > ? and "users"."age" >= ? and "users"."age" < ? and "users"."age" <= ?)	int:1,int:18,int:21,int:65,int:64
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_operators_comparison"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where ("users"."id" <> $1 and "users"."age" > $2 and "users"."age" >= $3 and "users"."age" < $4 and "users"."age" <= $5)	int:1,int:18,int:21,int:65,int:64
select `id` from `users` where (`users`.`id` <> ? and `users`.`age` > ? and `users`.`age` >= ? and `users`.`age` < ? and `users`.`age` <= ?)	int:1,int:18,int:21,int:65,int:64
select "id" from "users" where ("users"."id" <> ? and "users"."age" > ? and "users"."age" >= ? and "users"."age" < ? and "users"."age" <= ?)	int:1,int:18,int:21,int:65,int:64
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where ("users"."id" <> $1 and "users"."age" > $2 and "users"."age" >= $3 and "users"."age" < $4 and "users"."age" <= $5)	int:1,int:18,int:21,int:65,int:64
select "id" from "users" where ("users"."id" <> $1 and "users"."age" > $2 and "users"."age" >= $3 and "users"."age" < $4 and "users"."age" <= $5)	int:1,int:18,int:21,int:65,int:64
match
mysql
select `id` from `users` where (`users`.`id` <> ? and `users`.`age` > ? and `users`.`age` >= ? and `users`.`age` < ? and `users`.`age` <= ?)	int:1,int:18,int:21,int:65,int:64
select `id` from `users` where (`users`.`id` <> ? and `users`.`age` > ? and `users`.`age` >= ? and `users`.`age` < ? and `users`.`age` <= ?)	int:1,int:18,int:21,int:65,int:64
match
sqlite
select "id" from "users" where ("users"."id" <> ? and "users"."age" > ? and "users"."age" >= ? and "users"."age" < ? and "users"."age" <= ?)	int:1,int:18,int:21,int:65,int:64
select "id" from "users" where ("users"."id" <> ? and "users"."age" > ? and "users"."age" >= ? and "users"."age" < ? and "users"."age" <= ?)	int:1,int:18,int:21,int:65,int:64
match
15

LIKE family

operators/like·operators_like

like / not like / ilike / not ilike

pass
source · lingua tungga
import expr "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_operators_like {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }

  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.and([expr.like(schema.col(tb, "name"), expr.str("A%")), expr.not_like(schema.col(tb, "name"), expr.str("B%")), expr.ilike(schema.col(tb, "name"), expr.str("a%")), expr.not_ilike(schema.col(tb, "name"), expr.str("b%"))]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m25 from "./case_operators_like";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m25.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m25.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m25.q())));
  }
}

main();
stdout · pass
select "id" from "users" where ("users"."name" like $1 and "users"."name" not like $2 and "users"."name" ilike $3 and "users"."name" not ilike $4)	text:A%,text:B%,text:a%,text:b%
select `id` from `users` where (`users`.`name` like ? and `users`.`name` not like ? and `users`.`name` ilike ? and `users`.`name` not ilike ?)	text:A%,text:B%,text:a%,text:b%
select "id" from "users" where ("users"."name" like ? and "users"."name" not like ? and "users"."name" ilike ? and "users"."name" not ilike ?)	text:A%,text:B%,text:a%,text:b%
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_operators_like as m25

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m25.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m25.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m25.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where ("users"."name" like $1 and "users"."name" not like $2 and "users"."name" ilike $3 and "users"."name" not ilike $4)	text:A%,text:B%,text:a%,text:b%
select `id` from `users` where (`users`.`name` like ? and `users`.`name` not like ? and `users`.`name` ilike ? and `users`.`name` not ilike ?)	text:A%,text:B%,text:a%,text:b%
select "id" from "users" where ("users"."name" like ? and "users"."name" not like ? and "users"."name" ilike ? and "users"."name" not ilike ?)	text:A%,text:B%,text:a%,text:b%
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_operators_like"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where ("users"."name" like $1 and "users"."name" not like $2 and "users"."name" ilike $3 and "users"."name" not ilike $4)	text:A%,text:B%,text:a%,text:b%
select `id` from `users` where (`users`.`name` like ? and `users`.`name` not like ? and `users`.`name` ilike ? and `users`.`name` not ilike ?)	text:A%,text:B%,text:a%,text:b%
select "id" from "users" where ("users"."name" like ? and "users"."name" not like ? and "users"."name" ilike ? and "users"."name" not ilike ?)	text:A%,text:B%,text:a%,text:b%
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where ("users"."name" like $1 and "users"."name" not like $2 and "users"."name" ilike $3 and "users"."name" not ilike $4)	text:A%,text:B%,text:a%,text:b%
select "id" from "users" where ("users"."name" like $1 and "users"."name" not like $2 and "users"."name" ilike $3 and "users"."name" not ilike $4)	text:A%,text:B%,text:a%,text:b%
match
mysql
select `id` from `users` where (`users`.`name` like ? and `users`.`name` not like ? and `users`.`name` ilike ? and `users`.`name` not ilike ?)	text:A%,text:B%,text:a%,text:b%
select `id` from `users` where (`users`.`name` like ? and `users`.`name` not like ? and `users`.`name` ilike ? and `users`.`name` not ilike ?)	text:A%,text:B%,text:a%,text:b%
match
sqlite
select "id" from "users" where ("users"."name" like ? and "users"."name" not like ? and "users"."name" ilike ? and "users"."name" not ilike ?)	text:A%,text:B%,text:a%,text:b%
select "id" from "users" where ("users"."name" like ? and "users"."name" not like ? and "users"."name" ilike ? and "users"."name" not ilike ?)	text:A%,text:B%,text:a%,text:b%
match
16

IN and NOT IN

operators/list·operators_list

Empty lists become false/true literals.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_operators_list {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.and([expr.in_list(schema.col(tb, "id"), [expr.int(1), expr.int(2)]), expr.not_in_list(schema.col(tb, "id"), [expr.int(3)])]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m26 from "./case_operators_list";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m26.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m26.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m26.q())));
  }
}

main();
stdout · pass
select "id" from "users" where ("users"."id" in ($1, $2) and "users"."id" not in ($3))	int:1,int:2,int:3
select `id` from `users` where (`users`.`id` in (?, ?) and `users`.`id` not in (?))	int:1,int:2,int:3
select "id" from "users" where ("users"."id" in (?, ?) and "users"."id" not in (?))	int:1,int:2,int:3
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_operators_list as m26

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m26.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m26.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m26.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where ("users"."id" in ($1, $2) and "users"."id" not in ($3))	int:1,int:2,int:3
select `id` from `users` where (`users`.`id` in (?, ?) and `users`.`id` not in (?))	int:1,int:2,int:3
select "id" from "users" where ("users"."id" in (?, ?) and "users"."id" not in (?))	int:1,int:2,int:3
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_operators_list"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where ("users"."id" in ($1, $2) and "users"."id" not in ($3))	int:1,int:2,int:3
select `id` from `users` where (`users`.`id` in (?, ?) and `users`.`id` not in (?))	int:1,int:2,int:3
select "id" from "users" where ("users"."id" in (?, ?) and "users"."id" not in (?))	int:1,int:2,int:3
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where ("users"."id" in ($1, $2) and "users"."id" not in ($3))	int:1,int:2,int:3
select "id" from "users" where ("users"."id" in ($1, $2) and "users"."id" not in ($3))	int:1,int:2,int:3
match
mysql
select `id` from `users` where (`users`.`id` in (?, ?) and `users`.`id` not in (?))	int:1,int:2,int:3
select `id` from `users` where (`users`.`id` in (?, ?) and `users`.`id` not in (?))	int:1,int:2,int:3
match
sqlite
select "id" from "users" where ("users"."id" in (?, ?) and "users"."id" not in (?))	int:1,int:2,int:3
select "id" from "users" where ("users"."id" in (?, ?) and "users"."id" not in (?))	int:1,int:2,int:3
match
17

AND / OR / NOT

operators/logical·operators_logical

Parenthesisation must match drizzle.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_operators_logical {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.and([expr.eq(schema.col(tb, "name"), expr.str("a")), expr.or([expr.gt(schema.col(tb, "age"), expr.int(18)), expr.is_null(schema.col(tb, "age"))])]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m27 from "./case_operators_logical";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m27.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m27.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m27.q())));
  }
}

main();
stdout · pass
select "id" from "users" where ("users"."name" = $1 and ("users"."age" > $2 or "users"."age" is null))	text:a,int:18
select `id` from `users` where (`users`.`name` = ? and (`users`.`age` > ? or `users`.`age` is null))	text:a,int:18
select "id" from "users" where ("users"."name" = ? and ("users"."age" > ? or "users"."age" is null))	text:a,int:18
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_operators_logical as m27

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m27.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m27.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m27.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where ("users"."name" = $1 and ("users"."age" > $2 or "users"."age" is null))	text:a,int:18
select `id` from `users` where (`users`.`name` = ? and (`users`.`age` > ? or `users`.`age` is null))	text:a,int:18
select "id" from "users" where ("users"."name" = ? and ("users"."age" > ? or "users"."age" is null))	text:a,int:18
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_operators_logical"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where ("users"."name" = $1 and ("users"."age" > $2 or "users"."age" is null))	text:a,int:18
select `id` from `users` where (`users`.`name` = ? and (`users`.`age` > ? or `users`.`age` is null))	text:a,int:18
select "id" from "users" where ("users"."name" = ? and ("users"."age" > ? or "users"."age" is null))	text:a,int:18
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where ("users"."name" = $1 and ("users"."age" > $2 or "users"."age" is null))	text:a,int:18
select "id" from "users" where ("users"."name" = $1 and ("users"."age" > $2 or "users"."age" is null))	text:a,int:18
match
mysql
select `id` from `users` where (`users`.`name` = ? and (`users`.`age` > ? or `users`.`age` is null))	text:a,int:18
select `id` from `users` where (`users`.`name` = ? and (`users`.`age` > ? or `users`.`age` is null))	text:a,int:18
match
sqlite
select "id" from "users" where ("users"."name" = ? and ("users"."age" > ? or "users"."age" is null))	text:a,int:18
select "id" from "users" where ("users"."name" = ? and ("users"."age" > ? or "users"."age" is null))	text:a,int:18
match
18

IS NULL / IS NOT NULL

operators/null·operators_null

is null stays unparenthesised

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_operators_null {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.and([expr.is_null(schema.col(tb, "age")), expr.is_not_null(schema.col(tb, "name"))]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m28 from "./case_operators_null";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m28.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m28.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m28.q())));
  }
}

main();
stdout · pass
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
select `id` from `users` where (`users`.`age` is null and `users`.`name` is not null)	
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_operators_null as m28

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m28.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m28.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m28.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
select `id` from `users` where (`users`.`age` is null and `users`.`name` is not null)	
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_operators_null"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
select `id` from `users` where (`users`.`age` is null and `users`.`name` is not null)	
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
match
mysql
select `id` from `users` where (`users`.`age` is null and `users`.`name` is not null)	
select `id` from `users` where (`users`.`age` is null and `users`.`name` is not null)	
match
sqlite
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
select "id" from "users" where ("users"."age" is null and "users"."name" is not null)	
match
19

IS DISTINCT FROM from a nullable column

schema/distinct-from·distinct_from

Nullable columns still expose distinct-from predicates; the adapter renders the neutral Expr as IS DISTINCT FROM.

pass
source · lingua tungga
import dialect { Dialect } "./dialect.lt"
import schema_table_users { users } "./generated/schema_table_users.lt"
import select { Select } "./select.lt"
import support "./support.lt"

package case_schema_distinct_from {
  export fn q() -> Select {
    select.where(
      select.fields(select.from(select.create(), users), [users.age]),
      users.age.is_distinct_from(18),
    )
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m29 from "./case_schema_distinct_from";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m29.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m29.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m29.q())));
  }
}

main();
stdout · pass
select "age" from "users" where "users"."age" is distinct from $1	int:18
select `age` from `users` where `users`.`age` is distinct from ?	int:18
select "age" from "users" where "users"."age" is distinct from ?	int:18
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_schema_distinct_from as m29

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m29.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m29.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m29.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "age" from "users" where "users"."age" is distinct from $1	int:18
select `age` from `users` where `users`.`age` is distinct from ?	int:18
select "age" from "users" where "users"."age" is distinct from ?	int:18
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_distinct_from"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "age" from "users" where "users"."age" is distinct from $1	int:18
select `age` from `users` where `users`.`age` is distinct from ?	int:18
select "age" from "users" where "users"."age" is distinct from ?	int:18
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "age" from "users" where "users"."age" is distinct from $1	int:18
select "age" from "users" where "users"."age" is distinct from $1	int:18
match
mysql
select `age` from `users` where `users`.`age` is distinct from ?	int:18
select `age` from `users` where `users`.`age` is distinct from ?	int:18
match
sqlite
select "age" from "users" where "users"."age" is distinct from ?	int:18
select "age" from "users" where "users"."age" is distinct from ?	int:18
match
20

Nullable assignment takes an Option

schema/nullable-insert·nullable_insert

users.age is nullable, so its generated assign takes Option<Int>; Some(18) becomes a bound parameter.

pass
source · lingua tungga
import dialect { Dialect } "./dialect.lt"
import schema_table_users { users } "./generated/schema_table_users.lt"
import insert "./insert.lt"
import support "./support.lt"

package case_schema_nullable_insert {
  export fn q(d: Dialect) -> Str {
    let row = [
      users.age.assign(Some(18)),
      users.name.assign("a"),
    ]
    support.render_built(
      insert.build(
        insert.set_dialect(
          insert.values(insert.create(users), row),
          d,
        ),
      ),
    )
  }

  test "postgres" {
    expect.not_equal(q(dialect.postgres()), "")
  }
  test "mysql" {
    expect.not_equal(q(dialect.mysql()), "")
  }
  test "sqlite" {
    expect.not_equal(q(dialect.sqlite()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m37 from "./case_schema_nullable_insert";

function main(): void {
  {
    lt.print(m37.q(m4.postgres()));
  }
  {
    lt.print(m37.q(m4.mysql()));
  }
  {
    lt.print(m37.q(m4.sqlite()));
  }
}

main();
stdout · pass
insert into "users" ("id", "name", "active", "age", "email", "role") values (default, $1, default, $2, default, default)	text:a,int:18
insert into `users` (`id`, `name`, `active`, `age`, `email`, `role`) values (default, ?, default, ?, default, default)	text:a,int:18
insert into "users" ("id", "name", "active", "age", "email", "role") values (null, ?, null, ?, null, null)	text:a,int:18
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.case_schema_nullable_insert as m37

def _usage0() -> None:
    _lt.print_value(m37.q(m4.postgres()))

def _usage1() -> None:
    _lt.print_value(m37.q(m4.mysql()))

def _usage2() -> None:
    _lt.print_value(m37.q(m4.sqlite()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
insert into "users" ("id", "name", "active", "age", "email", "role") values (default, $1, default, $2, default, default)	text:a,int:18
insert into `users` (`id`, `name`, `active`, `age`, `email`, `role`) values (default, ?, default, ?, default, default)	text:a,int:18
insert into "users" ("id", "name", "active", "age", "email", "role") values (null, ?, null, ?, null, null)	text:a,int:18
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_nullable_insert"
	m4 "linguatungga/gen/dialect"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(Q(m4.Postgres()))
	}()

	func() {
		lt.Print(Q(m4.Mysql()))
	}()

	func() {
		lt.Print(Q(m4.Sqlite()))
	}()

}
stdout · pass
insert into "users" ("id", "name", "active", "age", "email", "role") values (default, $1, default, $2, default, default)	text:a,int:18
insert into `users` (`id`, `name`, `active`, `age`, `email`, `role`) values (default, ?, default, ?, default, default)	text:a,int:18
insert into "users" ("id", "name", "active", "age", "email", "role") values (null, ?, null, ?, null, null)	text:a,int:18
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
insert into "users" ("id", "name", "active", "age", "email", "role") values (default, $1, default, $2, default, default)	text:a,int:18
insert into "users" ("id", "name", "active", "age", "email", "role") values (default, $1, default, $2, default, default)	text:a,int:18
match
mysql
insert into `users` (`id`, `name`, `active`, `age`, `email`, `role`) values (default, ?, default, ?, default, default)	text:a,int:18
insert into `users` (`id`, `name`, `active`, `age`, `email`, `role`) values (default, ?, default, ?, default, default)	text:a,int:18
match
sqlite
insert into "users" ("id", "name", "active", "age", "email", "role") values (null, ?, null, ?, null, null)	text:a,int:18
insert into "users" ("id", "name", "active", "age", "email", "role") values (null, ?, null, ?, null, null)	text:a,int:18
match
21

Generated relation with aliased tables

schema/relation-alias·relation_alias

on_alias turns the same generated relation into an ON clause that uses the query aliases p and u.

pass
source · lingua tungga
import dialect { Dialect } "./dialect.lt"
import schema_relations { posts_users } "./generated/schema_relations.lt"
import schema_table_posts { posts } "./generated/schema_table_posts.lt"
import schema_table_users { users } "./generated/schema_table_users.lt"
import relations { on_alias } "./relations.lt"
import select { Select } "./select.lt"
import support "./support.lt"

package case_schema_relation_alias {
  export fn q() -> Select {
    let u = users.alias("u")
    let p = posts.alias("p")
    let joined = select.inner_join(select.from(select.create(), u), p, on_alias(posts_users, "p", "u"))
    select.order_by(select.fields(joined, [u.name, p.title]), [p.title.asc()])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m38 from "./case_schema_relation_alias";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m38.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m38.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m38.q())));
  }
}

main();
stdout · pass
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
select `u`.`name`, `p`.`title` from `users` `u` inner join `posts` `p` on `p`.`user_id` = `u`.`id` order by `p`.`title` asc	
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_schema_relation_alias as m38

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m38.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m38.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m38.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
select `u`.`name`, `p`.`title` from `users` `u` inner join `posts` `p` on `p`.`user_id` = `u`.`id` order by `p`.`title` asc	
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_relation_alias"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
select `u`.`name`, `p`.`title` from `users` `u` inner join `posts` `p` on `p`.`user_id` = `u`.`id` order by `p`.`title` asc	
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
match
mysql
select `u`.`name`, `p`.`title` from `users` `u` inner join `posts` `p` on `p`.`user_id` = `u`.`id` order by `p`.`title` asc	
select `u`.`name`, `p`.`title` from `users` `u` inner join `posts` `p` on `p`.`user_id` = `u`.`id` order by `p`.`title` asc	
match
sqlite
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
select "u"."name", "p"."title" from "users" "u" inner join "posts" "p" on "p"."user_id" = "u"."id" order by "p"."title" asc	
match
22

Join from generated relation metadata

schema/relation-join·relation_join

The ON clause comes from posts_users in schema_relations, not a hand-written column comparison.

pass
source · lingua tungga
import dialect { Dialect } "./dialect.lt"
import schema_relations { posts_users } "./generated/schema_relations.lt"
import schema_table_posts { posts } "./generated/schema_table_posts.lt"
import schema_table_users { users } "./generated/schema_table_users.lt"
import relations { on } "./relations.lt"
import select { Select } "./select.lt"
import support "./support.lt"

package case_schema_relation_join {
  export fn q() -> Select {
    let joined = select.inner_join(select.from(select.create(), users), posts, on(posts_users))
    select.fields(joined, [users.name, posts.title])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m42 from "./case_schema_relation_join";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m42.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m42.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m42.q())));
  }
}

main();
stdout · pass
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
select `users`.`name`, `posts`.`title` from `users` inner join `posts` on `posts`.`user_id` = `users`.`id`	
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_schema_relation_join as m42

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m42.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m42.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m42.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
select `users`.`name`, `posts`.`title` from `users` inner join `posts` on `posts`.`user_id` = `users`.`id`	
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_relation_join"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
select `users`.`name`, `posts`.`title` from `users` inner join `posts` on `posts`.`user_id` = `users`.`id`	
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
match
mysql
select `users`.`name`, `posts`.`title` from `users` inner join `posts` on `posts`.`user_id` = `users`.`id`	
select `users`.`name`, `posts`.`title` from `users` inner join `posts` on `posts`.`user_id` = `users`.`id`	
match
sqlite
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
select "users"."name", "posts"."title" from "users" inner join "posts" on "posts"."user_id" = "users"."id"	
match
23

Aliased columns use the alias

schema/alias·schema_alias

Drizzle renders a table alias as the qualifier, and as `"users" "u"` inside FROM.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import sql_core { Sql } "./sql_core.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"

package case_schema_alias {
  export fn q() -> Sql {
    let tb = schema.with_alias("users", "u", [pg_core.serial("id")])
    expr.to_sql(schema.col(tb, "id"))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m43 from "./case_schema_alias";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m43.q()));
  }
}

main();
stdout · pass
"u"."id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_schema_alias as m43

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m43.q()))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
"u"."id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_alias"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

}
stdout · pass
"u"."id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
"u"."id"	
"u"."id"	
match
24

Column references are table-qualified

schema/column·schema_column

In WHERE, drizzle qualifies columns with the table label.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import sql_core { Sql } "./sql_core.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"

package case_schema_column {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Sql {
    expr.to_sql(schema.col(t(), "id"))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), q()), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m44 from "./case_schema_column";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m44.q()));
  }
  {
    lt.print(m6.render(m4.mysql(), m44.q()));
  }
  {
    lt.print(m6.render(m4.sqlite(), m44.q()));
  }
}

main();
stdout · pass
"users"."id"	
`users`.`id`	
"users"."id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_schema_column as m44

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m44.q()))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m44.q()))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m44.q()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
"users"."id"	
`users`.`id`	
"users"."id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_column"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), Q()))
	}()

}
stdout · pass
"users"."id"	
`users`.`id`	
"users"."id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
"users"."id"	
"users"."id"	
match
mysql
`users`.`id`	
`users`.`id`	
match
sqlite
"users"."id"	
"users"."id"	
match
25

Schema-qualified names

schema/namespace·schema_namespace

A table inside a schema renders `"auth"."accounts"."id"`.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import sql_core { Sql } "./sql_core.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"

package case_schema_namespace {
  export fn q() -> Sql {
    let tb = schema.with_schema("accounts", "auth", [pg_core.integer("account_id")])
    expr.to_sql(schema.col(tb, "account_id"))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m45 from "./case_schema_namespace";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m45.q()));
  }
}

main();
stdout · pass
"auth"."accounts"."account_id"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_schema_namespace as m45

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m45.q()))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
"auth"."accounts"."account_id"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_namespace"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

}
stdout · pass
"auth"."accounts"."account_id"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
"auth"."accounts"."account_id"	
"auth"."accounts"."account_id"	
match
26

Table references are unqualified

schema/table·schema_table

A table on its own renders as its quoted name.

pass
source · lingua tungga
import sql_core { Sql } "./sql_core.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"

package case_schema_table {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Sql {
    schema.ref(t())
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), q()), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m46 from "./case_schema_table";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m46.q()));
  }
  {
    lt.print(m6.render(m4.mysql(), m46.q()));
  }
  {
    lt.print(m6.render(m4.sqlite(), m46.q()));
  }
}

main();
stdout · pass
"users"	
`users`	
"users"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_schema_table as m46

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m46.q()))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m46.q()))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m46.q()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
"users"	
`users`	
"users"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_schema_table"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), Q()))
	}()

}
stdout · pass
"users"	
`users`	
"users"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
"users"	
"users"	
match
mysql
`users`	
`users`	
match
sqlite
"users"	
"users"	
match
27

Aggregates and GROUP BY

select/aggregate·select_aggregate

count(*) and sum over an unqualified field.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_select_aggregate {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.having(select.group_by(select.fields(select.from(select.create(), tb), [schema.field(tb, "age"), expr.count_all()]), [schema.col(tb, "age")]), expr.gt(expr.count_all(), expr.int(1)))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m47 from "./case_select_aggregate";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m47.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m47.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m47.q())));
  }
}

main();
stdout · pass
select "age", count(*) from "users" group by "users"."age" having count(*) > $1	int:1
select `age`, count(*) from `users` group by `users`.`age` having count(*) > ?	int:1
select "age", count(*) from "users" group by "users"."age" having count(*) > ?	int:1
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_select_aggregate as m47

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m47.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m47.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m47.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "age", count(*) from "users" group by "users"."age" having count(*) > $1	int:1
select `age`, count(*) from `users` group by `users`.`age` having count(*) > ?	int:1
select "age", count(*) from "users" group by "users"."age" having count(*) > ?	int:1
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_select_aggregate"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "age", count(*) from "users" group by "users"."age" having count(*) > $1	int:1
select `age`, count(*) from `users` group by `users`.`age` having count(*) > ?	int:1
select "age", count(*) from "users" group by "users"."age" having count(*) > ?	int:1
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "age", count(*) from "users" group by "users"."age" having count(*) > $1	int:1
select "age", count(*) from "users" group by "users"."age" having count(*) > $1	int:1
match
mysql
select `age`, count(*) from `users` group by `users`.`age` having count(*) > ?	int:1
select `age`, count(*) from `users` group by `users`.`age` having count(*) > ?	int:1
match
sqlite
select "age", count(*) from "users" group by "users"."age" having count(*) > ?	int:1
select "age", count(*) from "users" group by "users"."age" having count(*) > ?	int:1
match
28

DISTINCT

select/distinct·select_distinct

select distinct "id" from "users"

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_select_distinct {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.distinct(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m48 from "./case_select_distinct";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m48.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m48.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m48.q())));
  }
}

main();
stdout · pass
select distinct "id" from "users"	
select distinct `id` from `users`	
select distinct "id" from "users"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_select_distinct as m48

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m48.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m48.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m48.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select distinct "id" from "users"	
select distinct `id` from `users`	
select distinct "id" from "users"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_select_distinct"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select distinct "id" from "users"	
select distinct `id` from `users`	
select distinct "id" from "users"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select distinct "id" from "users"	
select distinct "id" from "users"	
match
mysql
select distinct `id` from `users`	
select distinct `id` from `users`	
match
sqlite
select distinct "id" from "users"	
select distinct "id" from "users"	
match
29

Selected columns are unqualified

select/fields·select_fields

Drizzle renders selected columns by name, not table-qualified.

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_select_fields {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.fields(select.from(select.create(), tb), [schema.field(tb, "id"), schema.field(tb, "name")])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m49 from "./case_select_fields";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m49.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m49.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m49.q())));
  }
}

main();
stdout · pass
select "id", "name" from "users"	
select `id`, `name` from `users`	
select "id", "name" from "users"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_select_fields as m49

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m49.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m49.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m49.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id", "name" from "users"	
select `id`, `name` from `users`	
select "id", "name" from "users"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_select_fields"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id", "name" from "users"	
select `id`, `name` from `users`	
select "id", "name" from "users"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id", "name" from "users"	
select "id", "name" from "users"	
match
mysql
select `id`, `name` from `users`	
select `id`, `name` from `users`	
match
sqlite
select "id", "name" from "users"	
select "id", "name" from "users"	
match
30

LIMIT and OFFSET are parameters

select/limit·select_limit

Drizzle binds both values instead of inlining them.

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_select_limit {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.offset(select.limit(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), 10), 5)
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m50 from "./case_select_limit";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m50.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m50.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m50.q())));
  }
}

main();
stdout · pass
select "id" from "users" limit $1 offset $2	int:10,int:5
select `id` from `users` limit ? offset ?	int:10,int:5
select "id" from "users" limit ? offset ?	int:10,int:5
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_select_limit as m50

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m50.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m50.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m50.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" limit $1 offset $2	int:10,int:5
select `id` from `users` limit ? offset ?	int:10,int:5
select "id" from "users" limit ? offset ?	int:10,int:5
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_select_limit"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" limit $1 offset $2	int:10,int:5
select `id` from `users` limit ? offset ?	int:10,int:5
select "id" from "users" limit ? offset ?	int:10,int:5
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" limit $1 offset $2	int:10,int:5
select "id" from "users" limit $1 offset $2	int:10,int:5
match
mysql
select `id` from `users` limit ? offset ?	int:10,int:5
select `id` from `users` limit ? offset ?	int:10,int:5
match
sqlite
select "id" from "users" limit ? offset ?	int:10,int:5
select "id" from "users" limit ? offset ?	int:10,int:5
match
31

ORDER BY with asc/desc

select/order·select_order

Direction is lower-case and the column stays qualified.

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_select_order {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.order_by(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), [expr.asc(schema.col(tb, "name")), expr.desc(schema.col(tb, "id"))])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m51 from "./case_select_order";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m51.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m51.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m51.q())));
  }
}

main();
stdout · pass
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
select `id` from `users` order by `users`.`name` asc, `users`.`id` desc	
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_select_order as m51

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m51.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m51.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m51.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
select `id` from `users` order by `users`.`name` asc, `users`.`id` desc	
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_select_order"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
select `id` from `users` order by `users`.`name` asc, `users`.`id` desc	
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
match
mysql
select `id` from `users` order by `users`.`name` asc, `users`.`id` desc	
select `id` from `users` order by `users`.`name` asc, `users`.`id` desc	
match
sqlite
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
select "id" from "users" order by "users"."name" asc, "users"."id" desc	
match
32

WHERE qualifies the left-hand column

select/where·select_where

where "users"."id" = $1

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_select_where {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), expr.eq(schema.col(tb, "id"), expr.int(1)))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m52 from "./case_select_where";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m52.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m52.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m52.q())));
  }
}

main();
stdout · pass
select "id" from "users" where "users"."id" = $1	int:1
select `id` from `users` where `users`.`id` = ?	int:1
select "id" from "users" where "users"."id" = ?	int:1
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_select_where as m52

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m52.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m52.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m52.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where "users"."id" = $1	int:1
select `id` from `users` where `users`.`id` = ?	int:1
select "id" from "users" where "users"."id" = ?	int:1
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_select_where"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where "users"."id" = $1	int:1
select `id` from `users` where `users`.`id` = ?	int:1
select "id" from "users" where "users"."id" = ?	int:1
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where "users"."id" = $1	int:1
select "id" from "users" where "users"."id" = $1	int:1
match
mysql
select `id` from `users` where `users`.`id` = ?	int:1
select `id` from `users` where `users`.`id` = ?	int:1
match
sqlite
select "id" from "users" where "users"."id" = ?	int:1
select "id" from "users" where "users"."id" = ?	int:1
match
33

EXCEPT

set/except·set_except

Set difference.

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_set_except {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.except_query(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), select.fields(select.from(select.create(), other), [schema.field(other, "id")]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(select.set_dialect(q(), dialect.postgres()))), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m53 from "./case_set_except";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m8.setDialect(m53.q(), m4.postgres()))));
  }
}

main();
stdout · pass
(select "id" from "users") except (select "id" from "posts")	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_set_except as m53

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m8.set_dialect(m53.q(), m4.postgres()))))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
(select "id" from "users") except (select "id" from "posts")	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_set_except"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(m8.SetDialect(Q(), m4.Postgres()))))
	}()

}
stdout · pass
(select "id" from "users") except (select "id" from "posts")	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
(select "id" from "users") except (select "id" from "posts")	
(select "id" from "users") except (select "id" from "posts")	
match
34

INTERSECT

set/intersect·set_intersect

Set intersection.

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_set_intersect {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.intersect(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), select.fields(select.from(select.create(), other), [schema.field(other, "id")]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(select.set_dialect(q(), dialect.postgres()))), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m54 from "./case_set_intersect";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m8.setDialect(m54.q(), m4.postgres()))));
  }
}

main();
stdout · pass
(select "id" from "users") intersect (select "id" from "posts")	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_set_intersect as m54

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m8.set_dialect(m54.q(), m4.postgres()))))

def main() -> None:
    _usage0()

if __name__ == "__main__":
    main()
stdout · pass
(select "id" from "users") intersect (select "id" from "posts")	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_set_intersect"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(m8.SetDialect(Q(), m4.Postgres()))))
	}()

}
stdout · pass
(select "id" from "users") intersect (select "id" from "posts")	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
(select "id" from "users") intersect (select "id" from "posts")	
(select "id" from "users") intersect (select "id" from "posts")	
match
35

UNION and UNION ALL

set/union·set_union

Both sides parenthesised.

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_set_union {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    select.union(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), select.fields(select.from(select.create(), other), [schema.field(other, "id")]))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(select.set_dialect(q(), dialect.postgres()))), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(select.set_dialect(q(), dialect.mysql()))), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(select.set_dialect(q(), dialect.sqlite()))), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m55 from "./case_set_union";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m8.setDialect(m55.q(), m4.postgres()))));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m8.setDialect(m55.q(), m4.mysql()))));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m8.setDialect(m55.q(), m4.sqlite()))));
  }
}

main();
stdout · pass
(select "id" from "users") union (select "id" from "posts")	
(select `id` from `users`) union (select `id` from `posts`)	
select "id" from "users" union select "id" from "posts"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_set_union as m55

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m8.set_dialect(m55.q(), m4.postgres()))))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m8.set_dialect(m55.q(), m4.mysql()))))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m8.set_dialect(m55.q(), m4.sqlite()))))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
(select "id" from "users") union (select "id" from "posts")	
(select `id` from `users`) union (select `id` from `posts`)	
select "id" from "users" union select "id" from "posts"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_set_union"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(m8.SetDialect(Q(), m4.Postgres()))))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(m8.SetDialect(Q(), m4.Mysql()))))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(m8.SetDialect(Q(), m4.Sqlite()))))
	}()

}
stdout · pass
(select "id" from "users") union (select "id" from "posts")	
(select `id` from `users`) union (select `id` from `posts`)	
select "id" from "users" union select "id" from "posts"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
(select "id" from "users") union (select "id" from "posts")	
(select "id" from "users") union (select "id" from "posts")	
match
mysql
(select `id` from `users`) union (select `id` from `posts`)	
(select `id` from `users`) union (select `id` from `posts`)	
match
sqlite
select "id" from "users" union select "id" from "posts"	
select "id" from "users" union select "id" from "posts"	
match
36

Identifiers are quoted per dialect

sql/identifier·sql_identifier

Postgres and SQLite use double quotes, MySQL backticks; drizzle does not escape embedded quotes.

pass
source · lingua tungga
import sql_core { Sql, append, identifier, raw } "./sql_core.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"

package case_sql_identifier {
  export fn q() -> Sql {
    append(raw("select "), identifier("users"))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), q()), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m56 from "./case_sql_identifier";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m56.q()));
  }
  {
    lt.print(m6.render(m4.mysql(), m56.q()));
  }
  {
    lt.print(m6.render(m4.sqlite(), m56.q()));
  }
}

main();
stdout · pass
select "users"	
select `users`	
select "users"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_sql_identifier as m56

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m56.q()))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m56.q()))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m56.q()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "users"	
select `users`	
select "users"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_sql_identifier"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), Q()))
	}()

}
stdout · pass
select "users"	
select `users`	
select "users"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "users"	
select "users"	
match
mysql
select `users`	
select `users`	
match
sqlite
select "users"	
select "users"	
match
37

Typed parameters keep their order

sql/params·sql_params

Every scalar type is a parameter; numbering and dialect placeholders must match.

pass
source · lingua tungga
import sql_core { Sql } "./sql_core.lt"
import sql_tag { sql } "./sql_tag.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"

package case_sql_params {
  export fn q() -> Sql {
    sql(
      ["select ", ", ", ", ", ""],
      [Value.Int(1), Value.Bool(true), Value.Str("x")],
    )
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), q()), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m57 from "./case_sql_params";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m57.q()));
  }
  {
    lt.print(m6.render(m4.mysql(), m57.q()));
  }
  {
    lt.print(m6.render(m4.sqlite(), m57.q()));
  }
}

main();
stdout · pass
select $1, $2, $3	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_sql_params as m57

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m57.q()))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m57.q()))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m57.q()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select $1, $2, $3	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_sql_params"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), Q()))
	}()

}
stdout · pass
select $1, $2, $3	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select $1, $2, $3	int:1,bool:true,text:x
select $1, $2, $3	int:1,bool:true,text:x
match
mysql
select ?, ?, ?	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
match
sqlite
select ?, ?, ?	int:1,bool:true,text:x
select ?, ?, ?	int:1,bool:true,text:x
match
38

Raw SQL is passed through

sql/raw·sql_raw

Drizzle hands raw text to the dialect unchanged; the port must not add quoting.

pass
source · lingua tungga
import sql_core { Sql, raw } "./sql_core.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"

package case_sql_raw {
  export fn q() -> Sql {
    raw("select 1")
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), q()), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), q()), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), q()), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m59 from "./case_sql_raw";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m59.q()));
  }
  {
    lt.print(m6.render(m4.mysql(), m59.q()));
  }
  {
    lt.print(m6.render(m4.sqlite(), m59.q()));
  }
}

main();
stdout · pass
select 1	
select 1	
select 1	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.case_sql_raw as m59

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m59.q()))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m59.q()))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m59.q()))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select 1	
select 1	
select 1	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_sql_raw"
	m4 "linguatungga/gen/dialect"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), Q()))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), Q()))
	}()

}
stdout · pass
select 1	
select 1	
select 1	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select 1	
select 1	
match
mysql
select 1	
select 1	
match
sqlite
select 1	
select 1	
match
39

EXISTS subquery

subquery/exists·subquery_exists

exists (select ...)

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_subquery_exists {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    let inner = select.where(select.fields(select.from(select.create(), other), [schema.field(other, "id")]), expr.eq(schema.col(other, "user_id"), schema.col(tb, "id")))
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), select.exists(inner))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m60 from "./case_subquery_exists";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m60.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m60.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m60.q())));
  }
}

main();
stdout · pass
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
select `id` from `users` where exists (select `id` from `posts` where `posts`.`user_id` = `users`.`id`)	
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_subquery_exists as m60

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m60.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m60.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m60.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
select `id` from `users` where exists (select `id` from `posts` where `posts`.`user_id` = `users`.`id`)	
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_subquery_exists"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
select `id` from `users` where exists (select `id` from `posts` where `posts`.`user_id` = `users`.`id`)	
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
match
mysql
select `id` from `users` where exists (select `id` from `posts` where `posts`.`user_id` = `users`.`id`)	
select `id` from `users` where exists (select `id` from `posts` where `posts`.`user_id` = `users`.`id`)	
match
sqlite
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
select "id" from "users" where exists (select "id" from "posts" where "posts"."user_id" = "users"."id")	
match
40

Subquery in FROM

subquery/from·subquery_from

from (select ...) "s"

pass
source · lingua tungga
import expr { Expr } "./expr.lt"
import sql_core { Sql } "./sql_core.lt"
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_subquery_from {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  export fn q() -> Select {
    let tb = t()
    let inner = select.fields(select.from(select.create(), tb), [schema.field(tb, "id"), schema.field(tb, "name")])
    select.fields(select.from_subquery(select.create(), inner, "s"), [expr.raw_sql(sql_core.identifier("id"))])
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m61 from "./case_subquery_from";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m61.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m61.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m61.q())));
  }
}

main();
stdout · pass
select "id" from (select "id", "name" from "users") "s"	
select `id` from (select `id`, `name` from `users`) `s`	
select "id" from (select "id", "name" from "users") "s"	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_subquery_from as m61

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m61.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m61.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m61.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from (select "id", "name" from "users") "s"	
select `id` from (select `id`, `name` from `users`) `s`	
select "id" from (select "id", "name" from "users") "s"	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_subquery_from"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from (select "id", "name" from "users") "s"	
select `id` from (select `id`, `name` from `users`) `s`	
select "id" from (select "id", "name" from "users") "s"	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from (select "id", "name" from "users") "s"	
select "id" from (select "id", "name" from "users") "s"	
match
mysql
select `id` from (select `id`, `name` from `users`) `s`	
select `id` from (select `id`, `name` from `users`) `s`	
match
sqlite
select "id" from (select "id", "name" from "users") "s"	
select "id" from (select "id", "name" from "users") "s"	
match
41

IN subquery

subquery/in·subquery_in

in (select ...)

pass
source · lingua tungga
import schema { Table } "./schema.lt"
import dialect { Dialect } "./dialect.lt"
import support "./support.lt"
import pg_core "./pg_core.lt"
import select { Select } "./select.lt"

package case_subquery_in {
  fn t() -> Table {
    schema.plain("users", [pg_core.serial("id"), pg_core.text("name"), pg_core.integer("age")])
  }
  fn p() -> Table {
    schema.plain("posts", [pg_core.serial("id"), pg_core.integer("user_id"), pg_core.text("title")])
  }
  export fn q() -> Select {
    let tb = t()
    let other = p()
    let inner = select.fields(select.from(select.create(), other), [schema.field(other, "user_id")])
    select.where(select.fields(select.from(select.create(), tb), [schema.field(tb, "id")]), select.in_subquery(schema.col(tb, "id"), inner))
  }

  test "postgres" {
    expect.not_equal(support.render(dialect.postgres(), select.to_sql(q())), "")
  }
  test "mysql" {
    expect.not_equal(support.render(dialect.mysql(), select.to_sql(q())), "")
  }
  test "sqlite" {
    expect.not_equal(support.render(dialect.sqlite(), select.to_sql(q())), "")
  }
}
host output · three targets
// Generated by Lingua Tungga. Do not edit by hand.
import * as lt from "../_lingua_rt";
import * as m4 from "./dialect";
import * as m6 from "./support";
import * as m8 from "./select";
import * as m62 from "./case_subquery_in";

function main(): void {
  {
    lt.print(m6.render(m4.postgres(), m8.toSql(m62.q())));
  }
  {
    lt.print(m6.render(m4.mysql(), m8.toSql(m62.q())));
  }
  {
    lt.print(m6.render(m4.sqlite(), m8.toSql(m62.q())));
  }
}

main();
stdout · pass
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
select `id` from `users` where `users`.`id` in (select `user_id` from `posts`)	
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
# Generated by Lingua Tungga. Do not edit by hand.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import lt_runtime as _lt
from typing import Any, Callable
import gen.dialect as m4
import gen.support as m6
import gen.select as m8
import gen.case_subquery_in as m62

def _usage0() -> None:
    _lt.print_value(m6.render(m4.postgres(), m8.to_sql(m62.q())))

def _usage1() -> None:
    _lt.print_value(m6.render(m4.mysql(), m8.to_sql(m62.q())))

def _usage2() -> None:
    _lt.print_value(m6.render(m4.sqlite(), m8.to_sql(m62.q())))

def main() -> None:
    _usage0()
    _usage1()
    _usage2()

if __name__ == "__main__":
    main()
stdout · pass
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
select `id` from `users` where `users`.`id` in (select `user_id` from `posts`)	
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
// Generated by Lingua Tungga. Do not edit by hand.
package main

import (
	. "linguatungga/gen/case_subquery_in"
	m4 "linguatungga/gen/dialect"
	m8 "linguatungga/gen/select"
	m6 "linguatungga/gen/support"
	lt "linguatungga/lt"
)

func main() {
	func() {
		lt.Print(m6.Render(m4.Postgres(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Mysql(), m8.ToSql(Q())))
	}()

	func() {
		lt.Print(m6.Render(m4.Sqlite(), m8.ToSql(Q())))
	}()

}
stdout · pass
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
select `id` from `users` where `users`.`id` in (select `user_id` from `posts`)	
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
parity · port vs drizzle 0.44.4
dialectportdrizzle
postgres
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
match
mysql
select `id` from `users` where `users`.`id` in (select `user_id` from `posts`)	
select `id` from `users` where `users`.`id` in (select `user_id` from `posts`)	
match
sqlite
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
select "id" from "users" where "users"."id" in (select "user_id" from "posts")	
match