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 MyRepoextend Crecto::Repoconfig do |conf|conf.adapter = Crecto::Adapters::Postgres# or Crecto::Adapters::Mysql, Crecto::Adapters::SQLite3conf.hostname = "localhost"conf.database = "my_database"endendmodule AnotherRepoextend Crecto::Repoconfig do |conf|conf.adapter = Crecto::Adatperes::SQLite3conf.database = "./my_db.db"endend
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