package sequoia

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

SELECT queries.

type _ t

The type of SELECT queries.

type ('s1, 't1, 't2, 's2) join_steps =
  1. | There : (('t2 -> _) as 's1, 't1, 't2, 't1 -> 's1) join_steps
  2. | Skip : ('s1, 't1, 't2, 's2) join_steps -> ('a -> 's1, 't1, 't2, 'a -> 's2) join_steps
    (*

    This type allows the representation of SQL joins in the OCaml type system.

    *)
type join

The type of SQL joins.

type 's source =
  1. | From : 't Sequoia_table.t -> ('t -> unit) source
  2. | Join : join * ('t1, 't2) Sequoia_field.foreign_key * 's1 source * ('s1, 't1, 't2, 's2) join_steps -> 's2 source
    (*

    Data sources for SELECT queries: tables specified in the the FROM or JOIN clause. Joins are only allowed on fields declared as foreign keys. The join_steps type joins the tables in the OCaml type system sense.

    *)
type ('s1, 't1, 't2, 's2) steps =
  1. | There : (('t2 -> _) as 's1, 't1, 't2, 's1) steps
  2. | Skip : ('s1, 't1, 't2, 's2) steps -> ('a -> 's1, 't1, 't2, 'a -> 's2) steps
    (*

    This is analogous to join_steps but instead of building the set of data sources (i.e. the tables being referenced in the query), it is used to simply reference them.

    *)
val seal : handover:Sequoia_expr.handover -> 's t -> string * Sequoia_param.t list

Mark the end of a SELECT query.

module Expr : sig ... end

Expressions that are valid in SELECT queries.

val select : ?distinct:bool -> ('s, 'a, 'n Sequoia_vector.Nat.s) Expr.Vector.t -> 's source -> 's t

Define the selected expressions in a SELECT query.

val from : 't Sequoia_table.t -> ('t -> unit) source

Starts a SELECT query by specifying the initial data source.

val left_join : (('t1, 't2) Sequoia_field.foreign_key * ('s1, 't1, 't2, 's2) join_steps) -> 's1 source -> 's2 source

Specifies a LEFT JOIN adding the table containing the given foreign key as a data source.

val right_join : (('t1, 't2) Sequoia_field.foreign_key * ('s1, 't1, 't2, 's2) join_steps) -> 's1 source -> 's2 source

Specifies a RIGHT JOIN adding the table containing the given foreign key as a data source.

val inner_join : (('t1, 't2) Sequoia_field.foreign_key * ('s1, 't1, 't2, 's2) join_steps) -> 's1 source -> 's2 source

Specifies an INNER JOIN adding the table containing the given foreign key as a data source.

val self : ('t, int) Sequoia_field.t -> ('t, int) Sequoia_field.t -> ('s1, 't1, 't, 's2) join_steps -> ('t, 't) Sequoia_field.foreign_key * ('s1, 't1, 't, 's2) join_steps

Allows self-joins, i.e. joins that use fields belonging to a single table.

val this : ('t1, 't2) Sequoia_field.foreign_key -> ('s1, 't1, 't2, 's2) join_steps -> ('t1, 't2) Sequoia_field.foreign_key * ('s1, 't1, 't2, 's2) join_steps

Call this on a foreign key when you want to define a join with the table that contains the foreign key.

val that : ('t1, 't2) Sequoia_field.foreign_key -> ('s1, 't2, 't1, 's2) join_steps -> ('t2, 't1) Sequoia_field.foreign_key * ('s1, 't2, 't1, 's2) join_steps

Call this on a foreign key when you want to define a join with the table that contains the field that the foreign key references.

val where : ('a source -> bool Expr.t) -> 'a t -> 'a t

Defines a WHERE clause for a SELECT query.

val group_by : ?having:('s source -> bool Expr.t) -> ('s, 'a, 'n Sequoia_vector.Nat.s) Expr.Vector.t -> 's t -> 's t

Defines a GROUP BY clause for a SELECT query.

module OrderBy : sig ... end

Definitions for ORDER BY clauses.

val order_by : ('s, 'a, 'n Sequoia_vector.Nat.s) OrderBy.Expr.Vector.t -> 's t -> 's t

Defines an ORDER BY clause in a SELECT query.

val limit : ?offset:int -> int -> 'a t -> 'a t

Defines a LIMIT clause in a SELECT query.