gmysql

Types

pub type Config {
  Config(
    host: String,
    port: Int,
    user: Option(String),
    password: Option(String),
    database: String,
    connection_mode: ConnectionMode,
    connection_timeout: Timeout,
    keep_alive: Int,
  )
}

Constructors

  • Config(
      host: String,
      port: Int,
      user: Option(String),
      password: Option(String),
      database: String,
      connection_mode: ConnectionMode,
      connection_timeout: Timeout,
      keep_alive: Int,
    )
pub type Connection
pub type ConnectionMode {
  Synchronous
  Asynchronous
  Lazy
}

Constructors

  • Synchronous
  • Asynchronous
  • Lazy
pub type Error {
  ServerError(Int, BitArray)
  UnknownError(Dynamic)
  DecodeError(dynamic.DecodeErrors)
}

Constructors

  • ServerError(Int, BitArray)
  • UnknownError(Dynamic)
  • DecodeError(dynamic.DecodeErrors)
pub type Param
pub type Timeout {
  Infinity
  Ms(Int)
}

Constructors

  • Infinity
  • Ms(Int)
pub type TransactionError(a) {
  FunctionError(a)
  OtherError(Dynamic)
}

Constructors

  • FunctionError(a)
  • OtherError(Dynamic)

Functions

pub fn connect(config: Config) -> Result(Connection, Dynamic)
pub fn default_config() -> Config
pub fn disconnect(connection: Connection) -> Nil
pub fn exec(
  sql: String,
  on connection: Connection,
) -> Result(Nil, Error)
pub fn exec_with_timeout(
  sql: String,
  on connection: Connection,
  until timeout: Timeout,
) -> Result(Nil, Error)
pub fn from_pid(connection: Pid) -> Connection

Danger, this is primarily for internal use, do not pass in pids that you did not get from the to_pid/1 function.

pub fn query(
  sql: String,
  on connection: Connection,
  with arguments: List(Param),
  expecting decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
) -> Result(List(a), Error)
pub fn query_with_timeout(
  sql: String,
  on connection: Connection,
  with arguments: List(Param),
  expecting decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
  until timeout: Timeout,
) -> Result(List(a), Error)
pub fn to_param(param: a) -> Param
pub fn to_pid(connection: Connection) -> Pid
pub fn with_connection(
  config: Config,
  with function: fn(Connection) -> a,
) -> Result(a, Dynamic)
pub fn with_transaction(
  connection: Connection,
  retry retries: Int,
  with function: fn(Connection) -> Result(a, b),
) -> Result(a, TransactionError(b))

Execute a function within a transaction. If the function throws or returns an error, it will rollback. You can nest this function, which will create a savepoint.

Search Document