Skip to content

Instantly share code, notes, and snippets.

@katafrakt
Created October 27, 2017 18:12
Show Gist options
  • Save katafrakt/c7a35c70f09dc267dfba1876e9ef6d7d to your computer and use it in GitHub Desktop.
Save katafrakt/c7a35c70f09dc267dfba1876e9ef6d7d to your computer and use it in GitHub Desktop.
require 'rom'
require 'rom/sql'
require 'pg'
# Assuming a database with tables 'users' and 'projects'
rom = ROM.container(:sql, 'postgres://localhost/test')
#
# # Perhaps one Repo to handle users
class UserRepo < ROM::Repository[:users]
end
#
# # Another repository could handle the projects
class ProjectRepo < ROM::Repository[:projects]
end
#
user_repo = UserRepo.new(rom)
project_repo = ProjectRepo.new(rom)
/tmp  psql test  ✓  20:10:22
psql (10.0, server 9.6.2)
Type "help" for help.
test=# \dt
List of relations
Schema | Name | Type | Owner
--------+-------+-------+-------
public | users | table | pawel
(1 row)
test=# \q
/tmp  ruby rom-test.rb  ✓  20:10:28
/Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-core-4.0.1/lib/rom/registry.rb:66:in `block in fetch': :users doesn't exist in ROM::RelationRegistry registry (ROM::ElementNotFoundError)
from /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-core-4.0.1/lib/rom/registry.rb:63:in `fetch'
from /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-core-4.0.1/lib/rom/registry.rb:63:in `fetch'
from /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-repository-2.0.0/lib/rom/repository/relation_reader.rb:15:in `set_relation'
from /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-repository-2.0.0/lib/rom/repository/root.rb:62:in `initialize'
from /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-repository-2.0.0/lib/rom/repository/class_interface.rb:42:in `new'
from /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rom-repository-2.0.0/lib/rom/repository/class_interface.rb:42:in `new'
from rom-test.rb:16:in `<main>'
/tmp  ruby --version  1 ↵  20:10:30
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
/tmp  gem list | grep rom  ✓  20:10:35
rom (4.0.1)
rom-changeset (1.0.0)
rom-core (4.0.1)
rom-mapper (1.0.1)
rom-repository (2.0.0)
rom-sql (2.1.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment