Created
February 7, 2017 16:14
-
-
Save flash-gordon/1cf5bca1468b6e24823d282e4e9af07c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require "rom-sql" | |
require "rom-repository" | |
require "byebug" | |
module Persistence | |
module Relations | |
class Configurations < ROM::Relation[:sql] | |
gateway :bonuses | |
schema(:bns_configurations, infer: true, as: :configurations) do | |
associations do | |
has_many :rush_hours_configuration | |
has_many :global_checks_configuration | |
end | |
end | |
end | |
end | |
end | |
config = ROM::Configuration.new(default: [:sql, "sqlite::memory"], | |
bonuses: [:sql, "postgres://localhost/rom_sql"]) | |
config.gateways[:bonuses].tap do |gateway| | |
migration = gateway.migration do | |
change do | |
create_table :bns_configurations do | |
primary_key :id | |
end | |
end | |
end | |
migration.apply gateway.connection, :up | |
end | |
config.register_relation Persistence::Relations::Configurations | |
container = ROM.container(config) | |
puts container.relations[:configurations].class.dataset # => bns_configurations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment