cake/fragment

Fragments are low level building blocks of queries which allow direct manipulation of the query string.

If you want to insert parameters, you are required to use prepared fragments, which will be validated against the number of parameters given and the parameters are automatically escaped by the RDBMS to prevent SQL injections.

Types

pub type Fragment =
  read_query.Fragment

Constants

pub const placeholder: String

This placeholder must be used when building fragments with parameters.

Functions

pub fn bool(value vl: Bool) -> Param

Create a new Param with a Bool value.

pub fn false() -> Param

Create a new Param with a True value.

pub fn float(value vl: Float) -> Param

Create a new Param with a Float value.

pub fn int(value vl: Int) -> Param

Create a new Param with an Int value.

pub fn literal(string str: String) -> Fragment

Create a new fragment from a literal string.

⛔ ⛔ ⛔

WARNING: YOU ARE FORBIDDEN TO INSERT UNCONTROLLED USER INPUT THIS WAY!

⛔ ⛔ ⛔

pub fn null() -> Param

Create a new Param with an SQL NULL value.

pub fn prepared(
  string str: String,
  params prms: List(Param),
) -> Fragment

Create a new fragment from a string and a list of parameters.

⛔ ⛔ ⛔

If you missmatch the number of placeholders with the number of parameters, an error will be printed to stderr and the fragment will be created with the given parameters:

  • If there are too many placeholders, the fragment will be created with the given parameters and the last parameter will be repeated for the remaining placeholders.
  • If there are too many parameters, the fragment will be created with the given parameters and the excess parameters will be ignored.

⛔ ⛔ ⛔

pub fn string(value vl: String) -> Param

Create a new Param with a String value.

pub fn true() -> Param

Create a new Param with a True value.

Search Document