pg_query 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -52
  3. data/README.md +72 -65
  4. data/Rakefile +82 -1
  5. data/ext/pg_query/extconf.rb +2 -39
  6. data/ext/pg_query/guc-file.c +0 -0
  7. data/ext/pg_query/pg_query.c +104 -0
  8. data/ext/pg_query/pg_query.pb-c.c +37628 -0
  9. data/ext/pg_query/pg_query_deparse.c +9953 -0
  10. data/ext/pg_query/pg_query_fingerprint.c +292 -0
  11. data/ext/pg_query/pg_query_fingerprint.h +8 -0
  12. data/ext/pg_query/pg_query_internal.h +24 -0
  13. data/ext/pg_query/pg_query_json_plpgsql.c +738 -0
  14. data/ext/pg_query/pg_query_json_plpgsql.h +9 -0
  15. data/ext/pg_query/pg_query_normalize.c +437 -0
  16. data/ext/pg_query/pg_query_outfuncs.h +10 -0
  17. data/ext/pg_query/pg_query_outfuncs_json.c +297 -0
  18. data/ext/pg_query/pg_query_outfuncs_protobuf.c +237 -0
  19. data/ext/pg_query/pg_query_parse.c +148 -0
  20. data/ext/pg_query/pg_query_parse_plpgsql.c +460 -0
  21. data/ext/pg_query/pg_query_readfuncs.h +11 -0
  22. data/ext/pg_query/pg_query_readfuncs_protobuf.c +142 -0
  23. data/ext/pg_query/pg_query_ruby.c +108 -12
  24. data/ext/pg_query/pg_query_scan.c +173 -0
  25. data/ext/pg_query/pg_query_split.c +221 -0
  26. data/ext/pg_query/protobuf-c.c +3660 -0
  27. data/ext/pg_query/src_backend_catalog_namespace.c +1051 -0
  28. data/ext/pg_query/src_backend_catalog_pg_proc.c +142 -0
  29. data/ext/pg_query/src_backend_commands_define.c +117 -0
  30. data/ext/pg_query/src_backend_libpq_pqcomm.c +651 -0
  31. data/ext/pg_query/src_backend_nodes_bitmapset.c +513 -0
  32. data/ext/pg_query/src_backend_nodes_copyfuncs.c +6013 -0
  33. data/ext/pg_query/src_backend_nodes_equalfuncs.c +4003 -0
  34. data/ext/pg_query/src_backend_nodes_extensible.c +99 -0
  35. data/ext/pg_query/src_backend_nodes_list.c +922 -0
  36. data/ext/pg_query/src_backend_nodes_makefuncs.c +417 -0
  37. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +1363 -0
  38. data/ext/pg_query/src_backend_nodes_value.c +84 -0
  39. data/ext/pg_query/src_backend_parser_gram.c +47456 -0
  40. data/ext/pg_query/src_backend_parser_parse_expr.c +313 -0
  41. data/ext/pg_query/src_backend_parser_parser.c +497 -0
  42. data/ext/pg_query/src_backend_parser_scan.c +7091 -0
  43. data/ext/pg_query/src_backend_parser_scansup.c +160 -0
  44. data/ext/pg_query/src_backend_postmaster_postmaster.c +2230 -0
  45. data/ext/pg_query/src_backend_storage_ipc_ipc.c +192 -0
  46. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +370 -0
  47. data/ext/pg_query/src_backend_tcop_postgres.c +776 -0
  48. data/ext/pg_query/src_backend_utils_adt_datum.c +326 -0
  49. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +98 -0
  50. data/ext/pg_query/src_backend_utils_adt_format_type.c +136 -0
  51. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +1683 -0
  52. data/ext/pg_query/src_backend_utils_error_assert.c +74 -0
  53. data/ext/pg_query/src_backend_utils_error_elog.c +1748 -0
  54. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +570 -0
  55. data/ext/pg_query/src_backend_utils_hash_dynahash.c +1086 -0
  56. data/ext/pg_query/src_backend_utils_init_globals.c +168 -0
  57. data/ext/pg_query/src_backend_utils_mb_mbutils.c +839 -0
  58. data/ext/pg_query/src_backend_utils_misc_guc.c +1831 -0
  59. data/ext/pg_query/src_backend_utils_mmgr_aset.c +1560 -0
  60. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +1006 -0
  61. data/ext/pg_query/src_common_encnames.c +158 -0
  62. data/ext/pg_query/src_common_keywords.c +39 -0
  63. data/ext/pg_query/src_common_kwlist_d.h +1081 -0
  64. data/ext/pg_query/src_common_kwlookup.c +91 -0
  65. data/ext/pg_query/src_common_psprintf.c +158 -0
  66. data/ext/pg_query/src_common_string.c +86 -0
  67. data/ext/pg_query/src_common_stringinfo.c +336 -0
  68. data/ext/pg_query/src_common_wchar.c +1651 -0
  69. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +1133 -0
  70. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +877 -0
  71. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +6533 -0
  72. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +107 -0
  73. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +123 -0
  74. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +671 -0
  75. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +255 -0
  76. data/ext/pg_query/src_port_erand48.c +127 -0
  77. data/ext/pg_query/src_port_pg_bitutils.c +246 -0
  78. data/ext/pg_query/src_port_pgsleep.c +69 -0
  79. data/ext/pg_query/src_port_pgstrcasecmp.c +83 -0
  80. data/ext/pg_query/src_port_qsort.c +240 -0
  81. data/ext/pg_query/src_port_random.c +31 -0
  82. data/ext/pg_query/src_port_snprintf.c +1449 -0
  83. data/ext/pg_query/src_port_strerror.c +324 -0
  84. data/ext/pg_query/src_port_strnlen.c +39 -0
  85. data/ext/pg_query/xxhash.c +43 -0
  86. data/lib/pg_query.rb +7 -4
  87. data/lib/pg_query/constants.rb +21 -0
  88. data/lib/pg_query/deparse.rb +15 -1673
  89. data/lib/pg_query/filter_columns.rb +86 -85
  90. data/lib/pg_query/fingerprint.rb +122 -87
  91. data/lib/pg_query/json_field_names.rb +1402 -0
  92. data/lib/pg_query/node.rb +31 -0
  93. data/lib/pg_query/param_refs.rb +42 -37
  94. data/lib/pg_query/parse.rb +220 -203
  95. data/lib/pg_query/parse_error.rb +1 -1
  96. data/lib/pg_query/pg_query_pb.rb +3211 -0
  97. data/lib/pg_query/scan.rb +23 -0
  98. data/lib/pg_query/treewalker.rb +24 -40
  99. data/lib/pg_query/truncate.rb +64 -43
  100. data/lib/pg_query/version.rb +2 -2
  101. metadata +101 -11
  102. data/ext/pg_query/pg_query_ruby.h +0 -10
  103. data/lib/pg_query/deep_dup.rb +0 -16
  104. data/lib/pg_query/deparse/alter_table.rb +0 -42
  105. data/lib/pg_query/deparse/interval.rb +0 -105
  106. data/lib/pg_query/deparse/keywords.rb +0 -159
  107. data/lib/pg_query/deparse/rename.rb +0 -41
  108. data/lib/pg_query/legacy_parsetree.rb +0 -109
  109. data/lib/pg_query/node_types.rb +0 -297
@@ -0,0 +1,23 @@
1
+ module PgQuery
2
+ class ScanError < ArgumentError
3
+ attr_reader :location
4
+ def initialize(message, source_file, source_line, location)
5
+ super("#{message} (#{source_file}:#{source_line})")
6
+ @location = location
7
+ end
8
+ end
9
+
10
+ def self.scan(query)
11
+ out, stderr = _raw_scan(query)
12
+
13
+ result = PgQuery::ScanResult.decode(out)
14
+
15
+ warnings = []
16
+ stderr.each_line do |line|
17
+ next unless line[/^WARNING/]
18
+ warnings << line.strip
19
+ end
20
+
21
+ [result, warnings]
22
+ end
23
+ end
@@ -1,53 +1,37 @@
1
- class PgQuery
2
- private
1
+ module PgQuery
2
+ class ParserResult
3
+ private
3
4
 
4
- def treewalker!(normalized_parsetree)
5
- exprs = normalized_parsetree.dup.map { |e| [e, []] }
5
+ def treewalker!(tree) # rubocop:disable Metrics/CyclomaticComplexity
6
+ nodes = [[tree.dup, []]]
6
7
 
7
- loop do
8
- expr, parent_location = exprs.shift
8
+ loop do
9
+ parent_node, parent_location = nodes.shift
9
10
 
10
- if expr.is_a?(Hash)
11
- expr.each do |k, v|
12
- location = parent_location + [k]
11
+ case parent_node
12
+ when Google::Protobuf::MessageExts
13
+ parent_node.to_h.keys.each do |parent_field|
14
+ node = parent_node[parent_field.to_s]
15
+ next if node.nil?
16
+ location = parent_location + [parent_field]
13
17
 
14
- yield(expr, k, v, location)
18
+ yield(parent_node, parent_field, node, location) if node.is_a?(Google::Protobuf::MessageExts) || node.is_a?(Google::Protobuf::RepeatedField)
15
19
 
16
- exprs << [v, location] unless v.nil?
20
+ nodes << [node, location] unless node.nil?
21
+ end
22
+ when Google::Protobuf::RepeatedField
23
+ nodes += parent_node.map.with_index { |e, idx| [e, parent_location + [idx]] }
17
24
  end
18
- elsif expr.is_a?(Array)
19
- exprs += expr.map.with_index { |e, idx| [e, parent_location + [idx]] }
20
- end
21
-
22
- break if exprs.empty?
23
- end
24
- end
25
25
 
26
- def find_tree_location(normalized_parsetree, searched_location)
27
- treewalker! normalized_parsetree do |expr, k, v, location|
28
- next unless location == searched_location
29
- yield(expr, k, v)
26
+ break if nodes.empty?
27
+ end
30
28
  end
31
- end
32
29
 
33
- def transform_nodes!(parsetree)
34
- result = deep_dup(parsetree)
35
- exprs = result.dup
36
-
37
- loop do
38
- expr = exprs.shift
39
-
40
- if expr.is_a?(Hash)
41
- yield(expr) if expr.size == 1 && expr.keys[0][/^[A-Z]+/]
42
-
43
- exprs += expr.values.compact
44
- elsif expr.is_a?(Array)
45
- exprs += expr
30
+ def find_tree_location(tree, searched_location)
31
+ treewalker! tree do |parent_node, parent_field, node, location|
32
+ next unless location == searched_location
33
+ yield(parent_node, parent_field, node)
46
34
  end
47
-
48
- break if exprs.empty?
49
35
  end
50
-
51
- result
52
36
  end
53
37
  end
@@ -1,60 +1,81 @@
1
- class PgQuery
2
- PossibleTruncation = Struct.new(:location, :node_type, :length, :is_array)
3
1
 
4
- A_TRUNCATED = 'A_Truncated'.freeze
2
+ module PgQuery
3
+ class ParserResult
4
+ PossibleTruncation = Struct.new(:location, :node_type, :length, :is_array)
5
5
 
6
- # Truncates the query string to be below the specified length, first trying to
7
- # omit less important parts of the query, and only then cutting off the end.
8
- def truncate(max_length)
9
- output = deparse(@tree)
6
+ # Truncates the query string to be below the specified length, first trying to
7
+ # omit less important parts of the query, and only then cutting off the end.
8
+ def truncate(max_length) # rubocop:disable Metrics/CyclomaticComplexity
9
+ output = deparse
10
10
 
11
- # Early exit if we're already below the max length
12
- return output if output.size <= max_length
11
+ # Early exit if we're already below the max length
12
+ return output if output.size <= max_length
13
+
14
+ truncations = find_possible_truncations
13
15
 
14
- truncations = find_possible_truncations
16
+ # Truncate the deepest possible truncation that is the longest first
17
+ truncations.sort_by! { |t| [-t.location.size, -t.length] }
15
18
 
16
- # Truncate the deepest possible truncation that is the longest first
17
- truncations.sort_by! { |t| [-t.location.size, -t.length] }
19
+ tree = dup_tree
20
+ truncations.each do |truncation|
21
+ next if truncation.length < 3
18
22
 
19
- tree = deep_dup(@tree)
20
- truncations.each do |truncation|
21
- next if truncation.length < 3
23
+ find_tree_location(tree, truncation.location) do |node, _k|
24
+ dummy_column_ref = PgQuery::Node.new(column_ref: PgQuery::ColumnRef.new(fields: [PgQuery::Node.new(string: PgQuery::String.new(str: '…'))]))
25
+ case truncation.node_type
26
+ when :target_list
27
+ node.target_list.replace(
28
+ [
29
+ PgQuery::Node.new(res_target: PgQuery::ResTarget.new(val: dummy_column_ref))
30
+ ]
31
+ )
32
+ when :where_clause
33
+ node.where_clause = dummy_column_ref
34
+ when :ctequery
35
+ node.ctequery = PgQuery::Node.new(select_stmt: PgQuery::SelectStmt.new(where_clause: dummy_column_ref, op: :SETOP_NONE))
36
+ when :cols
37
+ node.cols.replace([PgQuery::Node.from(PgQuery::ResTarget.new(name: '…'))])
38
+ else
39
+ raise ArgumentError, format('Unexpected truncation node type: %s', truncation.node_type)
40
+ end
41
+ end
22
42
 
23
- find_tree_location(tree, truncation.location) do |expr, k|
24
- expr[k] = { A_TRUNCATED => nil }
25
- expr[k] = [expr[k]] if truncation.is_array
43
+ output = PgQuery.deparse(tree).gsub('SELECT WHERE "…"', '...').gsub('"…"', '...')
44
+ return output if output.size <= max_length
26
45
  end
27
46
 
28
- output = deparse(tree)
29
- return output if output.size <= max_length
47
+ # We couldn't do a proper smart truncation, so we need a hard cut-off
48
+ output[0..max_length - 4] + '...'
30
49
  end
31
50
 
32
- # We couldn't do a proper smart truncation, so we need a hard cut-off
33
- output[0..max_length - 4] + '...'
34
- end
35
-
36
- private
51
+ private
37
52
 
38
- def find_possible_truncations
39
- truncations = []
53
+ def find_possible_truncations
54
+ truncations = []
40
55
 
41
- treewalker! @tree do |_expr, k, v, location|
42
- case k
43
- when TARGET_LIST_FIELD
44
- length = deparse([{ SELECT_STMT => { k => v } }]).size - 7 # 'SELECT '.size
45
-
46
- truncations << PossibleTruncation.new(location, TARGET_LIST_FIELD, length, true)
47
- when 'whereClause'
48
- length = deparse([{ SELECT_STMT => { k => v } }]).size
49
-
50
- truncations << PossibleTruncation.new(location, 'whereClause', length, false)
51
- when 'ctequery'
52
- truncations << PossibleTruncation.new(location, 'ctequery', deparse([v]).size, false)
53
- when 'cols'
54
- truncations << PossibleTruncation.new(location, 'cols', deparse(v).size, true)
56
+ treewalker! @tree do |_expr, k, v, location|
57
+ case k
58
+ when :target_list
59
+ length = PgQuery.deparse_stmt(PgQuery::SelectStmt.new(k => v.to_a, op: :SETOP_NONE)).size - 7 # 'SELECT '.size
60
+ truncations << PossibleTruncation.new(location, :target_list, length, true)
61
+ when :where_clause
62
+ length = PgQuery.deparse_expr(v).size
63
+ truncations << PossibleTruncation.new(location, :where_clause, length, false)
64
+ when :ctequery
65
+ length = PgQuery.deparse_stmt(v[v.node.to_s]).size
66
+ truncations << PossibleTruncation.new(location, :ctequery, length, false)
67
+ when :cols
68
+ length = PgQuery.deparse_stmt(
69
+ PgQuery::InsertStmt.new(
70
+ relation: PgQuery::RangeVar.new(relname: 'x', inh: true),
71
+ cols: v.to_a
72
+ )
73
+ ).size - 31 # "INSERT INTO x () DEFAULT VALUES".size
74
+ truncations << PossibleTruncation.new(location, :cols, length, true)
75
+ end
55
76
  end
56
- end
57
77
 
58
- truncations
78
+ truncations
79
+ end
59
80
  end
60
81
  end
@@ -1,3 +1,3 @@
1
- class PgQuery
2
- VERSION = '1.3.0'.freeze
1
+ module PgQuery
2
+ VERSION = '2.0.0'.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.3.0
4
+ version: 2.0.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: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.15.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: google-protobuf
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.15.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.15.5
69
83
  description: Parses SQL queries using a copy of the PostgreSQL server query parser
70
84
  email: lukas@fittl.com
71
85
  executables: []
@@ -80,27 +94,103 @@ files:
80
94
  - README.md
81
95
  - Rakefile
82
96
  - ext/pg_query/extconf.rb
97
+ - ext/pg_query/guc-file.c
98
+ - ext/pg_query/pg_query.c
99
+ - ext/pg_query/pg_query.pb-c.c
100
+ - ext/pg_query/pg_query_deparse.c
101
+ - ext/pg_query/pg_query_fingerprint.c
102
+ - ext/pg_query/pg_query_fingerprint.h
103
+ - ext/pg_query/pg_query_internal.h
104
+ - ext/pg_query/pg_query_json_plpgsql.c
105
+ - ext/pg_query/pg_query_json_plpgsql.h
106
+ - ext/pg_query/pg_query_normalize.c
107
+ - ext/pg_query/pg_query_outfuncs.h
108
+ - ext/pg_query/pg_query_outfuncs_json.c
109
+ - ext/pg_query/pg_query_outfuncs_protobuf.c
110
+ - ext/pg_query/pg_query_parse.c
111
+ - ext/pg_query/pg_query_parse_plpgsql.c
112
+ - ext/pg_query/pg_query_readfuncs.h
113
+ - ext/pg_query/pg_query_readfuncs_protobuf.c
83
114
  - ext/pg_query/pg_query_ruby.c
84
- - ext/pg_query/pg_query_ruby.h
85
115
  - ext/pg_query/pg_query_ruby.sym
116
+ - ext/pg_query/pg_query_scan.c
117
+ - ext/pg_query/pg_query_split.c
118
+ - ext/pg_query/protobuf-c.c
119
+ - ext/pg_query/src_backend_catalog_namespace.c
120
+ - ext/pg_query/src_backend_catalog_pg_proc.c
121
+ - ext/pg_query/src_backend_commands_define.c
122
+ - ext/pg_query/src_backend_libpq_pqcomm.c
123
+ - ext/pg_query/src_backend_nodes_bitmapset.c
124
+ - ext/pg_query/src_backend_nodes_copyfuncs.c
125
+ - ext/pg_query/src_backend_nodes_equalfuncs.c
126
+ - ext/pg_query/src_backend_nodes_extensible.c
127
+ - ext/pg_query/src_backend_nodes_list.c
128
+ - ext/pg_query/src_backend_nodes_makefuncs.c
129
+ - ext/pg_query/src_backend_nodes_nodeFuncs.c
130
+ - ext/pg_query/src_backend_nodes_value.c
131
+ - ext/pg_query/src_backend_parser_gram.c
132
+ - ext/pg_query/src_backend_parser_parse_expr.c
133
+ - ext/pg_query/src_backend_parser_parser.c
134
+ - ext/pg_query/src_backend_parser_scan.c
135
+ - ext/pg_query/src_backend_parser_scansup.c
136
+ - ext/pg_query/src_backend_postmaster_postmaster.c
137
+ - ext/pg_query/src_backend_storage_ipc_ipc.c
138
+ - ext/pg_query/src_backend_storage_lmgr_s_lock.c
139
+ - ext/pg_query/src_backend_tcop_postgres.c
140
+ - ext/pg_query/src_backend_utils_adt_datum.c
141
+ - ext/pg_query/src_backend_utils_adt_expandeddatum.c
142
+ - ext/pg_query/src_backend_utils_adt_format_type.c
143
+ - ext/pg_query/src_backend_utils_adt_ruleutils.c
144
+ - ext/pg_query/src_backend_utils_error_assert.c
145
+ - ext/pg_query/src_backend_utils_error_elog.c
146
+ - ext/pg_query/src_backend_utils_fmgr_fmgr.c
147
+ - ext/pg_query/src_backend_utils_hash_dynahash.c
148
+ - ext/pg_query/src_backend_utils_init_globals.c
149
+ - ext/pg_query/src_backend_utils_mb_mbutils.c
150
+ - ext/pg_query/src_backend_utils_misc_guc.c
151
+ - ext/pg_query/src_backend_utils_mmgr_aset.c
152
+ - ext/pg_query/src_backend_utils_mmgr_mcxt.c
153
+ - ext/pg_query/src_common_encnames.c
154
+ - ext/pg_query/src_common_keywords.c
155
+ - ext/pg_query/src_common_kwlist_d.h
156
+ - ext/pg_query/src_common_kwlookup.c
157
+ - ext/pg_query/src_common_psprintf.c
158
+ - ext/pg_query/src_common_string.c
159
+ - ext/pg_query/src_common_stringinfo.c
160
+ - ext/pg_query/src_common_wchar.c
161
+ - ext/pg_query/src_pl_plpgsql_src_pl_comp.c
162
+ - ext/pg_query/src_pl_plpgsql_src_pl_funcs.c
163
+ - ext/pg_query/src_pl_plpgsql_src_pl_gram.c
164
+ - ext/pg_query/src_pl_plpgsql_src_pl_handler.c
165
+ - ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h
166
+ - ext/pg_query/src_pl_plpgsql_src_pl_scanner.c
167
+ - ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h
168
+ - ext/pg_query/src_port_erand48.c
169
+ - ext/pg_query/src_port_pg_bitutils.c
170
+ - ext/pg_query/src_port_pgsleep.c
171
+ - ext/pg_query/src_port_pgstrcasecmp.c
172
+ - ext/pg_query/src_port_qsort.c
173
+ - ext/pg_query/src_port_random.c
174
+ - ext/pg_query/src_port_snprintf.c
175
+ - ext/pg_query/src_port_strerror.c
176
+ - ext/pg_query/src_port_strnlen.c
177
+ - ext/pg_query/xxhash.c
86
178
  - lib/pg_query.rb
87
- - lib/pg_query/deep_dup.rb
179
+ - lib/pg_query/constants.rb
88
180
  - lib/pg_query/deparse.rb
89
- - lib/pg_query/deparse/alter_table.rb
90
- - lib/pg_query/deparse/interval.rb
91
- - lib/pg_query/deparse/keywords.rb
92
- - lib/pg_query/deparse/rename.rb
93
181
  - lib/pg_query/filter_columns.rb
94
182
  - lib/pg_query/fingerprint.rb
95
- - lib/pg_query/legacy_parsetree.rb
96
- - lib/pg_query/node_types.rb
183
+ - lib/pg_query/json_field_names.rb
184
+ - lib/pg_query/node.rb
97
185
  - lib/pg_query/param_refs.rb
98
186
  - lib/pg_query/parse.rb
99
187
  - lib/pg_query/parse_error.rb
188
+ - lib/pg_query/pg_query_pb.rb
189
+ - lib/pg_query/scan.rb
100
190
  - lib/pg_query/treewalker.rb
101
191
  - lib/pg_query/truncate.rb
102
192
  - lib/pg_query/version.rb
103
- homepage: http://github.com/lfittl/pg_query
193
+ homepage: http://github.com/pganalyze/pg_query
104
194
  licenses:
105
195
  - BSD-3-Clause
106
196
  metadata: {}
@@ -1,10 +0,0 @@
1
- #ifndef PG_QUERY_RUBY_H
2
- #define PG_QUERY_RUBY_H
3
-
4
- #include "pg_query.h"
5
-
6
- #include <ruby.h>
7
-
8
- void Init_pg_query(void);
9
-
10
- #endif
@@ -1,16 +0,0 @@
1
- class PgQuery
2
- def deep_dup(obj)
3
- case obj
4
- when Hash
5
- obj.each_with_object(obj.dup) do |(key, value), hash|
6
- hash[deep_dup(key)] = deep_dup(value)
7
- end
8
- when Array
9
- obj.map { |it| deep_dup(it) }
10
- when NilClass, FalseClass, TrueClass, Symbol, Numeric
11
- obj # Can't be duplicated
12
- else
13
- obj.dup
14
- end
15
- end
16
- end
@@ -1,42 +0,0 @@
1
- class PgQuery
2
- module Deparse
3
- module AlterTable
4
- # Returns a list of strings of length one or length two. The first string
5
- # will be placed before the column name and the second, if present, will be
6
- # placed after.
7
- #
8
- # If node['subtype'] is the integer 4 (AT_DropNotNull),
9
- # then return value of this method will be:
10
- #
11
- # ['ALTER COLUMN', 'DROP NOT NULL']
12
- #
13
- # Which will be composed into the SQL as:
14
- #
15
- # ALTER COLUMN {column_name} DROP NOT NULL
16
- #
17
- def self.commands(node)
18
- action = ALTER_TABLE_TYPES_MAPPING[node['subtype']] || raise(format("Can't deparse: %s", node.inspect))
19
- PgQuery::Deparse.instance_exec(node, &action)
20
- end
21
-
22
- ALTER_TABLE_TYPES_MAPPING = {
23
- AT_AddColumn => ->(_node) { ['ADD COLUMN'] },
24
- AT_ColumnDefault => ->(node) { ['ALTER COLUMN', node['def'] ? 'SET DEFAULT' : 'DROP DEFAULT'] },
25
- AT_DropNotNull => ->(_node) { ['ALTER COLUMN', 'DROP NOT NULL'] },
26
- AT_SetNotNull => ->(_node) { ['ALTER COLUMN', 'SET NOT NULL'] },
27
- AT_SetStatistics => ->(_node) { ['ALTER COLUMN', 'SET STATISTICS'] },
28
- AT_SetOptions => ->(_node) { ['ALTER COLUMN', 'SET'] },
29
- AT_ResetOptions => ->(_node) { ['ALTER COLUMN', 'RESET'] },
30
- AT_SetStorage => ->(_node) { ['ALTER COLUMN', 'SET STORAGE'] },
31
- AT_DropColumn => ->(_node) { ['DROP'] },
32
- AT_AddIndex => ->(_node) { ['ADD INDEX'] },
33
- AT_AddConstraint => ->(_node) { ['ADD'] },
34
- AT_AlterConstraint => ->(_node) { ['ALTER CONSTRAINT'] },
35
- AT_ValidateConstraint => ->(_node) { ['VALIDATE CONSTRAINT'] },
36
- AT_DropConstraint => ->(_node) { ['DROP CONSTRAINT'] },
37
- AT_AlterColumnType => ->(_node) { ['ALTER COLUMN', 'TYPE'] },
38
- AT_AlterColumnGenericOptions => ->(_node) { ['ALTER COLUMN', 'OPTIONS'] }
39
- }.freeze
40
- end
41
- end
42
- end