aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/arel/select_manager_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* fix a typoyamato-payforward2019-07-311-1/+1
|
* Remove unused `DepthFirst` visitorRyuta Kamizono2019-06-151-10/+0
| | | | | | | | | | | | | We only use `ToSQL` visitors in the our codebase, do not use `DepthFirst` and `Dot` visitors. The `DepthFirst` visitor (which was introduced at c86c37e5f) is used to traverse an Arel (partial) ast with depth first. Is there any worth to keep that undocumented feature with much code and test cases. This removes that unused `DepthFirst` code and test cases.
* Add Relation#annotate for SQL commentingMatt Yoho2019-03-211-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Abandon TOP support.Vladimir Kochnev2018-09-251-2/+2
| | | | | | | | | | | | | | | | Initially, `TOP` was introduced to support `limit` for MSSQL database. Unlike PostgreSQL/MySQL/SQLite, MSSQL does not have native `LIMIT`/`OFFSET` support. The commit adding `TOP` is 1a246f71616cf246a75ef6cbdb56032e43d4e643. However, it figured out that `TOP` implementation was weak and it's not sufficient to also support `OFFSET`, then `TOP` was substituted with `ROW_NUMBER()` subquery in be48ed3071fd6524d0145c4ad3faeb4aafe3eda3. This is a well known trick in MSSQL - https://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server. So now we don't need this `visit_Arel_Nodes_Top` at all. It does nothing useful but also adds an extra space after `SELECT` when `LIMIT` is being used for **any** database.
* Fix a wrong correctionKazuhiro Sera2018-08-081-1/+1
|
* Fix the obvious typos detected by github.com/client9/misspellKazuhiro Sera2018-08-081-1/+1
|
* Enable `Layout/EmptyLinesAroundBlockBody` to reduce review cost in the futureRyuta Kamizono2018-07-121-11/+0
| | | | | | | We sometimes ask "✂️ extra blank lines" to a contributor in reviews like https://github.com/rails/rails/pull/33337#discussion_r201509738. It is preferable to deal automatically without depending on manpower.
* Make `Arel::Test` subclass of `ActiveSupport::TestCase`Yasuo Honda2018-05-011-1/+1
| | | | | | | | | | not `Minitest::Test` to address `CustomCops/RefuteNot` and `CustomCops/AssertNot` offenses for Arel test cases Also including `ActiveSupport::Testing::Assertions` to `Arel::Spec` and add test/unit backwards compatibility methods Fixes #32720
* Arel: rubocop -aMatthew Draper2018-02-241-244/+244
|
* Merge Arel into Active RecordMatthew Draper2018-02-241-0/+1236