Skip to content

Instantly share code, notes, and snippets.

View flash-gordon's full-sized avatar
🔪
Working on sharp tools

Nikita Shilnikov flash-gordon

🔪
Working on sharp tools
View GitHub Profile
@flash-gordon
flash-gordon / env_validation.rb
Created September 18, 2016 10:14
ENV validation POC
require 'dry-validation'
class EnvValidation
class ENV
def inspect
ivs = instance_variables.each { |v| "#{v}=#{instance_variable_get(v)}" }.join(', ')
"ENV[#{ivs}]"
end
def to_s
Sequel.migration do
up do
create_table(:users) do
primary_key :id
String :first_name, null: false, limit: 100
String :last_name, null: false, limit: 100
String :middle_name, null: true, limit: 100
String :email, null: false, limit: 500
String :role, null: true, limit: 50
#!/usr/bin/env ruby
require "rom-sql"
require "rom-repository"
require "byebug"
module Persistence
module Relations
class Configurations < ROM::Relation[:sql]
gateway :bonuses
#!/usr/bin/env ruby
require "bundler/setup"
require "rom-repository"
config = ROM::Configuration.new(:sql, 'postgres://localhost/rom_repository')
config.relation(:books) do
schema(:books) do
attribute :id, ROM::SQL::Types::Serial
#!/usr/bin/env ruby
require "bundler/setup"
require "rom-repository"
config = ROM::Configuration.new(:sql, 'postgres://localhost/rom_repository')
config.relation(:books) do
schema(:books) do
attribute :id, ROM::SQL::Types::Serial
require 'rom-sql'
require 'rom-repository'
rom = ROM.container(:sql, 'sqlite::memory') do |c|
c.gateways[:default].create_table :events do
primary_key :id
column :event_no, Integer
end
c.gateways[:default].create_table :orders do
require 'rom'
require 'rom-sql'
DB = Sequel.connect('postgres://localhost/rom_sql')
DB.execute('create extension if not exists hstore ')
DB.drop_table?(:strings)
DB.create_table(:strings) do
primary_key(:id)
hstore :value
users:
- name: 'Jane'
email: '[email protected]'
- name: 'John'
email: '[email protected]'
class Jobs < ROM::Relation[:sql]
schema(:jobs) do
# ...
associations do
belongs_to :team
belongs_to :template
belongs_to :address
belongs_to :client
end
require 'rom'
require 'rom-repository'
require 'sqlite3'
rom = ROM.container(:sql, 'sqlite::memory') do |conf|
conf.default.create_table(:bookings) do
primary_key :booking_id
end
conf.default.create_table(:tickets) do