db_fuel 1.2.0.pre.alpha → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4f5691edb9519be2c43b787f9eeee14d2e2e83fcf9071e21dbef2442449d3fa
4
- data.tar.gz: a95cc6d63d3eba9256c022891328352662b64cf8e0391a92962609f6d3a8062c
3
+ metadata.gz: 532f508d6074e44c1dd4bb57dcecf343f32e035d44f6bdbfcb0405127ede5552
4
+ data.tar.gz: dccd390d0c15277ab9ca6c93027d12db85ebe7ad970333ebc2eadc7fc6f39b8c
5
5
  SHA512:
6
- metadata.gz: 36c2477f3010bd60a7ef7a49f60f7a5302d2cec2ad8be034d83e18923eed07820578a87993a9ebc07e1121c8853d45e5060eaca4d4895222afb3b69b8a8b61f9
7
- data.tar.gz: 54f65f7f0d56271bacb6b67512f10135b4d22ddb64dd0a7d1fc864e6d2cd29a0d7e4579056f518cf517b5b3353715bafc489743d596cc8bd8e3e9a0812d6755b
6
+ metadata.gz: b49ad96e45049b564625a2288786e26087701e84c063aa71b316fde794237006c430fb9cc101ef2704efd79117702c36427e3bdf41098622ddb747e2af01d2f0
7
+ data.tar.gz: 1d426794ea2045a5a6c1966352b1e9a00ae991cf4d2996315011da26c99fa652ab0ce719dc3a8cd9a495f61df350a1cc1584d7e47a3aa0317276fbea866e6f37
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 2.0.0 (March 16th, 2021)
2
+
3
+ New Jobs:
4
+ * db_fuel/active_record/upsert
5
+ * db_fuel/active_record/update_all
6
+
7
+ Changes:
8
+ * db_fuel/active_record/update now only updates a single record. Use db_fuel/active_record/update_all to update multiple records at a time.
9
+
1
10
  # 1.1.0 (Decmeber 1st, 2020)
2
11
 
3
12
  New Jobs:
data/README.md CHANGED
@@ -24,16 +24,16 @@ Refer to the [Burner](https://github.com/bluemarblepayroll/burner) library for m
24
24
 
25
25
  ### ActiveRecord Jobs
26
26
 
27
- * **db_fuel/active_record/find_or_insert** [name, table_name, attributes, debug, primary_key, register, separator, timestamps, unique_attributes]: An extension of the `db_fuel/active_record/insert` job that adds an existence check before SQL insertion. The `unique_attributes` will be converted to WHERE clauses for performing the existence check.
28
- * **db_fuel/active_record/insert** [name, table_name, attributes, debug, primary_key, register, separator, timestamps]: This job can take the objects in a register and insert them into a database table. If primary_key is specified then its key will be set to the primary key. Note that composite primary keys are not supported. Attributes defines which object properties to convert to SQL. Refer to the class and constructor specification for more detail.
27
+ * **db_fuel/active_record/find_or_insert** [name, table_name, attributes, debug, primary_keyed_column, register, separator, timestamps, unique_attributes]: An extension of the `db_fuel/active_record/insert` job that adds an existence check before SQL insertion. The `unique_attributes` will be converted to WHERE clauses for performing the existence check.
28
+ * **db_fuel/active_record/insert** [name, table_name, attributes, debug, primary_keyed_column, register, separator, timestamps]: This job can take the objects in a register and insert them into a database table. If primary_keyed_column is specified then its key will be set to the primary key. Note that composite primary keys are not supported. Attributes defines which object properties to convert to SQL. Refer to the class and constructor specification for more detail.
29
29
  * **db_fuel/active_record/update_all** [name, table_name, attributes, debug, register, separator, timestamps, unique_attributes]: This job can take the objects in a register and updates them within a database table. Attributes defines which object properties to convert to SQL SET clauses while unique_attributes translate to WHERE clauses. One or more records may be updated at a time. Refer to the class and constructor specification for more detail.
30
- * **db_fuel/active_record/update** [name, table_name, attributes, debug, register, primary_key, separator, timestamps, unique_attributes]: This job can take the unique objects in a register and updates them within a database table. Attributes defines which object properties to convert to SQL SET clauses while unique_attributes translate to WHERE clauses to find the records to update. The primary_key is used to update the unique record. Only one record will be updated per statement. Refer to the class and constructor specification for more detail.
31
- * **db_fuel/active_record/upsert** [name, table_name, attributes, debug, primary_key, register, separator, timestamps, unique_attributes]: This job can take the objects in a register and either inserts or updates them within a database table. Attributes defines which object properties to convert to SQL SET clauses while each key in unique_attributes become a WHERE clause in order to check for the existence of a specific record. The updated record will use the primary_key specified to perform the UPDATE operation. Note that composite primary keys are not supported. Refer to the class and constructor specification for more detail.
30
+ * **db_fuel/active_record/update** [name, table_name, attributes, debug, register, primary_keyed_column, separator, timestamps, unique_attributes]: This job can take the unique objects in a register and updates them within a database table. Attributes defines which object properties to convert to SQL SET clauses while unique_attributes translate to WHERE clauses to find the records to update. The primary_keyed_column is used to update the unique record. Only one record will be updated per statement. Note that composite primary keys are not supported. Refer to the class and constructor specification for more detail.
31
+ * **db_fuel/active_record/upsert** [name, table_name, attributes, debug, primary_keyed_column, register, separator, timestamps, unique_attributes]: This job can take the objects in a register and either inserts or updates them within a database table. Attributes defines which object properties to convert to SQL SET clauses while each key in unique_attributes become a WHERE clause in order to check for the existence of a specific record. The updated record will use the primary_keyed_column specified to perform the UPDATE operation. Note that composite primary keys are not supported. Refer to the class and constructor specification for more detail.
32
32
 
33
33
  ### Dbee Jobs
34
34
 
35
- * **db_fuel/dbee/query** [model, query, register]: Pass in a [Dbee](https://github.com/bluemarblepayroll/dbee) model and query and store the results in the specified register. Refer to the [Dbee](https://github.com/bluemarblepayroll/dbee) library directly on how to craft a model or query.
36
- * **db_fuel/dbee/range** [key, key_path, model, query, register, separator]: Similar to `db_fuel/dbee/query` with the addition of being able to grab a list of values from the register to use as a Dbee EQUALS/IN filter. This helps to dynamically limit the resulting record set. The key is used to specify where to grab the list of values, while the key_path will be used to craft the [Dbee equal's filter](https://github.com/bluemarblepayroll/dbee/blob/master/lib/dbee/query/filters/equals.rb). Separator is exposed in case nested object support is necessary.
35
+ * **db_fuel/dbee/query** [model, query, register, debug]: Pass in a [Dbee](https://github.com/bluemarblepayroll/dbee) model and query and store the results in the specified register. Refer to the [Dbee](https://github.com/bluemarblepayroll/dbee) library directly on how to craft a model or query.
36
+ * **db_fuel/dbee/range** [key, key_path, model, query, register, separator, debug]: Similar to `db_fuel/dbee/query` with the addition of being able to grab a list of values from the register to use as a Dbee EQUALS/IN filter. This helps to dynamically limit the resulting record set. The key is used to specify where to grab the list of values, while the key_path will be used to craft the [Dbee equal's filter](https://github.com/bluemarblepayroll/dbee/blob/master/lib/dbee/query/filters/equals.rb). Separator is exposed in case nested object support is necessary.
37
37
 
38
38
  ## Examples
39
39
 
@@ -98,6 +98,10 @@ If we were to inspect the contents of `payload` we should see the patient's resu
98
98
  payload['patients'] # array in form of: [ { "id" => 1, "first_name" => "Something" }, ... ]
99
99
  ````
100
100
 
101
+ Notes
102
+
103
+ * Set `debug: true` to print out SQL statement in the output (not for production use.)
104
+
101
105
  ### Limiting Result Sets
102
106
 
103
107
  The `db_fuel/dbee/query` does not provide a way to dynamically connect the query to existing data. You are free to put any Dbee query filters in the query declaration, but what if you would like to further limit this based on the knowledge of a range of values? The `db_fuel/dbee/range` job is meant to do exactly this. On the surface it is mainly an extension of the `db_fuel/dbee/query` job.
@@ -151,6 +155,10 @@ payload['patients'] # array in form of: [ { "id" => 1, "first_name" => "Somethin
151
155
 
152
156
  The only difference between the query and range jobs should be the latter is limited based on the incoming first names.
153
157
 
158
+ Notes
159
+
160
+ * Set `debug: true` to print out SQL statement in the output (not for production use.)
161
+
154
162
  ### Updating the Database
155
163
 
156
164
  #### Inserting Records
@@ -179,7 +187,7 @@ pipeline = {
179
187
  { key: :last_name }
180
188
  ],
181
189
  table_name: 'patients',
182
- primary_key: {
190
+ primary_keyed_column: {
183
191
  key: :id
184
192
  }
185
193
  }
@@ -195,13 +203,13 @@ There should now be two new patients, AB0 and AB1, present in the table `patient
195
203
 
196
204
  Notes:
197
205
 
198
- * Since we specified the `primary_key`, the records' `id` attributes should be set to their respective primary key values.
206
+ * Since we specified the `primary_keyed_column`, the records' `id` attributes should be set to their respective primary key values.
199
207
  * Composite primary keys are not currently supported.
200
208
  * Set `debug: true` to print out each INSERT statement in the output (not for production use.)
201
209
 
202
210
  #### Inserting Only New Records
203
211
 
204
- Another job `db_fuel/active_record/find_or_insert` allows for an existence check to performed each insertion. If a record is found then it will not insert the record. If `primary_key` is set then the existence check will also still set the primary key on the payload's respective object. Note that composite primary keys are not currently supported. We can build on the above insert example for only inserting new patients if their chart_number is unique:
212
+ Another job `db_fuel/active_record/find_or_insert` allows for an existence check to performed each insertion. If a record is found then it will not insert the record. If `primary_keyed_column` is set then the existence check will also still set the primary key on the payload's respective object. Note that composite primary keys are not currently supported. We can build on the above insert example for only inserting new patients if their chart_number is unique:
205
213
 
206
214
  ````ruby
207
215
  pipeline = {
@@ -225,7 +233,7 @@ pipeline = {
225
233
  { key: :last_name }
226
234
  ],
227
235
  table_name: 'patients',
228
- primary_key: {
236
+ primary_keyed_column: {
229
237
  key: :id
230
238
  },
231
239
  unique_attributes: [
@@ -266,7 +274,7 @@ pipeline = {
266
274
  { key: :last_name }
267
275
  ],
268
276
  table_name: 'patients',
269
- primary_key: {
277
+ primary_keyed_column: {
270
278
  key: :id
271
279
  },
272
280
  unique_attributes: [
@@ -348,7 +356,7 @@ pipeline = {
348
356
  { key: :last_name }
349
357
  ],
350
358
  table_name: 'patients',
351
- primary_key: {
359
+ primary_keyed_column: {
352
360
  key: :id
353
361
  },
354
362
  unique_attributes: [
data/db_fuel.gemspec CHANGED
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
 
43
43
  s.add_dependency('activerecord', activerecord_version)
44
44
  s.add_dependency('acts_as_hashable', '~>1.2')
45
- s.add_dependency('burner', '~>1.2')
45
+ s.add_dependency('burner', '~>1.7')
46
46
  s.add_dependency('dbee', '~>2.1')
47
47
  s.add_dependency('dbee-active_record', '~>2.1')
48
48
  s.add_dependency('objectable', '~>1.0')
@@ -26,8 +26,8 @@ module DbFuel
26
26
  :attribute_renderers_set
27
27
 
28
28
  def initialize(
29
- name:,
30
29
  table_name:,
30
+ name: '',
31
31
  attributes: [],
32
32
  debug: false,
33
33
  register: Burner::DEFAULT_REGISTER,
@@ -36,13 +36,13 @@ module DbFuel
36
36
  super(name: name, register: register)
37
37
 
38
38
  @resolver = Objectable.resolver(separator: separator)
39
- @attribute_renderers_set = Modeling::AttributeRendererSet.new(attributes: attributes,
40
- resolver: resolver)
39
+ @attribute_renderers_set = Modeling::AttributeRendererSet.new(resolver: resolver,
40
+ attributes: attributes)
41
41
  @db_provider = DbProvider.new(table_name)
42
42
  @debug = debug || false
43
43
  end
44
44
 
45
- private
45
+ protected
46
46
 
47
47
  def debug_detail(output, message)
48
48
  return unless debug
@@ -14,8 +14,9 @@ module DbFuel
14
14
  module ActiveRecord
15
15
  # This job is a slight enhancement to the insert job, in that it will only insert new
16
16
  # records. It will use the unique_keys to first run a query to see if it exists.
17
- # Each unique_key becomes a WHERE clause. If primary_key is specified and a record is
18
- # found then the first record's id will be set to the primary_key.
17
+ # Each unique_key becomes a WHERE clause. If primary_keyed_column is specified
18
+ # and a record is found then the first record's id will be set to
19
+ # the primary_keyed_column.
19
20
  #
20
21
  # Expected Payload[register] input: array of objects
21
22
  # Payload[register] output: array of objects.
@@ -23,7 +24,7 @@ module DbFuel
23
24
  # attr_reader :unique_attribute_renderers
24
25
 
25
26
  # Arguments:
26
- # name [required]: name of the job within the Burner::Pipeline.
27
+ # name: name of the job within the Burner::Pipeline.
27
28
  #
28
29
  # table_name [required]: name of the table to use for the INSERT statements.
29
30
  #
@@ -36,8 +37,9 @@ module DbFuel
36
37
  # returned objects will be printed in the output. Only use this option while
37
38
  # debugging issues as it will fill up the output with (potentially too much) data.
38
39
  #
39
- # primary_key: If primary_key is present then it will be used to set the object's
40
- # property to the returned primary key from the INSERT statement.
40
+ # primary_keyed_column: If primary_keyed_column is present then it will be used to set
41
+ # the object's property to the returned primary key
42
+ # from the INSERT statement.
41
43
  #
42
44
  # separator: Just like other jobs with a 'separator' option, if the objects require
43
45
  # key-path notation or nested object support, you can set the separator
@@ -51,11 +53,11 @@ module DbFuel
51
53
  # unique_attributes: Each key will become a WHERE clause in order check for record
52
54
  # existence before insertion attempt.
53
55
  def initialize(
54
- name:,
55
56
  table_name:,
57
+ name: '',
56
58
  attributes: [],
57
59
  debug: false,
58
- primary_key: nil,
60
+ primary_keyed_column: nil,
59
61
  register: Burner::DEFAULT_REGISTER,
60
62
  separator: '',
61
63
  timestamps: true,
@@ -67,7 +69,7 @@ module DbFuel
67
69
  table_name: table_name,
68
70
  attributes: attributes,
69
71
  debug: debug,
70
- primary_key: primary_key,
72
+ primary_keyed_column: primary_keyed_column,
71
73
  register: register,
72
74
  separator: separator,
73
75
  timestamps: timestamps,
@@ -17,10 +17,8 @@ module DbFuel
17
17
  # Expected Payload[register] input: array of objects
18
18
  # Payload[register] output: array of objects.
19
19
  class Insert < Upsert
20
- # attr_reader :primary_key
21
-
22
20
  # Arguments:
23
- # name [required]: name of the job within the Burner::Pipeline.
21
+ # name: name of the job within the Burner::Pipeline.
24
22
  #
25
23
  # table_name [required]: name of the table to use for the INSERT statements.
26
24
  #
@@ -33,8 +31,9 @@ module DbFuel
33
31
  # returned objects will be printed in the output. Only use this option while
34
32
  # debugging issues as it will fill up the output with (potentially too much) data.
35
33
  #
36
- # primary_key: If primary_key is present then it will be used to set the object's
37
- # property to the returned primary key from the INSERT statement.
34
+ # primary_keyed_column: If primary_keyed_column is present then it will be used to
35
+ # set the object's property to the returned primary key
36
+ # from the INSERT statement.
38
37
  #
39
38
  # separator: Just like other jobs with a 'separator' option, if the objects require
40
39
  # key-path notation or nested object support, you can set the separator
@@ -45,11 +44,11 @@ module DbFuel
45
44
  # and updated_at columns will automatically have their values set
46
45
  # to the current UTC timestamp.
47
46
  def initialize(
48
- name:,
49
47
  table_name:,
48
+ name: '',
50
49
  attributes: [],
51
50
  debug: false,
52
- primary_key: nil,
51
+ primary_keyed_column: nil,
53
52
  register: Burner::DEFAULT_REGISTER,
54
53
  separator: '',
55
54
  timestamps: true
@@ -62,7 +61,7 @@ module DbFuel
62
61
  table_name: table_name,
63
62
  attributes: attributes,
64
63
  debug: debug,
65
- primary_key: primary_key,
64
+ primary_keyed_column: primary_keyed_column,
66
65
  register: register,
67
66
  separator: separator,
68
67
  timestamps: timestamps
@@ -15,14 +15,14 @@ module DbFuel
15
15
  # This job can take the unique objects in a register and updates them within database table.
16
16
  # The attributes translate to SQL SET clauses and the unique_keys translate to
17
17
  # WHERE clauses to find the records to update.
18
- # The primary_key is used to update the unique record.
18
+ # The primary_keyed_column is used to update the unique record.
19
19
  # Only one record will be updated per statement.
20
20
  #
21
21
  # Expected Payload[register] input: array of objects
22
22
  # Payload[register] output: array of objects.
23
23
  class Update < Upsert
24
24
  # Arguments:
25
- # name [required]: name of the job within the Burner::Pipeline.
25
+ # name: name of the job within the Burner::Pipeline.
26
26
  #
27
27
  # table_name [required]: name of the table to use for the INSERT statements.
28
28
  #
@@ -35,7 +35,7 @@ module DbFuel
35
35
  # returned objects will be printed in the output. Only use this option while
36
36
  # debugging issues as it will fill up the output with (potentially too much) data.
37
37
  #
38
- # primary_key [required]: Primary key column for the corresponding table.
38
+ # primary_keyed_column [required]: Primary key column for the corresponding table.
39
39
  # Used as the WHERE clause for the UPDATE statement.
40
40
  # Only one record will be updated at a time
41
41
  # using the primary key specified.
@@ -52,11 +52,11 @@ module DbFuel
52
52
  # records. The UPDATE statement's WHERE
53
53
  # clause will use the primary key specified.
54
54
  def initialize(
55
- name:,
56
55
  table_name:,
56
+ name: '',
57
57
  attributes: [],
58
58
  debug: false,
59
- primary_key: nil,
59
+ primary_keyed_column: nil,
60
60
  register: Burner::DEFAULT_REGISTER,
61
61
  separator: '',
62
62
  timestamps: true,
@@ -70,7 +70,7 @@ module DbFuel
70
70
  table_name: table_name,
71
71
  attributes: attributes,
72
72
  debug: debug,
73
- primary_key: primary_key,
73
+ primary_keyed_column: primary_keyed_column,
74
74
  register: register,
75
75
  separator: separator,
76
76
  timestamps: timestamps,
@@ -21,7 +21,7 @@ module DbFuel
21
21
  # Payload[register] output: array of objects.
22
22
  class UpdateAll < Upsert
23
23
  # Arguments:
24
- # name [required]: name of the job within the Burner::Pipeline.
24
+ # name: name of the job within the Burner::Pipeline.
25
25
  #
26
26
  # table_name [required]: name of the table to use for the INSERT statements.
27
27
  #
@@ -45,8 +45,8 @@ module DbFuel
45
45
  # unique_attributes: Each key will become a WHERE clause in order to only update specific
46
46
  # records.
47
47
  def initialize(
48
- name:,
49
48
  table_name:,
49
+ name: '',
50
50
  attributes: [],
51
51
  debug: false,
52
52
  register: Burner::DEFAULT_REGISTER,
@@ -62,7 +62,7 @@ module DbFuel
62
62
  table_name: table_name,
63
63
  attributes: attributes,
64
64
  debug: debug,
65
- primary_key: nil,
65
+ primary_keyed_column: nil,
66
66
  register: register,
67
67
  separator: separator,
68
68
  timestamps: timestamps,
@@ -16,15 +16,15 @@ module DbFuel
16
16
  # It will use the unique_keys to first run a query to see if it exists.
17
17
  # Each unique_key becomes a WHERE clause. If a record is found it will then
18
18
  # update the found record using the primary key specified.
19
- # If a record is updated or created the record's id will be set to the primary_key.
19
+ # If a record is updated or created the record's id will be set to the primary_keyed_column.
20
20
  #
21
21
  # Expected Payload[register] input: array of objects
22
22
  # Payload[register] output: array of objects.
23
23
  class Upsert < Base
24
- attr_reader :primary_key, :timestamps, :unique_attribute_renderers
24
+ attr_reader :primary_keyed_column, :timestamps, :unique_attribute_renderers
25
25
 
26
26
  # Arguments:
27
- # name [required]: name of the job within the Burner::Pipeline.
27
+ # name: name of the job within the Burner::Pipeline.
28
28
  #
29
29
  # table_name [required]: name of the table to use for the INSERT OR UPDATE statements.
30
30
  #
@@ -38,9 +38,10 @@ module DbFuel
38
38
  # debugging issues as it will fill
39
39
  # up the output with (potentially too much) data.
40
40
  #
41
- # primary_key [required]: Used to set the object's property to the returned primary key
42
- # from the INSERT statement or used as the
43
- # WHERE clause for the UPDATE statement.
41
+ # primary_keyed_column [required]: Used to set the object's property to the
42
+ # returned primary key from the
43
+ # INSERT statement or used as the
44
+ # WHERE clause for the UPDATE statement.
44
45
  #
45
46
  # separator: Just like other jobs with a 'separator' option, if the objects require
46
47
  # key-path notation or nested object support, you can set the separator
@@ -56,9 +57,9 @@ module DbFuel
56
57
  # unique_attributes: Each key will become a WHERE clause in
57
58
  # order to check for the existence of a specific record.
58
59
  def initialize(
59
- name:,
60
60
  table_name:,
61
- primary_key:,
61
+ primary_keyed_column:,
62
+ name: '',
62
63
  attributes: [],
63
64
  debug: false,
64
65
  register: Burner::DEFAULT_REGISTER,
@@ -75,10 +76,10 @@ module DbFuel
75
76
  separator: separator
76
77
  )
77
78
 
78
- @primary_key = Modeling::KeyedColumn.make(primary_key, nullable: true)
79
+ @primary_keyed_column = Modeling::KeyedColumn.make(primary_keyed_column, nullable: true)
79
80
 
80
81
  @unique_attribute_renderers = attribute_renderers_set
81
- .make_attribute_renderers(unique_attributes)
82
+ .make_renderers(unique_attributes)
82
83
 
83
84
  @timestamps = timestamps
84
85
 
@@ -86,7 +87,7 @@ module DbFuel
86
87
  end
87
88
 
88
89
  def perform(output, payload)
89
- raise ArgumentError, 'primary_key is required' unless primary_key
90
+ raise ArgumentError, 'primary_keyed_column is required' unless primary_keyed_column
90
91
 
91
92
  total_inserted = 0
92
93
  total_updated = 0
@@ -118,9 +119,9 @@ module DbFuel
118
119
 
119
120
  first_record = db_provider.first(unique_row)
120
121
 
121
- id = resolver.get(first_record, primary_key.column)
122
+ id = resolver.get(first_record, primary_keyed_column.column)
122
123
 
123
- resolver.set(row, primary_key.key, id)
124
+ resolver.set(row, primary_keyed_column.key, id)
124
125
 
125
126
  debug_detail(output, "Record Exists: #{first_record}") if first_record
126
127
 
@@ -133,7 +134,7 @@ module DbFuel
133
134
  # set the created_at and updated_at fields
134
135
  attribute_renderers_set.timestamp_created_attribute_renderers
135
136
  else
136
- attribute_renderer_set.attribute_renderers
137
+ attribute_renderers_set.attribute_renderers
137
138
  end
138
139
 
139
140
  set_object = attribute_renderers_set.transform(dynamic_attrs, row, time)
@@ -144,24 +145,24 @@ module DbFuel
144
145
 
145
146
  id = db_provider.insert(set_object)
146
147
 
147
- # add the primary key name and value to row if primary_key was specified
148
- resolver.set(row, primary_key.key, id) if primary_key
148
+ # add the primary key name and value to row if primary_keyed_column was specified
149
+ resolver.set(row, primary_keyed_column.key, id) if primary_keyed_column
149
150
 
150
151
  debug_detail(output, "Insert Return: #{row}")
151
152
  end
152
153
 
153
154
  # Updates only a single record. Lookups primary key to update the record.
154
155
  def update_record(output, row, time)
155
- raise ArgumentError, 'primary_key is required' unless primary_key
156
+ raise ArgumentError, 'primary_keyed_column is required' unless primary_keyed_column
156
157
 
157
158
  first_record = find_record(output, row, time)
158
159
 
159
160
  if first_record
160
161
  debug_detail(output, "Record Exists: #{first_record}")
161
162
 
162
- id = resolver.get(first_record, primary_key.column)
163
+ id = resolver.get(first_record, primary_keyed_column.column)
163
164
 
164
- where_object = { primary_key.key => id }
165
+ where_object = { primary_keyed_column.column => id }
165
166
 
166
167
  # update record using the primary key as the WHERE clause
167
168
  update(output, row, time, where_object)
@@ -177,7 +178,7 @@ module DbFuel
177
178
  # modify the updated_at field, don't modify the created_at field
178
179
  attribute_renderers_set.timestamp_updated_attribute_renderers
179
180
  else
180
- attribute_renderer_set.attribute_renderers
181
+ attribute_renderers_set.attribute_renderers
181
182
  end
182
183
 
183
184
  set_object = attribute_renderers_set.transform(dynamic_attrs, row, time)
@@ -14,7 +14,8 @@ module DbFuel
14
14
  class Base < Burner::JobWithRegister
15
15
  attr_reader :model,
16
16
  :provider,
17
- :query
17
+ :query,
18
+ :debug
18
19
 
19
20
  # Arguments:
20
21
  # - model: Dbee Model configuration
@@ -22,16 +23,18 @@ module DbFuel
22
23
  # - register: Name of the register to use for gathering the IN clause values and where
23
24
  # to store the resulting recordset.
24
25
  def initialize(
25
- name:,
26
+ name: '',
26
27
  model: {},
27
28
  query: {},
28
- register: Burner::DEFAULT_REGISTER
29
+ register: Burner::DEFAULT_REGISTER,
30
+ debug: false
29
31
  )
30
32
  super(name: name, register: register)
31
33
 
32
34
  @model = ::Dbee::Model.make(model)
33
35
  @provider = ::Dbee::Providers::ActiveRecordProvider.new
34
36
  @query = ::Dbee::Query.make(query)
37
+ @debug = debug || false
35
38
 
36
39
  freeze
37
40
  end
@@ -47,6 +50,12 @@ module DbFuel
47
50
 
48
51
  payload[register] = records
49
52
  end
53
+
54
+ def debug_detail(output, message)
55
+ return unless debug
56
+
57
+ output.detail(message)
58
+ end
50
59
  end
51
60
  end
52
61
  end
@@ -18,16 +18,48 @@ module DbFuel
18
18
  # Expected Payload[register] input: nothing
19
19
  # Payload[register] output: array of objects.
20
20
  class Query < Base
21
+ # Arguments:
22
+ # - name: Name of job.
23
+ # - model: Dbee Model configuration
24
+ # - query: Dbee Query configuration
25
+ #
26
+ # - register: Name of the register to use for gathering the IN clause values and where
27
+ # to store the resulting recordset.
28
+ #
29
+ # - debug: If debug is set to true (defaults to false) then the SQL statements
30
+ # will be printed in the output. Only use this option while
31
+ # debugging issues as it will fill
32
+ # up the output with (potentially too much) data.
33
+ def initialize(
34
+ name: '',
35
+ model: {},
36
+ query: {},
37
+ register: Burner::DEFAULT_REGISTER,
38
+ debug: false
39
+ )
40
+ super(
41
+ model: model,
42
+ name: name,
43
+ query: query,
44
+ register: register,
45
+ debug: debug
46
+ )
47
+ end
48
+
21
49
  def perform(output, payload)
22
- records = execute(sql)
50
+ records = execute(sql(output))
23
51
 
24
52
  load_register(records, output, payload)
25
53
  end
26
54
 
27
55
  private
28
56
 
29
- def sql
30
- ::Dbee.sql(model, query, provider)
57
+ def sql(output)
58
+ sql_statement = ::Dbee.sql(model, query, provider)
59
+
60
+ debug_detail(output, "Query SQL: #{sql_statement}")
61
+
62
+ sql_statement
31
63
  end
32
64
  end
33
65
  end
@@ -32,14 +32,20 @@ module DbFuel
32
32
  # - register: Name of the register to use for gathering the IN clause values and where
33
33
  # to store the resulting recordset.
34
34
  # - separator: Character to use to split the key-path for nested object support.
35
+ #
36
+ # - debug: If debug is set to true (defaults to false) then the SQL statements
37
+ # will be printed in the output. Only use this option while
38
+ # debugging issues as it will fill
39
+ # up the output with (potentially too much) data.
35
40
  def initialize(
36
- name:,
37
41
  key:,
42
+ name: '',
38
43
  key_path: '',
39
44
  model: {},
40
45
  query: {},
41
46
  register: Burner::DEFAULT_REGISTER,
42
- separator: ''
47
+ separator: '',
48
+ debug: false
43
49
  )
44
50
  raise ArgumentError, 'key is required' if key.to_s.empty?
45
51
 
@@ -51,12 +57,13 @@ module DbFuel
51
57
  model: model,
52
58
  name: name,
53
59
  query: query,
54
- register: register
60
+ register: register,
61
+ debug: debug
55
62
  )
56
63
  end
57
64
 
58
65
  def perform(output, payload)
59
- records = execute(sql(payload))
66
+ records = execute(sql(output, payload))
60
67
 
61
68
  load_register(records, output, payload)
62
69
  end
@@ -90,8 +97,13 @@ module DbFuel
90
97
  )
91
98
  end
92
99
 
93
- def sql(payload)
94
- ::Dbee.sql(model, compile_dbee_query(payload), provider)
100
+ def sql(output, payload)
101
+ dbee_query = compile_dbee_query(payload)
102
+ sql_statement = ::Dbee.sql(model, dbee_query, provider)
103
+
104
+ debug_detail(output, "Range SQL: #{sql_statement}")
105
+
106
+ sql_statement
95
107
  end
96
108
  end
97
109
  end
@@ -12,25 +12,31 @@ module DbFuel
12
12
  # Creates attribute renderers based on attributes passed.
13
13
  # Also constains methods to transform attribute renderers
14
14
  # and include timestamp attributes if needed.
15
- class AttributeRendererSet
16
- CREATED_AT = :created_at
15
+ class AttributeRendererSet # :nodoc:
17
16
  NOW_TYPE = 'r/value/now'
18
- UPDATED_AT = :updated_at
17
+
18
+ CREATED_AT = Burner::Modeling::Attribute.make(
19
+ key: :created_at, transformers: [{ type: NOW_TYPE }]
20
+ )
21
+
22
+ UPDATED_AT = Burner::Modeling::Attribute.make(
23
+ key: :updated_at, transformers: [{ type: NOW_TYPE }]
24
+ )
19
25
 
20
26
  attr_reader :attribute_renderers, :resolver
21
27
 
22
- def initialize(attributes: [], resolver: nil)
28
+ def initialize(resolver:, attributes: [])
23
29
  raise ArgumentError, 'resolver is required' unless resolver
24
30
 
25
31
  @resolver = resolver
26
- @attribute_renderers = make_attribute_renderers(attributes)
32
+ @attribute_renderers = make_renderers(attributes)
27
33
 
28
34
  freeze
29
35
  end
30
36
 
31
37
  # Adds the attributes for created_at and updated_at to the currrent attribute renderers.
32
38
  def timestamp_created_attribute_renderers
33
- timestamp_attributes = [created_at_timestamp_attribute, updated_at_timestamp_attribute]
39
+ timestamp_attributes = [CREATED_AT, UPDATED_AT]
34
40
 
35
41
  timestamp_attributes.map do |a|
36
42
  Burner::Modeling::AttributeRenderer.new(a, resolver)
@@ -39,14 +45,14 @@ module DbFuel
39
45
 
40
46
  # Adds the attribute for updated_at to the currrent attribute renderers.
41
47
  def timestamp_updated_attribute_renderers
42
- timestamp_attributes = [updated_at_timestamp_attribute]
48
+ timestamp_attributes = [UPDATED_AT]
43
49
 
44
50
  timestamp_attributes.map do |a|
45
51
  Burner::Modeling::AttributeRenderer.new(a, resolver)
46
52
  end + attribute_renderers
47
53
  end
48
54
 
49
- def make_attribute_renderers(attributes)
55
+ def make_renderers(attributes)
50
56
  Burner::Modeling::Attribute
51
57
  .array(attributes)
52
58
  .map { |a| Burner::Modeling::AttributeRenderer.new(a, resolver) }
@@ -59,25 +65,6 @@ module DbFuel
59
65
  resolver.set(memo, attribute_renderer.key, value)
60
66
  end
61
67
  end
62
-
63
- private
64
-
65
- def created_at_timestamp_attribute
66
- timestamp_attribute(CREATED_AT)
67
- end
68
-
69
- def updated_at_timestamp_attribute
70
- timestamp_attribute(UPDATED_AT)
71
- end
72
-
73
- def timestamp_attribute(key)
74
- Burner::Modeling::Attribute.make(
75
- key: key,
76
- transformers: [
77
- { type: NOW_TYPE }
78
- ]
79
- )
80
- end
81
68
  end
82
69
  end
83
70
  end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module DbFuel
11
- VERSION = '1.2.0-alpha'
11
+ VERSION = '2.0.0'
12
12
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_fuel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre.alpha
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  - John Bosko
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-01-13 00:00:00.000000000 Z
12
+ date: 2021-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -51,14 +51,14 @@ dependencies:
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.2'
54
+ version: '1.7'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.2'
61
+ version: '1.7'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: dbee
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -263,7 +263,7 @@ metadata:
263
263
  documentation_uri: https://www.rubydoc.info/gems/db_fuel
264
264
  homepage_uri: https://github.com/bluemarblepayroll/db_fuel
265
265
  source_code_uri: https://github.com/bluemarblepayroll/db_fuel
266
- post_install_message:
266
+ post_install_message:
267
267
  rdoc_options: []
268
268
  require_paths:
269
269
  - lib
@@ -274,12 +274,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
274
  version: '2.5'
275
275
  required_rubygems_version: !ruby/object:Gem::Requirement
276
276
  requirements:
277
- - - ">"
277
+ - - ">="
278
278
  - !ruby/object:Gem::Version
279
- version: 1.3.1
279
+ version: '0'
280
280
  requirements: []
281
281
  rubygems_version: 3.0.3
282
- signing_key:
282
+ signing_key:
283
283
  specification_version: 4
284
284
  summary: Dbee and ActiveRecord jobs for Burner
285
285
  test_files: []