gmysql

Types

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

Constructors

  • Config(
      host: String,
      port: Int,
      user: Option(String),
      password: Option(String),
      database: String,
      connection_mode: ConnectionMode,
      connection_timeout: Int,
      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 TransactionError(a) {
  FunctionError(a)
  OtherError(Dynamic)
}

Constructors

  • FunctionError(a)
  • OtherError(Dynamic)

Functions

pub fn close(connection: Connection) -> Nil
pub fn connect(config: Config) -> Result(Connection, Dynamic)
pub fn default_config() -> Config
pub fn exec(
  connection: Connection,
  query: String,
  timeout: Int,
) -> Result(Nil, Error)
pub fn query(
  connection: Connection,
  query: String,
  params: List(Param),
  timeout: Int,
  decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
) -> Result(a, Error)
pub fn to_param(param: a) -> Param
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