pg_query 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -18
- data/lib/pg_query/parse.rb +28 -9
- data/lib/pg_query/version.rb +1 -1
- metadata +3 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5be9c84a9ac788a7845fc900696e4c7df77bb3
|
4
|
+
data.tar.gz: e77d94ae2f8fb120c21efabf2faed451ad4e0966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2f3fe149dfb181c7023fd243fa66f95f7613fffdb174c2968d947d37ade1d3dd15be599c27aa83ea67f8a289c8bff5e249c94902cb9fd61ca0306f61259927
|
7
|
+
data.tar.gz: ae8f01f2afc0172fad220c3119fb48806893b8e49e5e35ab58448e2342161933487a5ba9cbae8d95c656c68f453537458b450529c72c12cc77119327494e7aa1
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/pg_query/parse.rb
CHANGED
@@ -97,18 +97,23 @@ class PgQuery
|
|
97
97
|
statements << statement[SELECT_STMT]['rarg'] if statement[SELECT_STMT]['rarg']
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
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
|
data/lib/pg_query/version.rb
CHANGED
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.
|
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:
|
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.
|
125
|
+
rubygems_version: 2.6.13
|
146
126
|
signing_key:
|
147
127
|
specification_version: 4
|
148
128
|
summary: PostgreSQL query parsing and normalization library
|