async-matrixSourceAsyncMatrixBridgeDiscordDBConnection

module Connection

Establishes a Sequel database connection from the bridge config's database section.

Supports both SQLite (with foreign keys and WAL mode) and PostgreSQL, matching the mautrix bridgev2 database config schema.

db = Connection.establish(config.database) db[:users].all # => [...]

Nested

Definitions

def self.establish(database_config)

Establish a database connection from a config.database section.

Implementation

def self.establish(database_config)
  type = database_config.type || SQLITE_TYPE
  uri  = database_config.uri  || "sqlite://bridge.db"

  db = case type
       when SQLITE_TYPE
         connect_sqlite(uri, database_config)
       when POSTGRES_TYPE
         connect_postgres(uri, database_config)
       else
         raise ArgumentError, "Unknown database type: #{type.inspect}. Expected #{SQLITE_TYPE.inspect} or #{POSTGRES_TYPE.inspect}."
       end

  db
end