1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/lib/active_record
Matt Yoho f41825809c Add Relation#annotate for SQL commenting
This patch has two main portions:

1. Add SQL comment support to Arel via Arel::Nodes::Comment.
2. Implement a Relation#annotate method on top of that.

== Adding SQL comment support

Adds a new Arel::Nodes::Comment node that represents an optional SQL
comment and teachers the relevant visitors how to handle it.

Comment nodes may be added to the basic CRUD statement nodes and set
through any of the four (Select|Insert|Update|Delete)Manager objects.

For example:

    manager = Arel::UpdateManager.new
    manager.table table
    manager.comment("annotation")
    manager.to_sql # UPDATE "users" /* annotation */

This new node type will be used by ActiveRecord::Relation to enable
query annotation via SQL comments.

== Implementing the Relation#annotate method

Implements `ActiveRecord::Relation#annotate`, which accepts a comment
string that will be appeneded to any queries generated by the relation.

Some examples:

    relation = Post.where(id: 123).annotate("metadata string")
    relation.first
    # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123
    # LIMIT 1 /* metadata string */

    class Tag < ActiveRecord::Base
      scope :foo_annotated, -> { annotate("foo") }
    end
    Tag.foo_annotated.annotate("bar").first
    # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */

Also wires up the plumbing so this works with `#update_all` and
`#delete_all` as well.

This feature is useful for instrumentation and general analysis of
queries generated at runtime.
2019-03-21 20:30:56 -07:00
..
associations Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
attribute_methods Fix query attribute method on user-defined attribute to be aware of typecasted value 2019-03-11 00:51:33 +09:00
coders
connection_adapters Extract sanitize_as_sql_comment from SQL visitor into connection 2019-03-19 04:15:52 +09:00
database_configurations Fix document formatting of Database configuration classes [ci skip] 2019-03-21 14:02:34 +09:00
fixture_set
locale
locking
middleware Fix typo a -> an, an -> a [ci skip] 2019-02-11 17:03:10 +09:00
migration Allow remove_foreign_key with both to_table and options 2019-03-06 23:45:08 +09:00
railties Allow truncate for SQLite3 adapter and add rails db:seed:replant (#34779) 2019-03-04 14:57:38 -08:00
relation Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
scoping Merge pull request #35121 from utilum/warning_tried_to_create_proc_without_block 2019-03-10 16:31:15 +01:00
tasks Tweak truncate_tables 2019-03-18 00:21:40 +09:00
type
type_caster
validations Merge pull request #35503 from samjohn/cannot-grammar-correction 2019-03-07 10:50:15 +01:00
aggregations.rb
association_relation.rb
associations.rb Improve doc of automatic inverse_of detection 2019-03-08 09:50:45 +01:00
attribute_assignment.rb
attribute_decorators.rb
attribute_methods.rb Give GeneratedAttributeMethods module a name 2019-03-13 10:34:15 +09:00
attributes.rb Document option forwarding in ActiveRecord::Base.attribute 2019-03-20 15:05:31 -04:00
autosave_association.rb
base.rb
callbacks.rb Should not pass extra args to _update_record 2019-02-21 21:59:31 +09:00
collection_cache_key.rb
connection_handling.rb Invalidate query cache for all connections in the current thread 2019-02-01 16:05:25 -05:00
core.rb Enable SQL statement cache for find on base class as with find_by 2019-03-01 16:28:32 +09:00
counter_cache.rb
database_configurations.rb Fix document formatting of Database configuration classes [ci skip] 2019-03-21 14:02:34 +09:00
define_callbacks.rb
dynamic_matchers.rb
enum.rb Add negative scopes for all enum values (#35381) 2019-02-26 12:47:27 -08:00
errors.rb Replace “can not” with “cannot”. 2019-03-06 16:35:52 -05:00
explain.rb
explain_registry.rb
explain_subscriber.rb
fixtures.rb
gem_version.rb Prep release 2019-03-11 11:58:15 -04:00
inheritance.rb Use placeholder for type_condition predicate 2019-02-18 01:39:06 +09:00
insert_all.rb Bulk Insert: Reuse indexes for unique_by 2019-03-20 13:28:18 +01:00
integration.rb Remove ability to specify a timestamp name for #cache_key 2019-01-17 16:08:32 -05:00
internal_metadata.rb
legacy_yaml_adapter.rb
log_subscriber.rb
migration.rb Allow remove_foreign_key with both to_table and options 2019-03-06 23:45:08 +09:00
model_schema.rb
nested_attributes.rb
no_touching.rb
null_relation.rb
persistence.rb [ci skip] Documentation pass for insert_all etc. 2019-03-20 13:28:18 +01:00
query_cache.rb
querying.rb Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
railtie.rb Rename database_operations config to *_context 2019-02-07 15:41:43 -08:00
readonly_attributes.rb
reflection.rb Fix eager loading polymorphic association with mixed table conditions 2019-02-18 00:41:43 +09:00
relation.rb Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
result.rb
runtime_registry.rb
sanitization.rb Quote empty ranges like other empty enumerables 2019-03-07 19:22:29 -05:00
schema.rb
schema_dumper.rb
schema_migration.rb
scoping.rb Revert "Merge pull request #35186 from kamipo/fix_leaking_scope_on_relation_create" 2019-02-15 12:06:45 +09:00
secure_token.rb
serialization.rb
statement_cache.rb Ruby 2.7 warning: creating a Proc without a block 2019-02-13 02:11:21 +01:00
store.rb
suppressor.rb
table_metadata.rb
test_databases.rb
test_fixtures.rb Eagerly materialize the fixtures transaction 2019-01-29 16:10:47 +01:00
timestamp.rb Should not pass extra args to _update_record 2019-02-21 21:59:31 +09:00
touch_later.rb
transactions.rb
translation.rb
type.rb
type_caster.rb
validations.rb
version.rb