Configure Database Connection

This guide shows you how to configure your database connection in CQL.

Basic PostgreSQL Connection

require "cql"
require "pg"

MyDB = CQL::Schema.define(
  :my_db,
  adapter: CQL::Adapter::Postgres,
  uri: "postgres://username:password@localhost:5432/myapp_development"
) do
end

MyDB.init

Basic SQLite Connection

require "cql"
require "sqlite3"

MyDB = CQL::Schema.define(
  :my_db,
  adapter: CQL::Adapter::SQLite,
  uri: "sqlite3://./db/development.db"
) do
end

MyDB.init

Basic MySQL Connection

Use Environment Variables

Connection String Format

PostgreSQL

MySQL

SQLite

Test Connection

Connection with Options (PostgreSQL)

Create Database Directory (SQLite)

Multiple Databases

Verify Connection

Last updated

Was this helpful?