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
query_decorator #13
query_decorator #13
Conversation
Is decorating the results of a query difficult at the moment? I've been thinking about doing this sort of thing with |
please see PR code https://github.com/discourse/mini_sql/pull/13/files I added info to readme and benchmarks |
I really like the design here and feel it keeps with the design of mini_racer and performance goals. Mixed on just supporting @davidtaylorhq what do you think about this change? |
2.5.5
2.6.5
2.7.0
code module MiniSql
module Postgres
class Connection < MiniSql::Connection
def query2(sql, *params, decorator: nil)
[sql, params, decorator]
end
def query_decorator(decorator, sql, *params)
[sql, params, decorator]
end
end
end
end
Benchmark.ips do |r|
r.stats = :bootstrap
r.confidence = 99
r.report('query2') do |n|
while n > 0
$mini_sql.query2('select id, title from topics order by id limit 1000', decorator: TopicDecorator)
n -= 1
end
end
r.report('query_decorator') do |n|
while n > 0
$mini_sql.query_decorator(TopicDecorator, 'select id, title from topics order by id limit 1000')
n -= 1
end
end
r.compare!
end |
Nice @ermolaev , I agree the non kwarg api is the way to go. |
also I think that $mini_sql.query_decorator(TopicDecorator, <<~SQL, param1: 'val1', param2: 'val2', param3: 'val3', param4: 'val4')
big sql
SQL
$mini_sql.query(<<~SQL, param1: 'val1', param2: 'val2', param3: 'val3', param4: 'val4', decorator: TopicDecorator)
big sql
SQL |
Thanks, yeah I agree, this api does read nicely. |
reworked #7