db_fuel 1.2.1.pre.alpha → 1.2.1.pre.alpha.1

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: ec22f03a9d7d5f09732805c47ffc8a31f8a366360ede468ca484e643629b146f
4
- data.tar.gz: 2342697a6bbf0933c82e85a32a60de1d26d76642af6d29f6d17dee40d3ddc2d7
3
+ metadata.gz: 0a93b59424a5cf6866f1061785f41a0c49c1bcc707ce84a6652f481a283aab64
4
+ data.tar.gz: 3b7a65c38a5cc24ee844412ef6cb1bc3b2bc2a33c9afd564196e1b1f739108b7
5
5
  SHA512:
6
- metadata.gz: 3016049ce85ba26c078f0d5f16cdd6aceb06765973c940bef11b250aae7d588af5204733d6ed51436d43560d31eed415f5c5d6b3b774e0f3ad41202990a69429
7
- data.tar.gz: e81158e2ac4d716a6d89e8de86a5c9f5c124c5929f10b857be7eb2ac35c029d3cb6ca6acf33e001dacaf9f88432ff6465d6dc646fecb7652dc1f840eabffd6fc
6
+ metadata.gz: f5bc7c2644584e1f8e0412e0215bef34b6431b085e18fba822723e94ab0baea9c7a97a25d4970dc9169a2adc23f7818d618f48f8ab2f9d7ddb9f5a5914ecd356
7
+ data.tar.gz: 02d4f517420b8aa3331d99a69dadd39faa7b53382e89f153467eaea3d74a52141e75c000cba62c090e8e0aaa2fb2d293908160b016b242e35d483f396e37b542
data/README.md CHANGED
@@ -32,8 +32,8 @@ Refer to the [Burner](https://github.com/bluemarblepayroll/burner) library for m
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
@@ -42,7 +42,7 @@ module DbFuel
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,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
@@ -25,13 +26,15 @@ module DbFuel
25
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,6 +32,11 @@ 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
41
  name:,
37
42
  key:,
@@ -39,7 +44,8 @@ module DbFuel
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
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module DbFuel
11
- VERSION = '1.2.1-alpha'
11
+ VERSION = '1.2.1-alpha.1'
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_fuel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1.pre.alpha
4
+ version: 1.2.1.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-01-14 00:00:00.000000000 Z
12
+ date: 2021-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord