Created
March 24, 2015 23:34
-
-
Save ginjo/a399ca8a146ca6159451 to your computer and use it in GitHub Desktop.
ROM swappable datastore example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Swappable datastore example | |
| ROM_ADAPTER = :sql # or :memory | |
| # ...setup | |
| class UsersSql < ROM::Relation[:sql] | |
| dataset :users | |
| def by_name(name) | |
| where(name: name) | |
| end | |
| end if ROM_ADAPTER == :sql | |
| class UsersMemory < ROM::Relation[:memory] | |
| dataset :users | |
| def by_name(name) | |
| restrict(name: name) | |
| end | |
| end if ROM_ADAPTER == :memory | |
| # ...finalize | |
| @users = ROM.env.relation(:users) | |
| @users.by_name('bill') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment