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

Add querying and additional context to the enhanced Arel AST #106

Merged
merged 24 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
24bc523
WIP: Add query methods to the transformer AST
mvgijssel Jul 24, 2019
43b1ec4
Merge branch 'master' into 103/query-arel-transformer-ast
mvgijssel Jul 26, 2019
18a006a
Add contextual information to transformer nodes
mvgijssel Jul 26, 2019
1354ce9
Extracted context enhancer for Arel::Table
mvgijssel Jul 26, 2019
21bd87a
Sort rubocop
mvgijssel Jul 26, 2019
71ad35e
Fixed lint issues
mvgijssel Jul 26, 2019
0a1e052
Moved the context enhancer spec
mvgijssel Jul 26, 2019
8dee854
Fixed exception message in ArelTable context enhancer
mvgijssel Jul 26, 2019
14ab884
Fix comparison for select,update,insert and delete manager
mvgijssel Jul 28, 2019
b49a7e4
Added .query method to Node
mvgijssel Jul 28, 2019
852f878
Added AddchemaToTable transformer
mvgijssel Jul 28, 2019
c10744e
Add the required require
mvgijssel Jul 28, 2019
89021d5
Hack to support context argument
mvgijssel Jul 29, 2019
efb24ba
Add support for schemas in function calls
mvgijssel Jul 30, 2019
1b0e0cf
Added specs for updated tree managers
mvgijssel Jul 30, 2019
5501264
Added specs for the error branches of FuncCall
mvgijssel Jul 30, 2019
9380796
Add missing attributes to the SelectCore dot visitor
mvgijssel Jul 30, 2019
31c0503
Added TODO to Arel middleware
mvgijssel Jul 30, 2019
bd15cf2
Added specs for ArelTable context enhancer
mvgijssel Jul 30, 2019
efd17cb
Remove TODO
mvgijssel Jul 30, 2019
6c0b4f9
Remove comments
mvgijssel Jul 30, 2019
870aef1
Added specs for Query
mvgijssel Jul 30, 2019
8d7226b
Updated specs for AddSchemaToTable
mvgijssel Jul 30, 2019
cde022d
Remove broken spec
mvgijssel Jul 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/arel/sql_to_arel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@
pg_node: 'PgQuery::RANGE_SUBSELECT'
visit 'select', '1 FROM "public"."table_is_range_var" "alias", ONLY "b"',
pg_node: 'PgQuery::RANGE_VAR'
# TODO: this one breaks
# visit 'select', '1 FROM "b", (SELECT 1) "a", "c"', pg_node: 'PgQuery::RANGE_VAR'
visit 'select', '1', pg_node: 'PgQuery::RAW_STMT'
visit 'sql', 'REFRESH MATERIALIZED VIEW view WITH NO DATA',
pg_node: 'PgQuery::REFRESH_MAT_VIEW_STMT',
Expand Down
55 changes: 55 additions & 0 deletions spec/arel/transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,59 @@

expect(original_arel).to be_identical_arel(new_arel)
end

it 'replaces table references with subqueries' do
sql = <<~SQL
SELECT
COUNT(posts.id),
ARRAY_AGG(posts.title)
FROM
posts
INNER JOIN
comments
ON
comments.post_id = posts.id
AND
comments.message ILIKE '%hello%'
WHERE
posts.public = TRUE
AND
posts.id IN (SELECT id FROM posts WHERE id = 3)
GROUP BY
comments.created_at
SQL

# sql = <<~SQL
# SELECT
# id
# FROM
# posts
# SQL

# sql = <<~SQL
# SELECT
# id
# FROM
# (SELECT id FROM posts) posts,
# users
# SQL

# sql = <<~SQL
# SELECT
# id
# FROM
# users,posts
# SQL

# only the tables inside JOIN and FROM should be replaced
# tables inside the JOIN ... ON expression should not be replaced

arel = Arel.sql_to_arel(sql)
tree = Arel.transformer(arel.first)

binding.pry
mvgijssel marked this conversation as resolved.
Show resolved Hide resolved

tree.query(class: Arel::Nodes::JoinSource)

end
end