Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (32 sloc) 1.35 KB


Crecto::Repo maps the database to the database adapter, and is used to run queries on models. If connections to multiple databases is required, just create a separate Repo for each. The config block defines how the repo connects to the database.

module MyRepo
    extend Crecto::Repo
    config do |conf|
        conf.adapter = Crecto::Adapters::Postgres
        # or Crecto::Adapters::Mysql, Crecto::Adapters::SQLite3
        conf.hostname = "localhost"
        conf.database = "my_database"

module AnotherRepo
    extend Crecto::Repo
    config do |conf|
        conf.adapter = Crecto::Adatperes::SQLite3
        conf.database = "./my_db.db"

config options, all of the options from crystal-db database are implemented:

  • adapter - Specify the Crecto adapter to use: Crecto::Adapters::Postgres, Crecto::Adapters::Mysql, Crecto::Adapters::SQLite3
  • checkout_timeout
  • database - database name
  • password - database password
  • username - database username
  • uri - full uri to database, can include all config options (i.e. postgres://user@pass:localhost:5432/my_db?initial_pool_size=10&retry_attemps=5)
  • hostname - database host name
  • initial_pool_size
  • max_pool_size
  • retry_attempts
  • retry_delay
You can’t perform that action at this time.