shork

Types

The configuration of a connection.

pub opaque type Config
pub type Connection
pub opaque type Query(row_type)
pub type QueryError {
  UnexpectedResultType(List(decode.DecodeError))
  ServerError(Int, String)
}

Constructors

  • UnexpectedResultType(List(decode.DecodeError))

    The rows returned by the database could not be decoded using the supplied dynamic decoder.

  • ServerError(Int, String)

    The server returned a error during processing the query.

The names of the column names and the rows returned by the query.

pub type Returned(t) {
  Returned(column_names: List(String), rows: List(t))
}

Constructors

  • Returned(column_names: List(String), rows: List(t))
pub type TransactionError {
  TransactionQueryError(QueryError)
  TransactionRolledBack(String)
}

Constructors

  • TransactionQueryError(QueryError)

    One query inside a query returned a error.

  • TransactionRolledBack(String)

    The transaction rolled back as an result of an error inside the transaction.

A value that can be sent to MySQL as one of the arguments to a parameterised SQL query.

pub type Value

Values

pub fn bool(a: Bool) -> Value
pub fn connect(a: Config) -> Connection

Starts a database connection.

pub fn connection_timeout(
  config: Config,
  query_timeout: Int,
) -> Config

The maximum time to spend on connect.

(default: 3000)

pub fn database(config: Config, database: String) -> Config

Name of the database to use.

pub fn default_config() -> Config

The default configuration for a connection.

pub fn disconnect(a: Connection) -> Nil

Stops a database connection.

pub fn execute(
  query query: Query(t),
  on connection: Connection,
) -> Result(Returned(t), QueryError)

Run a query against a MySQL/MariaDB database.

pub fn float(a: Float) -> Value
pub fn host(config: Config, host: String) -> Config

Database server hostname.

(default: localhost)

pub fn int(a: Int) -> Value
pub fn keep_alive(config: Config, keep_alive: Bool) -> Config

Whether to send keep alive messages for used connections.

(default: False)

pub fn log_slow_queries(
  config: Config,
  log_slow_queries: Bool,
) -> Config

Whether to log queries that got as slow query from the server.

(default: False)

pub fn log_warnings(config: Config, log_warnings: Bool) -> Config

Whether to fetch warnings and log them using error_logger.

(default: False)

pub fn null() -> Value
pub fn parameter(query: Query(t), parameter: Value) -> Query(t)

Push a new parameter value for the query.

pub fn password(config: Config, password: String) -> Config

Password for the user.

pub fn port(config: Config, port: Int) -> Config

Port the server is listing on.

(default: 3306)

pub fn query(sql: String) -> Query(Nil)

Set the decoder to use for the type of row returned by executing this query.

If the decoder is unable to decode the row value then query will return an error.

pub fn query_cache_time(
  config: Config,
  query_cache_time: Int,
) -> Config

The minimum number of milliseconds to cache prepared statements used for parametrized queries with query.

(default: 1000)

pub fn query_timeout(
  config: Config,
  query_timeout: Int,
) -> Config

Default time to wait for a query to execute.

(default: 5000)

pub fn returning(
  query: Query(t1),
  decoder: decode.Decoder(t2),
) -> Query(t2)

Create a new query to use with the execute, returning and parameters function.

pub fn text(a: String) -> Value
pub fn timeout(query: Query(t), timeout: Int) -> Query(t)

Use a custom timeout for the query. The timeout give is given in ms.

pub fn transaction(
  connection: Connection,
  callback cb: fn(Connection) -> Result(t, e),
) -> Result(t, TransactionError)
pub fn user(config: Config, user: String) -> Config

Username to connect to database as.

Search Document