Skip to content

Instantly share code, notes, and snippets.

View solnic's full-sized avatar

Peter Solnica solnic

View GitHub Profile
@solnic
solnic / try_spec.rb
Created December 2, 2014 11:01
kleisli-inspired spike for handling inserts with associations in rom-rb
class Result
attr_reader :value, :error
class Success < Result
def initialize(value)
@value = value
end
def >(f)
f.call(value)
# 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)
@solnic
solnic / gist:2a2151b7b67e6d1f8447
Last active August 29, 2015 14:07
Sequel-powered ROM vs AR benchmark
# 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
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)
require 'pathname'
ROOT = Pathname(__FILE__).expand_path.join('../..')
require 'rom'
class Post
include Equalizer.new :id, :title, :body, :comments
attr_accessor :id, :title, :body, :comments
end
@solnic
solnic / axiom_sql_generator.rb
Created April 27, 2014 20:16
Progress on new axiom SQL generator
$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)
@solnic
solnic / rom_mapper_and_anima.rb
Last active August 29, 2015 13:59
ROM mapper with anima model
require 'rom'
require 'anima'
class User
include Anima.new(:id, :name, :tasks)
end
class Task
include Anima.new(:title)
end

Too long for a tweet...so, I tweeted this:

"One trend I'm observing is a lot of rubyists being fed up with messy ruby ecosystem are getting excited or even switch to clojure."

People asked me to comment further, so here it goes. First of all I said I'm seeing a trend, which is a fact. I know people who are learning Clojure (and other languages like some people pointed out) hoping to switch from Ruby or they even already left Ruby. Those people got tired of something I called "a messy ecosystem". Maybe not the best selection of words, I dunno. I meant that some people, myself included, find ruby ecosystem - which consists of multiple VMs, practically one web framework and a gazillion of libraries from which huge amount are only semi-working - to be a mess where it's hard to pick up a solid stack to solve bigger problems.

I really don't have time (which is a shame) to come up with some specific details. I could maybe only quickly describe what we're dealing with now at gitorious.org which is being upgraded t

ROM::Relation#delete:/mnt/hgfs/!%home!%vagrant!%rom-rb/rom/rom-relation/lib/rom/relation.rb:144
................
(16/16) 100% - 4.84s
ROM::Relation#drop:/mnt/hgfs/!%home!%vagrant!%rom-rb/rom/rom-relation/lib/rom/relation.rb:249
...........
(11/11) 100% - 3.22s
ROM::Relation#each:/mnt/hgfs/!%home!%vagrant!%rom-rb/rom/rom-relation/lib/rom/relation.rb:85
.........................
(25/25) 100% - 6.81s
ROM::Relation#first:/mnt/hgfs/!%home!%vagrant!%rom-rb/rom/rom-relation/lib/rom/relation.rb:214