This file contains 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
require 'rom' | |
require 'anima' | |
class User | |
include Anima.new(:id, :name, :tasks) | |
end | |
class Task | |
include Anima.new(:title) | |
end |
This file contains 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
$LOAD_PATH.unshift './lib' | |
require 'axiom-sql-generator' | |
users = Axiom::Relation::Base.new(:users, [[:id, Integer], [:name, String]]) | |
def compile_sql(relation) | |
sql_ast = Axiom::SQL::Processor.call(relation) | |
sql_str = SQL::Generator.generate(sql_ast) |
This file contains 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
Bundler could not find compatible versions for gem "rspec-core": | |
In Gemfile: | |
mutant-rspec (>= 0) ruby depends on | |
rspec-core (~> 2.14.1) ruby | |
rspec-rails (~> 3.0) ruby depends on | |
rspec-core (3.0.2) |
This file contains 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
# https://github.com/rom-rb/rom/blob/reboot/benchmarks/basic.rb | |
Calculating ------------------------------------- | |
schema.users.to_a 20 i/100ms | |
mappers.users.to_a 17 i/100ms | |
ARUser.all.to_a 10 i/100ms | |
------------------------------------------------- | |
schema.users.to_a 210.7 (±9.5%) i/s - 1060 in 5.074291s | |
mappers.users.to_a 173.8 (±9.2%) i/s - 867 in 5.026702s | |
ARUser.all.to_a 102.3 (±5.9%) i/s - 510 in 5.004413s |
This file contains 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
# without unique column names this is what you need to do to make sure the result set has correct values and there | |
# are no name clashes | |
DB[:users]. | |
join_table(:inner, :tasks, user_id: :users__id). | |
select(:tasks__id___task_id, :users__id___users_id) | |
# versus this, if we had unique column names by default | |
DB[:users].natural_join(:tasks).select(:task_id, :user_id) |
This file contains 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
class Result | |
attr_reader :value, :error | |
class Success < Result | |
def initialize(value) | |
@value = value | |
end | |
def >(f) | |
f.call(value) |
This file contains 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
require 'virtus' | |
class Money | |
include Virtus.value_object | |
values do | |
attribute :amount, Integer | |
attribute :currency, String | |
end | |
end |
This file contains 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
class ArrayAdapter < ROM::Adapter | |
def self.schemes | |
[:array] | |
end | |
def initialize(uri) | |
super | |
@connection = {} | |
end |
This file contains 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
-- create_table(:users) | |
-> 0.0039s | |
LOADED 1000 users via ROM/Sequel | |
LOADED 1000 users via ActiveRecord | |
Calculating ------------------------------------- | |
rom.read(:user_json).all.to_a | |
16 i/100ms | |
ARUser.all.map(&:as_json) | |
3 i/100ms | |
------------------------------------------------- |
This file contains 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
Calculating ------------------------------------- | |
[ROM] Loading 1k user objects | |
29 i/100ms | |
[AR] Loading 1k user objects | |
9 i/100ms | |
------------------------------------------------- | |
[ROM] Loading 1k user objects | |
277.2 (±6.5%) i/s - 1392 in 5.040249s | |
[AR] Loading 1k user objects | |
111.0 (±9.0%) i/s - 558 in 5.071423s |
OlderNewer