Skip to content
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

empty array encoding compatibility with Sequel and ActiveRecord #14

Merged
merged 2 commits into from Feb 20, 2020

Conversation

@ermolaev
Copy link
Contributor

ermolaev commented Feb 20, 2020

Sequel

DB.fetch("SELECT ?", []).sql
=> "SELECT (NULL)"

ActiveRecord

Product.find_by_sql(['select ? ', []])
  Product Load (0.7ms)  select NULL
@@ -50,19 +50,19 @@ def quoted_date(value)

def quote_val(value)
case value
when String then "'#{conn.escape_string(value.to_s)}'"

This comment has been minimized.

Copy link
@ermolaev

ermolaev Feb 20, 2020

Author Contributor

these are commonly used types, for performance, they should be placed on top

var = 2

Benchmark.ips do |r|
  r.report('bottom') do |n|
    while n > 0
      case var
      when String  then 1
      when Array   then 1
      when Symbol  then 1
      when Numeric then 1
      end
      n -= 1
    end
  end
  r.report('top') do |n|
    while n > 0
      case var
      when Numeric then 1
      when String  then 1
      when Array   then 1
      when Symbol  then 1
      end
      n -= 1
    end
  end
  r.compare!
end
# Comparison:
#                  top: 18495320.6 i/s
#               bottom:  5602695.7 i/s - 3.30x  slower
@SamSaffron
Copy link
Member

SamSaffron commented Feb 20, 2020

Thanks @ermolaev ! change looks good to me

@SamSaffron SamSaffron merged commit e5d394f into discourse:master Feb 20, 2020
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.