pg_query 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b234a246e532789199b80cfdc118cc44f45f56dc
4
- data.tar.gz: 9f1b878a7902bfbce4a86a69d96ecdc8bdd4a659
3
+ metadata.gz: 4a5be9c84a9ac788a7845fc900696e4c7df77bb3
4
+ data.tar.gz: e77d94ae2f8fb120c21efabf2faed451ad4e0966
5
5
  SHA512:
6
- metadata.gz: 642d3c1c1a325d737da9252e72715a16f25dc6c2138c03ebd4503efb231604a5fd13b0265cf5637c0aa12510837560b70e8f4ad90ca94ecaf937301783bc4673
7
- data.tar.gz: 269105c0470ee517a15f6bb613609ed0ff50a915e188b1c43510a98c02304eafee38f5c70a3ecfeefdf4bffdacbbe7331ce0c3d6d13d2336af41d8c314b746bb
6
+ metadata.gz: 1f2f3fe149dfb181c7023fd243fa66f95f7613fffdb174c2968d947d37ade1d3dd15be599c27aa83ea67f8a289c8bff5e249c94902cb9fd61ca0306f61259927
7
+ data.tar.gz: ae8f01f2afc0172fad220c3119fb48806893b8e49e5e35ab58448e2342161933487a5ba9cbae8d95c656c68f453537458b450529c72c12cc77119327494e7aa1
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1 2018-02-02
4
+
5
+ * Parse CTEs and nested selects in INSERT/UPDATE [#76](https://github.com/lfittl/pg_query/pull/76) [@jcoleman](https://github.com/jcoleman)
6
+ * Drop explicit json dependency [#74](https://github.com/lfittl/pg_query/pull/74) [@yuki24](https://github.com/yuki24)
7
+
8
+
3
9
  ## 1.0.0 2017-10-31
4
10
 
5
11
  * IMPORTANT: Major version bump to indicate backwards incompatible parse tree change!
data/README.md CHANGED
@@ -159,24 +159,7 @@ Currently tested and officially supported Ruby versions:
159
159
 
160
160
  ## Resources
161
161
 
162
- Products, tools and libraries built on pg_query:
163
-
164
- * [pganalyze](https://pganalyze.com/)
165
- * [hsql](https://github.com/JackDanger/hsql)
166
- * [sqlint](https://github.com/purcell/sqlint)
167
- * [pghero](https://github.com/ankane/pghero)
168
- * [dexter](https://github.com/ankane/dexter)
169
-
170
- pg_query for other languages:
171
-
172
- * C: [libpg_query](https://github.com/lfittl/libpg_query)
173
- * Go: [pg_query_go](https://github.com/lfittl/pg_query_go)
174
- * Javascript (Node): [pg-query-parser](https://github.com/zhm/pg-query-parser)
175
- * Javascript (Browser): [pg-query-emscripten](https://github.com/lfittl/pg-query-emscripten)
176
- * Python: [psqlparse](https://github.com/alculquicondor/psqlparse)
177
-
178
- Please feel free to [open a PR](https://github.com/lfittl/pg_query/pull/new/master) to add yours! :)
179
-
162
+ See [libpg_query](https://github.com/lfittl/libpg_query/blob/10-latest/README.md#resources) for pg_query in other languages, as well as products/tools built on pg_query.
180
163
 
181
164
  ## Original Author
182
165
 
@@ -97,18 +97,23 @@ class PgQuery
97
97
  statements << statement[SELECT_STMT]['rarg'] if statement[SELECT_STMT]['rarg']
98
98
  end
99
99
 
100
- # CTEs
101
- with_clause = statement[SELECT_STMT]['withClause']
102
- if with_clause
103
- with_clause[WITH_CLAUSE]['ctes'].each do |item|
104
- next unless item[COMMON_TABLE_EXPR]
105
- @cte_names << item[COMMON_TABLE_EXPR]['ctename']
106
- statements << item[COMMON_TABLE_EXPR]['ctequery']
107
- end
100
+ if (with_clause = statement[SELECT_STMT]['withClause'])
101
+ cte_statements, cte_names = statements_and_cte_names_for_with_clause(with_clause)
102
+ @cte_names.concat(cte_names)
103
+ statements.concat(cte_statements)
108
104
  end
109
105
  # The following statements modify the contents of a table
110
106
  when INSERT_STMT, UPDATE_STMT, DELETE_STMT
111
- from_clause_items << { item: statement.values[0]['relation'], type: :dml }
107
+ value = statement.values[0]
108
+ from_clause_items << { item: value['relation'], type: :dml }
109
+ statements << value['selectStmt'] if value.key?('selectStmt')
110
+ statements << value['withClause'] if value.key?('withClause')
111
+
112
+ if (with_clause = value['withClause'])
113
+ cte_statements, cte_names = statements_and_cte_names_for_with_clause(with_clause)
114
+ @cte_names.concat(cte_names)
115
+ statements.concat(cte_statements)
116
+ end
112
117
  when COPY_STMT
113
118
  from_clause_items << { item: statement.values[0]['relation'], type: :dml } if statement.values[0]['relation']
114
119
  statements << statement.values[0]['query']
@@ -221,5 +226,19 @@ class PgQuery
221
226
  end
222
227
 
223
228
  @tables.uniq!
229
+ @cte_names.uniq!
230
+ end
231
+
232
+ def statements_and_cte_names_for_with_clause(with_clause)
233
+ statements = []
234
+ cte_names = []
235
+
236
+ with_clause[WITH_CLAUSE]['ctes'].each do |item|
237
+ next unless item[COMMON_TABLE_EXPR]
238
+ cte_names << item[COMMON_TABLE_EXPR]['ctename']
239
+ statements << item[COMMON_TABLE_EXPR]['ctequery']
240
+ end
241
+
242
+ [statements, cte_names]
224
243
  end
225
244
  end
@@ -1,3 +1,3 @@
1
1
  class PgQuery
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Fittl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-31 00:00:00.000000000 Z
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -66,26 +66,6 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.15.1
69
- - !ruby/object:Gem::Dependency
70
- name: json
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '1.8'
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: '3'
79
- type: :runtime
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: '1.8'
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: '3'
89
69
  description: Parses SQL queries using a copy of the PostgreSQL server query parser
90
70
  email: lukas@fittl.com
91
71
  executables: []
@@ -142,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
122
  version: '0'
143
123
  requirements: []
144
124
  rubyforge_project:
145
- rubygems_version: 2.5.1
125
+ rubygems_version: 2.6.13
146
126
  signing_key:
147
127
  specification_version: 4
148
128
  summary: PostgreSQL query parsing and normalization library