Closed ollym closed 1 year ago
Hmm, for me this returns the latter when reusing the connection:
require "active_record"
require "sequel"
require "pg"
ActiveRecord.version # => #<Gem::Version "7.0.4">
Sequel.version # => "5.63.0"
Gem::Specification.find_by_name("sequel-activerecord_connection").version # => #<Gem::Version "1.2.9">
PG::VERSION # => "1.4.4"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "rodauth_demo_development")
db = Sequel.postgres(extensions: [:activerecord_connection])
db['SELECT TRUE'].prepare(:select, :select_true).call # => [{:bool=>true}]
@janko Only difference I can see is the Rails version:
ActiveRecord.version # => #<Gem::Version "6.1.7">
Sequel.version # => "5.63.0"
Gem::Specification.find_by_name("sequel-activerecord_connection").version # => #<Gem::Version "1.2.9">
PG::VERSION # => "1.4.5"
db = Sequel.postgres(extensions: [:activerecord_connection])
db['SELECT TRUE'].prepare(:select, :select_true).call # => [{:bool=>false}]
And without using prepared statements it works:
ActiveRecord.version # => #<Gem::Version "6.1.7">
Sequel.version # => "5.63.0"
Gem::Specification.find_by_name("sequel-activerecord_connection").version # => #<Gem::Version "1.2.9">
PG::VERSION # => "1.4.5"
db = Sequel.postgres(extensions: [:activerecord_connection])
db['SELECT TRUE'].all # => [{:bool=>true}]
Let me know if you can't recreate it and i'll dig deeper
I was able to reproduce it 👍🏻 The difference is the sequel_pg
gem that Sequel automatically loads when available, and I have it installed locally. When I set ENV["NO_SEQUEL_PG"] = "1"
, I get your behavior. I'll investigate.
Adding gem 'sequel_pg', require: false
fixed it, would you recommend that we use that regardless?
I would generally recommend it for performance, mainly if you're doing bigger selects, and if you want to use streaming.
I discovered the issue, it's related to the discrepancy in type maps between Active Record in Sequel. I already bridged this difference for normal queries, but this code wasn't getting called for prepared statements. I'll push a fix shortly.
Thanks @janko hope you're otherwise well.
For whatever reason, this is the case:
Without using the extension, it works fine: