cigogne/config

Types

Cigogne’s configuration type

It contains all the data that can be found in the cigogne.toml file and a bit more (like the application name).

pub type Config {
  Config(
    database: DatabaseConfig,
    migration_table: MigrationTableConfig,
    migrations: MigrationsConfig,
  )
}

Constructors

Possible errors when dealing with the configuration

pub type ConfigError {
  AppNameError
  AppNotFound(name: String)
  ConfigFileNotFound(path: String)
  FSError(error: @internal FSError)
}

Constructors

  • AppNameError
  • AppNotFound(name: String)
  • ConfigFileNotFound(path: String)
  • FSError(error: @internal FSError)

Database configuration options

pub type DatabaseConfig {
  UrlDbConfig(url: String)
  DetailedDbConfig(
    host: option.Option(String),
    user: option.Option(String),
    password: option.Option(String),
    port: option.Option(Int),
    name: option.Option(String),
  )
  EnvVarConfig
  ConnectionDbConfig(connection: pog.Connection)
}

Constructors

  • UrlDbConfig(url: String)

    Use a database URL / connection string to connect

  • DetailedDbConfig(
      host: option.Option(String),
      user: option.Option(String),
      password: option.Option(String),
      port: option.Option(Int),
      name: option.Option(String),
    )

    Use detailed parameters to connect

  • EnvVarConfig

    Use environment variable DATABASE_URL to connect

  • ConnectionDbConfig(connection: pog.Connection)

    Use an existing pog connection

Configuration for the migration table

pub type MigrationTableConfig {
  MigrationTableConfig(
    schema: option.Option(String),
    table: option.Option(String),
  )
}

Constructors

Configuration for migrations such as the folder they are in and dependencies

pub type MigrationsConfig {
  MigrationsConfig(
    application_name: String,
    migration_folder: option.Option(String),
    dependencies: List(#(String, String)),
    no_hash_check: option.Option(Bool),
  )
}

Constructors

  • MigrationsConfig(
      application_name: String,
      migration_folder: option.Option(String),
      dependencies: List(#(String, String)),
      no_hash_check: option.Option(Bool),
    )

Values

pub const default_config: Config
pub const default_db_config: DatabaseConfig
pub const default_mig_table_config: MigrationTableConfig
pub const default_migrations_config: MigrationsConfig
pub fn get(
  application_name: String,
) -> Result(Config, ConfigError)

Get the configuration for the provided application by reading the cigogne.toml file. The configuration file is read from the priv directory of the application.

pub fn get_app_name() -> Result(String, ConfigError)

Get the current application’s name by reading the gleam.toml file The gleam.toml file is expected to be in the current working directory You don’t have to use this function, since you should already know your project’s name

pub fn get_error_message(error: ConfigError) -> String
pub fn get_migrations_folder(
  migrations_config: MigrationsConfig,
) -> String

Get the migrations folder from the migrations configuration, or the default one if none is set.

pub fn merge(config: Config, to_merge: Config) -> Config

Merge two configurations, with to_merge having precedence over config.

pub fn merge_migrations_config(
  config: MigrationsConfig,
  to_merge: MigrationsConfig,
) -> MigrationsConfig

Merge two migrations configurations, with to_merge having precedence over config.

pub fn print(config: Config) -> String

Print the configuration as a TOML string.

pub fn write(config: Config) -> Result(Nil, ConfigError)

Write the given configuration to the priv/cigogne.toml file.

Search Document