Electric.Config (electric v1.2.4)

View Source

Summary

Types

instance_id()

@type instance_id() :: String.t()

Functions

default(key)

fetch_env!(key)

@spec fetch_env!(Application.key()) :: Application.value()

get_env(key)

@spec get_env(Application.key()) :: Application.value()

get_env_lazy(key, fun)

installation_id!(kv)

@spec installation_id!(term()) :: binary() | no_return()

min_replication_idle_timeout()

@spec min_replication_idle_timeout() :: pos_integer()

The minimum allowed time before Electric can close database connections due to the replication stream inactivity.

This is to prevent churn where connection and replication supervisors would restart too frequently.

The scale-to-zero feature of managed providers like Neon takes on the order of minutes before deciding that an idle database can be scaled down.

min_replication_idle_timeout_in_seconds()

parse_feature_flags(str)

parse_human_readable_time(str)

@spec parse_human_readable_time(binary() | nil) ::
  {:ok, pos_integer()} | {:error, binary()}

parse_human_readable_time!(str)

parse_log_level(str)

@spec parse_log_level(binary()) :: {:ok, Logger.level()} | {:error, binary()}

parse_log_level!(str)

parse_postgresql_uri(uri_str)

@spec parse_postgresql_uri(binary()) :: {:ok, keyword()} | {:error, binary()}

Parse a PostgreSQL URI into a keyword list.

Examples

iex> parse_postgresql_uri("postgresql://postgres:password@example.com/app-db") |> deobfuscate()
{:ok, [
  hostname: "example.com",
  port: 5432,
  database: "app-db",
  username: "postgres",
  password: "password",
]}

iex> parse_postgresql_uri("postgresql://electric@192.168.111.33:81/__shadow")
{:ok, [
  hostname: "192.168.111.33",
  port: 81,
  database: "__shadow",
  username: "electric"
]}

iex> parse_postgresql_uri("postgresql://pg@[2001:db8::1234]:4321")
{:ok, [
  hostname: "2001:db8::1234",
  port: 4321,
  database: "pg",
  username: "pg"
]}

iex> parse_postgresql_uri("postgresql://user@localhost:5433/")
{:ok, [
  hostname: "localhost",
  port: 5433,
  database: "user",
  username: "user"
]}

iex> parse_postgresql_uri("postgresql://user%2Btesting%40gmail.com:weird%2Fpassword@localhost:5433/my%2Bdb%2Bname") |> deobfuscate()
{:ok, [
  hostname: "localhost",
  port: 5433,
  database: "my+db+name",
  username: "user+testing@gmail.com",
  password: "weird/password"
]}

iex> parse_postgresql_uri("postgres://super_user@localhost:7801/postgres?sslmode=disable")
{:ok, [
  hostname: "localhost",
  port: 7801,
  database: "postgres",
  username: "super_user",
  sslmode: :disable
]}

iex> parse_postgresql_uri("postgres://super_user@localhost:7801/postgres?sslmode=require")
{:ok, [
  hostname: "localhost",
  port: 7801,
  database: "postgres",
  username: "super_user",
  sslmode: :require
]}

iex> parse_postgresql_uri("postgres://super_user@localhost:7801/postgres?sslmode=yesplease")
{:error, "invalid \"sslmode\" value: \"yesplease\""}

iex> parse_postgresql_uri("postgrex://localhost")
{:error, "invalid URL scheme: \"postgrex\""}

iex> parse_postgresql_uri("postgresql://localhost")
{:error, "invalid or missing username"}

iex> parse_postgresql_uri("postgresql://:@localhost")
{:error, "invalid or missing username"}

iex> parse_postgresql_uri("postgresql://:password@localhost")
{:error, "invalid or missing username"}

iex> parse_postgresql_uri("postgresql://user:password")
{:error, "invalid or missing username"}

iex> parse_postgresql_uri("postgresql://user:password@")
{:error, "missing host"}

iex> parse_postgresql_uri("postgresql://user@localhost:5433/mydb?opts=-c%20synchronous_commit%3Doff&foo=bar")
{:error, "unsupported query options: \"foo\", \"opts\""}

iex> parse_postgresql_uri("postgresql://electric@localhost/db?replication=database")
{:error, "unsupported \"replication\" query option. Electric opens both a replication connection and regular connections to Postgres as needed"}

iex> parse_postgresql_uri("postgresql://electric@localhost/db?replication=off")
{:error, "unsupported \"replication\" query option. Electric opens both a replication connection and regular connections to Postgres as needed"}

parse_postgresql_uri!(uri_str)

parse_telemetry_url(str)

@spec parse_telemetry_url(binary()) :: {:ok, binary()} | {:error, binary()}

parse_telemetry_url!(str)

persist_installation_id(persistent_kv, instance_id)

@spec persist_installation_id(term(), binary()) :: instance_id()

persistent_kv()

validate_security_config!(secret, insecure)