pg_query 0.8.0 → 0.9.0
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +47 -61
- data/ext/pg_query/extconf.rb +15 -4
- data/ext/pg_query/pg_query_ruby.c +42 -0
- data/lib/pg_query.rb +4 -0
- data/lib/pg_query/deep_dup.rb +16 -0
- data/lib/pg_query/deparse.rb +166 -116
- data/lib/pg_query/deparse/alter_table.rb +21 -122
- data/lib/pg_query/filter_columns.rb +37 -35
- data/lib/pg_query/fingerprint.rb +95 -26
- data/lib/pg_query/legacy_parsetree.rb +128 -0
- data/lib/pg_query/node_types.rb +218 -0
- data/lib/pg_query/param_refs.rb +9 -9
- data/lib/pg_query/parse.rb +48 -50
- data/lib/pg_query/treewalker.rb +17 -11
- data/lib/pg_query/truncate.rb +10 -8
- data/lib/pg_query/version.rb +1 -1
- metadata +5 -2
data/lib/pg_query/truncate.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
class PgQuery
|
2
2
|
PossibleTruncation = Struct.new(:location, :node_type, :length, :is_array)
|
3
3
|
|
4
|
+
A_TRUNCATED = 'A_Truncated'.freeze
|
5
|
+
|
4
6
|
# Truncates the query string to be below the specified length, first trying to
|
5
7
|
# omit less important parts of the query, and only then cutting off the end.
|
6
8
|
def truncate(max_length)
|
7
|
-
output = deparse(
|
9
|
+
output = deparse(@tree)
|
8
10
|
|
9
11
|
# Early exit if we're already below the max length
|
10
12
|
return output if output.size <= max_length
|
@@ -14,12 +16,12 @@ class PgQuery
|
|
14
16
|
# Truncate the deepest possible truncation that is the longest first
|
15
17
|
truncations.sort_by! { |t| [-t.location.size, -t.length] }
|
16
18
|
|
17
|
-
tree = deep_dup(
|
19
|
+
tree = deep_dup(@tree)
|
18
20
|
truncations.each do |truncation|
|
19
21
|
next if truncation.length < 3
|
20
22
|
|
21
23
|
find_tree_location(tree, truncation.location) do |expr, k|
|
22
|
-
expr[k] = {
|
24
|
+
expr[k] = { A_TRUNCATED => nil }
|
23
25
|
expr[k] = [expr[k]] if truncation.is_array
|
24
26
|
end
|
25
27
|
|
@@ -36,14 +38,14 @@ class PgQuery
|
|
36
38
|
def find_possible_truncations
|
37
39
|
truncations = []
|
38
40
|
|
39
|
-
treewalker!
|
41
|
+
treewalker! @tree do |_expr, k, v, location|
|
40
42
|
case k
|
41
|
-
when
|
42
|
-
length = deparse([{
|
43
|
+
when TARGET_LIST_FIELD
|
44
|
+
length = deparse([{ SELECT_STMT => { k => v } }]).size - 'SELECT '.size
|
43
45
|
|
44
|
-
truncations << PossibleTruncation.new(location,
|
46
|
+
truncations << PossibleTruncation.new(location, TARGET_LIST_FIELD, length, true)
|
45
47
|
when 'whereClause'
|
46
|
-
length = deparse([{
|
48
|
+
length = deparse([{ SELECT_STMT => { k => v } }]).size
|
47
49
|
|
48
50
|
truncations << PossibleTruncation.new(location, 'whereClause', length, false)
|
49
51
|
when 'ctequery'
|
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: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Fittl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -98,11 +98,14 @@ files:
|
|
98
98
|
- ext/pg_query/pg_query_ruby.h
|
99
99
|
- ext/pg_query/pg_query_ruby.sym
|
100
100
|
- lib/pg_query.rb
|
101
|
+
- lib/pg_query/deep_dup.rb
|
101
102
|
- lib/pg_query/deparse.rb
|
102
103
|
- lib/pg_query/deparse/alter_table.rb
|
103
104
|
- lib/pg_query/deparse/interval.rb
|
104
105
|
- lib/pg_query/filter_columns.rb
|
105
106
|
- lib/pg_query/fingerprint.rb
|
107
|
+
- lib/pg_query/legacy_parsetree.rb
|
108
|
+
- lib/pg_query/node_types.rb
|
106
109
|
- lib/pg_query/param_refs.rb
|
107
110
|
- lib/pg_query/parse.rb
|
108
111
|
- lib/pg_query/parse_error.rb
|