Skip to content

Instantly share code, notes, and snippets.

@y-yagi
Created August 15, 2016 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-yagi/6a9b29087d01f8a84bc88b913c17472e to your computer and use it in GitHub Desktop.
Save y-yagi/6a9b29087d01f8a84bc88b913c17472e to your computer and use it in GitHub Desktop.
require 'rom-sql'
class Users < ROM::Relation[:sql]
schema(infer: true)
def by_id(id)
where(id: id)
end
end
container = ROM.container(:sql, 'sqlite::memory') do |conf|
conf.default.connection.create_table(:users) do
primary_key :id
column :name, String, null: false
column :email, String, null: false
end
conf.register_relation(Users)
end
container.relations.users.insert(name: "Malcolm", email: "malcolm@example.com")
puts container.relations.users.where(id: 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment