pevensie/postgres

Types

An IP version for a PostgresConfig.

pub type IpVersion {
  Ipv4
  Ipv6
}

Constructors

  • Ipv4
  • Ipv6

The Postgres driver.

pub opaque type Postgres

Configuration for connecting to a Postgres database.

Use the default_config function to get a default configuration for connecting to a local Postgres database with sensible concurrency defaults.

import pevensie/drivers/postgres.{type PostgresConfig}

pub fn main() {
  let config = PostgresConfig(
    ..postgres.default_config(),
    host: "db.pevensie.dev",
    database: "my_database",
  )
  // ...
}
pub type PostgresConfig {
  PostgresConfig(
    host: String,
    port: Int,
    database: String,
    user: String,
    password: Option(String),
    ssl: Bool,
    connection_parameters: List(#(String, String)),
    pool_size: Int,
    queue_target: Int,
    queue_interval: Int,
    idle_interval: Int,
    trace: Bool,
    ip_version: IpVersion,
    default_timeout: Int,
  )
}

Constructors

  • PostgresConfig(
      host: String,
      port: Int,
      database: String,
      user: String,
      password: Option(String),
      ssl: Bool,
      connection_parameters: List(#(String, String)),
      pool_size: Int,
      queue_target: Int,
      queue_interval: Int,
      idle_interval: Int,
      trace: Bool,
      ip_version: IpVersion,
      default_timeout: Int,
    )

Errors that can occur when interacting with the Postgres driver. Will probably be removed or changed - haven’t decided on the final API yet.

pub type PostgresError {
  ConstraintViolated(
    message: String,
    constraint: String,
    detail: String,
  )
  PostgresqlError(code: String, name: String, message: String)
  ConnectionUnavailable
}

Constructors

  • ConstraintViolated(
      message: String,
      constraint: String,
      detail: String,
    )
  • PostgresqlError(code: String, name: String, message: String)
  • ConnectionUnavailable

Constants

pub const session_select_fields: String

The SQL used to select fields from the session table.

pub const user_select_fields: String

The SQL used to select fields from the user table.

Functions

pub fn default_config() -> PostgresConfig

Returns a default PostgresConfig for connecting to a local Postgres database.

Can also be used to provide sensible concurrency defaults for connecting to a remote database.

import pevensie/drivers/postgres.{type PostgresConfig}

pub fn main() {
  let config = PostgresConfig(
    ..postgres.default_config(),
    host: "db.pevensie.dev",
    database: "my_database",
  )
  // ...
}
pub fn main() -> Nil
pub fn new_auth_driver(
  config: PostgresConfig,
) -> AuthDriver(Postgres, PostgresError, a)

Creates a new AuthDriver for use with the pevensie/auth.new function.

import pevensie/drivers/postgres.{type PostgresConfig}
import pevensie/auth.{type PevensieAuth}

pub fn main() {
  let config = PostgresConfig(
    ..postgres.default_config(),
    host: "db.pevensie.dev",
    database: "my_database",
  )
  let driver = postgres.new_auth_driver(config)
  let pevensie_auth = auth.new(
    driver:,
    user_metadata_decoder:,
    user_metadata_encoder:,
    cookie_key: "super secret signing key",
  )
  // ...
}
pub fn new_cache_driver(
  config: PostgresConfig,
) -> CacheDriver(Postgres, PostgresError)

Creates a new CacheDriver for use with the pevensie/cache.new function.

import pevensie/drivers/postgres.{type PostgresConfig}
import pevensie/cache.{type PevensieCache}

pub fn main() {
  let config = PostgresConfig(
    ..postgres.default_config(),
    host: "db.pevensie.dev",
    database: "my_database",
  )
  let driver = postgres.new_cache_driver(config)
  let pevensie_cache = cache.new(driver)
  // ...
}
pub fn session_decoder() -> Decoder(Session)

A decoder for the session table. Requires use of the session_select_fields when querying.

pub fn user_decoder(
  user_metadata_decoder: Decoder(a),
) -> Decoder(User(a))

A decoder for the user table. Requires use of the user_select_fields when querying.

Search Document