-
Notifications
You must be signed in to change notification settings - Fork 8
Examples #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@TheFox there are two basic options you have: define all relations in a single file or create separate files per relation. data.yml users:
- name: 'Jane'
email: '[email protected]'
- name: 'John'
email: '[email protected]' require 'rom-yaml'
rom = ROM.container(:yaml, File.join(__dir__, 'data.yml')) do |c|
c.relation(:users) do
schema do
attribute :name, ROM::Types::String
attribute :email, ROM::Types::String
end
end
end
p rom.relation(:users).to_a
# [{:name=>"Jane", :email=>"[email protected]"}, {:name=>"John", :email=>"[email protected]"}] or as always you can make a separate class require 'rom-yaml'
class Users < ROM::Relation[:yaml]
dataset :users
schema do
attribute :name, ROM::Types::String
attribute :email, ROM::Types::String
end
end
rom = ROM.container(:yaml, File.join(__dir__, 'data.yml')) do |c|
c.register_relation(Users)
end
p rom.relation(:users).to_a
# [{:name=>"Jane", :email=>"[email protected]"}, {:name=>"John", :email=>"[email protected]"}] |
@flash-gordon Thank you for your fast response. How would it look like if I doesn't already have a |
@flash-gordon I see. Thank you for your help. |
Where can I find examples of a real usecase?
spec/integration/adapter_spec.rb
is not really an example code. It is not helpful. How can I create a new yaml file for a Relation using the YAML Gateway?The text was updated successfully, but these errors were encountered: