File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * Enable experimental support for models to connect to and query databases
2+ with different adapters.
3+
4+ Previously, models cached many adapter specific values which would prevent
5+ making queries against different database types. Now, those caches are per
6+ ` schema-context ` , which can be configured in ` database.yml ` :
7+
8+ ``` yaml
9+ primary :
10+ adapter : trilogy
11+ database : myapp_development
12+ primary_pg :
13+ adapter : postgresql
14+ database : myapp_development
15+ schema_context : pg
16+ ` ` `
17+
18+ This enables models to connect to both MySQL and PostgreSQL databases in the
19+ same application, and query them successfully:
20+
21+ ` ` ` ruby
22+ class User < ApplicationRecord
23+ connects_to shards : {
24+ mysql : { writing: :primary, reading: :primary },
25+ pg : { writing: :primary_pg, reading: :primary_pg },
26+ }
27+ end
28+
29+ User.connected_to(shard : :mysql) { User.first } # queries MySQL
30+ User.connected_to(shard : :pg) { User.first } # queries PostgreSQL
31+ ` ` `
32+
33+ *Hartley McGuire*
34+
135* Support PostgreSQL ` RESET` on readonly queries.
236
337 ` ` ` ruby
You can’t perform that action at this time.
0 commit comments