Skip to content

Commit

Permalink
Automatically load the sql_comments Database extension when loading t…
Browse files Browse the repository at this point in the history
…he sql_comments model plugin

Previously, users had to do this manually, but this makes it easier
for users, and there a number of other plugins that take this
approach.
  • Loading branch information
jeremyevans committed Feb 14, 2025
1 parent 03d32d2 commit d17d0d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Automatically load the sql_comments Database extension when loading the sql_comments model plugin (jeremyevans) (#2276)

* Support :pg_auto_parameterize_min_array_size Database option in pg_auto_parameterize_in_array extension to control minimum array size to handle (jeremyevans)

* Add pg_eager_any_typed_array plugin, automatically transform eager loads to use = ANY(array_expr::type[]) instead of IN (value_list) (jeremyevans)
Expand Down
7 changes: 6 additions & 1 deletion lib/sequel/plugins/sql_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module Plugins
# Album.sql_comments_dataset_methods :to_csv # csv_serializer plugin
#
# In order for the sql_comments plugin to work, the sql_comments
# Database extension must be loaded into the model's database.
# Database extension must be loaded into the model's database, so
# loading the plugin does this automatically.
#
# Note that in order to make sure SQL comments are included, some
# optimizations are disabled if this plugin is loaded.
Expand All @@ -67,6 +68,10 @@ def self.def_sql_commend_method(mod, model, method_type, meth)
# :nocov:
end

def self.apply(model)
model.db.extension(:sql_comments)
end

def self.configure(model)
model.send(:reset_fast_pk_lookup_sql)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/extensions/sql_comments_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe "sql_comments plugin " do
before do
@db = Sequel.mock(:fetch=>{:id=>1, :name=>'a'}).extension(:sql_comments)
@db = Sequel.mock(:fetch=>{:id=>1, :name=>'a'})
@c = Class.new(Sequel::Model(@db[:t]))
@c.columns :id, :name
def @c.to_s; 'C' end
Expand Down

0 comments on commit d17d0d1

Please sign in to comment.