DBX supports multi-connections to the database. It is just a light crystal-db overlay.
require "dbx"
require "pg" # <= PostgreSQL driver
require "sqlite3" # <= SQLite driver
# Create 4 DB connection pool (3 PostgreSQL and 1 SQLite)
DBX.open("app", "postgres://...")
DBX.open("reader", "postgres://...")
DBX.open("writer", "postgres://...")
DBX.open("local", "sqlite3://./data.db")
# Connection: app (using PostgreSQL)
DBX.db("app")
# Connection: local (using SQLite)
DBX.db("local")
# Connection: reader (using PostgreSQL)
DBX.db("reader")
# Connection: writer (using PostgreSQL)
DBX.db("writer")
You can use each DBX connection as you do with crystal-db
(example: DBX.db("app").query "select id, created_at, email from users"
).
The next chapter explores database querying, an essential chapter to take advantage of DBX's powerful querying capabilities.