better_batch 1.0.3 → 1.0.5

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
  SHA256:
3
- metadata.gz: b208e3117c167c67e291224859745f7fa44d7f777b81b07e4f0f4e4537295b57
4
- data.tar.gz: e8e6690424e9e9d9db8d613a201bd1551938e5f7502fb304c7dcfbe3ea2de482
3
+ metadata.gz: e8920be816452f9abe8b7e6232f28a98125d1822af759e9a44306a6a09f88a36
4
+ data.tar.gz: 29764cca73ca165266b481c80540aa6f3f642d00ff1a5f3a460b2ff31fcf64e9
5
5
  SHA512:
6
- metadata.gz: 7787219a815f6e26796f0563b1a36b7877e08f866d72f423823bbf0f08a96ebb6d32c071547dccc4523988473f46661019d7c9171e475f5e37e19089396a4eb2
7
- data.tar.gz: 1ae506ba8b32252090a802af2fd6e463e0753f3f8e5c34f0a8f77cd7d3744e0a0cf4f68785c9f92408c9ba109d8a8f9b2882ba55be25cfa60a21dd62c3285d9a
6
+ metadata.gz: 3b15e7ed5955cd8417bdec58eeedcd82dd99cd69305b5e83057da0a9117199a29467af9e3e64bdb8887b7cc7fec5fd68e5ccae6d069876fc926f2f40e0814351
7
+ data.tar.gz: e8dc815ba9b79c856f5908528ce08da075a6290c415b01f2fe713055434c84715792197426667e274eabe28ad686e7673ec229093cc55b1470d7aaa292857457
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'better_batch/word'
4
+
3
5
  module BetterBatch
4
- Inputs = Struct.new(
6
+ InputsStruct = Struct.new(
5
7
  :table_name,
6
8
  :primary_key,
7
9
  :input_columns,
@@ -16,11 +18,11 @@ module BetterBatch
16
18
  # this strange (to me) setup avoids method redefinition warnings
17
19
  module InstanceOverrides
18
20
  def preprocess!
19
- self[:column_types].transform_keys!(&:to_sym)
21
+ self[:column_types] = self[:column_types].transform_keys(&BetterBatch::Word.method(:new))
20
22
  preprocess_returning
21
23
  ensure_lists!
22
- symbolize_lists!
23
- symbolize!
24
+ to_word_lists!
25
+ to_word!
24
26
  end
25
27
 
26
28
  private
@@ -38,20 +40,26 @@ module BetterBatch
38
40
  end
39
41
  end
40
42
 
41
- def symbolize_lists!
43
+ def to_word_lists!
42
44
  %i[input_columns unique_columns now_on_insert now_on_update returning].each do |field|
43
- self[field].map!(&:to_sym)
45
+ self[field] = self[field].map do |it|
46
+ if it.is_a?(BetterBatch::Word)
47
+ it
48
+ else
49
+ BetterBatch::Word.new(it)
50
+ end
51
+ end
44
52
  end
45
53
  end
46
54
 
47
- def symbolize!
55
+ def to_word!
48
56
  %i[table_name primary_key].each do |field|
49
- self[field] = self[field].to_sym
57
+ self[field] = BetterBatch::Word.new(self[field])
50
58
  end
51
59
  end
52
60
  end
53
61
 
54
- class Inputs
62
+ class Inputs < InputsStruct
55
63
  prepend InstanceOverrides
56
64
  end
57
65
  end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterBatch # rubocop:disable Metrics/ModuleLength
4
+ POSTGRESQL_RESERVED = Set.new(
5
+ %w[
6
+ all
7
+ analyse
8
+ analyze
9
+ and
10
+ any
11
+ array
12
+ as
13
+ asc
14
+ asymmetric
15
+ authorization
16
+ binary
17
+ both
18
+ case
19
+ cast
20
+ check
21
+ collate
22
+ collation
23
+ column
24
+ concurrently
25
+ constraint
26
+ create
27
+ cross
28
+ current_catalog
29
+ current_date
30
+ current_role
31
+ current_schema
32
+ current_time
33
+ current_timestamp
34
+ current_user
35
+ default
36
+ deferrable
37
+ desc
38
+ distinct
39
+ do
40
+ else
41
+ end
42
+ except
43
+ false
44
+ fetch
45
+ for
46
+ foreign
47
+ freeze
48
+ from
49
+ full
50
+ grant
51
+ group
52
+ having
53
+ ilike
54
+ in
55
+ initially
56
+ inner
57
+ intersect
58
+ into
59
+ is
60
+ isnull
61
+ join
62
+ lateral
63
+ leading
64
+ left
65
+ like
66
+ limit
67
+ localtime
68
+ localtimestamp
69
+ natural
70
+ not
71
+ notnull
72
+ null
73
+ offset
74
+ on
75
+ only
76
+ or
77
+ order
78
+ outer
79
+ overlaps
80
+ placing
81
+ primary
82
+ references
83
+ returning
84
+ right
85
+ select
86
+ session_user
87
+ similar
88
+ some
89
+ symmetric
90
+ system_user
91
+ table
92
+ tablesample
93
+ then
94
+ to
95
+ trailing
96
+ true
97
+ union
98
+ unique
99
+ user
100
+ using
101
+ variadic
102
+ verbose
103
+ when
104
+ where
105
+ window
106
+ with
107
+ ]
108
+ )
109
+ end
@@ -40,7 +40,7 @@ module BetterBatch
40
40
  end
41
41
 
42
42
  def typed_columns_sql
43
- @typed_columns_sql ||= input_columns.map { |c| "#{c} #{column_types[c]}" }.join(', ')
43
+ @typed_columns_sql ||= input_columns.map { |c| "#{c} #{column_types.fetch(c)}" }.join(', ')
44
44
  end
45
45
 
46
46
  def input_columns_sql
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterBatch
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.5'
5
5
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'better_batch/postgresql_reserved'
4
+
5
+ module BetterBatch
6
+ class Word
7
+ attr_reader :input, :hash
8
+
9
+ def initialize(input)
10
+ @input = input.to_sym
11
+ @input_str = input.to_s.freeze
12
+ downcased = @input_str.downcase
13
+ @output = if POSTGRESQL_RESERVED.include?(downcased) || @input_str != downcased
14
+ "\"#{@input_str}\"".freeze
15
+ else
16
+ @input_str
17
+ end
18
+ @hash = @input.hash
19
+ end
20
+
21
+ def to_s
22
+ @output
23
+ end
24
+
25
+ def ==(other)
26
+ case other
27
+ when self.class
28
+ input == other.input
29
+ else
30
+ raise "Did not know how to compare to #{other.inspect}."
31
+ end
32
+ end
33
+ # needed for list subtraction and hash keys
34
+ alias eql? ==
35
+
36
+ def inspect
37
+ "#<BetterBatch::Word @output=#{@output.inspect}>"
38
+ end
39
+ end
40
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Hartland
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-16 00:00:00.000000000 Z
10
+ date: 2025-05-11 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: anbt-sql-formatter
@@ -41,10 +41,12 @@ files:
41
41
  - lib/better_batch/.DS_Store
42
42
  - lib/better_batch/inputs.rb
43
43
  - lib/better_batch/inserted.rb
44
+ - lib/better_batch/postgresql_reserved.rb
44
45
  - lib/better_batch/query.rb
45
46
  - lib/better_batch/selected.rb
46
47
  - lib/better_batch/updated.rb
47
48
  - lib/better_batch/version.rb
49
+ - lib/better_batch/word.rb
48
50
  - sig/better_batch.rbs
49
51
  homepage: https://github.com/th7/better_batch
50
52
  licenses: