ductr-postgres 0.2.1 → 0.2.2

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: 0b4bcb117297ac764d6502a16c53b8d19628b112c22cbe617e8e5caf2a8f173d
4
- data.tar.gz: ebf1858ea1d46b63b10db3dfc8246c98e8dcff86fb776193e8062927a37a463b
3
+ metadata.gz: 36ad408e367b91cf43f7c39992afc4b0436a9ce485026c3d36886005dc7f3083
4
+ data.tar.gz: aa9cba25e04afb1b9546bc9f94e2ae227f1965068365d0568da49f6a69e06082
5
5
  SHA512:
6
- metadata.gz: 6b73627f397c2407fae4295204ca5d5a1de413ad06249cb812593f1a4ca796dae5a6563764c815d2e63d99f6b2740236836205d5780e461abd2db2d19b1ac650
7
- data.tar.gz: 8a2587f3ed3db58bafc84e9b0a3b26b569068d18a7048e945024d93a4544cf6e57ed23a963618cf6efa22abb0521ffaab9aeb0e5ff37af79c7ba929bcb18ac4a
6
+ metadata.gz: 51ee731c10a8dfd6e2db2b6c6c0d1887b8fcdacdbe82ba1b5e81a4ac5cfd154f2ffcf9bbe7a7d1c77270bc430fe8001ac8ac2d09bbc423fbd5442667998ee929
7
+ data.tar.gz: 364f2b5da9a2fc1699ee5078deebcdcb7f2c4eaf78e0b119a51a0083ac23e8494815dfadc41ca7891435f5ce07bff6fcf2f656edf54396cdd03b5911355a94bb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ductr-postgres (0.2.1)
4
+ ductr-postgres (0.2.2)
5
5
  ductr (>= 0.2)
6
6
  pg (~> 1.5)
7
7
  sequel (~> 5.91)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module Postgres
5
+ #
6
+ # A destination control that that writes rows one by one, registered as `:basic`:
7
+ #
8
+ # destination :some_postgres_database, :basic
9
+ # def select_some_stuff(db, row)
10
+ # db[:items].update(row)
11
+ # end
12
+ #
13
+ class BasicDestination < Ductr::SequelBase::BasicDestination
14
+ Adapter.destination_registry.add(self, as: :basic)
15
+ end
16
+ end
17
+ end
@@ -3,6 +3,6 @@
3
3
  module Ductr
4
4
  module Postgres
5
5
  # @return [String] VERSION Gem's version
6
- VERSION = "0.2.1"
6
+ VERSION = "0.2.2"
7
7
  end
8
8
  end
@@ -7,8 +7,7 @@ module Ductr
7
7
  # To get details about the database connection handling, checkout the {Ductr::Postgres::Adapter} class.
8
8
  #
9
9
  # ### Sources
10
- # - {Ductr::Postgres::BasicSource} Yields rows one by one.
11
- # - {Ductr::Postgres::PaginatedSource} Allows to select a big number of rows by relying on pagination.
10
+ # - {Ductr::Postgres::BasicSource} Yields rows one by one using postgres streaming feature.
12
11
  #
13
12
  # ### Lookups
14
13
  # - {Ductr::Postgres::BasicLookup} Executes one query per row and merge the looked up row with the current row.
@@ -41,7 +40,7 @@ module Ductr
41
40
  # General sequel options
42
41
  # @see https://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html#label-postgres
43
42
  # PostgreSQL specific options
44
- class Adapter < Ductr::Adapter
43
+ class Adapter < Ductr::SequelBase::Adapter
45
44
  # sord warn - Sequel::Database wasn't able to be resolved to a constant in this project
46
45
  # Opens the database connection with the adapter's configuration.
47
46
  #
@@ -50,10 +49,6 @@ module Ductr
50
49
 
51
50
  # Closes the database connection.
52
51
  def close!: () -> void
53
-
54
- # sord warn - Sequel::Database wasn't able to be resolved to a constant in this project
55
- # _@return_ — The database connection instance
56
- attr_reader db: Sequel::Database?
57
52
  end
58
53
 
59
54
  #
@@ -69,13 +64,19 @@ module Ductr
69
64
  # ensure that column names are different or they will be overwritten.
70
65
  #
71
66
  # If the lookup returns a falsy value, nothing won't be merged with the current row.
72
- class BasicLookup < Ductr::ETL::Transform
73
- # Calls the job's method to merge its result with the current row.
74
- #
75
- # _@param_ `row` — The current row, preferably a Hash
76
- #
77
- # _@return_ — The row merged with looked up row or the untouched row if nothing was found
78
- def process: (::Hash[Symbol, Object] row) -> ::Hash[Symbol, Object]
67
+ class BasicLookup < Ductr::SequelBase::BasicLookup
68
+ end
69
+
70
+ #
71
+ # A source control that yields rows usnig the PostgreSQL streaming feature, registered as `:basic`:
72
+ #
73
+ # source :some_postgres_database, :basic
74
+ # def select_some_stuff(db)
75
+ # db[:items].limit(42)
76
+ # end
77
+ #
78
+ # You can select a large number of rows, without worrying about pagination handling or memory usage.
79
+ class BasicSource < Ductr::SequelBase::BasicSource
79
80
  end
80
81
 
81
82
  #
@@ -93,32 +94,7 @@ module Ductr
93
94
  # def merge_with_stuff(db, ids)
94
95
  # db[:items_bis].where(item: ids)
95
96
  # end
96
- class MatchLookup < Ductr::ETL::BufferedTransform
97
- # The looked up row key to match.
98
- #
99
- # _@return_ — The column name
100
- def from_key: () -> Symbol
101
-
102
- # The buffer row key to match.
103
- #
104
- # _@return_ — The column name
105
- def to_key: () -> Symbol
106
-
107
- # Opens the database if needed, calls the job's method and merges
108
- # the looked up rows with corresponding buffer rows.
109
- def on_flush: () ?{ (::Hash[Symbol, Object] row) -> void } -> void
110
-
111
- # Find the corresponding row into the buffer.
112
- #
113
- # _@param_ `row` — The looked up row
114
- #
115
- # _@return_ — the matching row if exists
116
- def buffer_find: (::Hash[Symbol, Object] row) -> ::Hash[Symbol, Object]?
117
-
118
- # Maps the buffer keys into an array.
119
- #
120
- # _@return_ — The keys array
121
- def buffer_keys: () -> ::Array[(Integer | String)]
97
+ class MatchLookup < Ductr::SequelBase::MatchLookup
122
98
  end
123
99
 
124
100
  #
@@ -137,26 +113,7 @@ module Ductr
137
113
  # yield(row.merge match)
138
114
  # end
139
115
  # end
140
- class BufferedLookup < Ductr::ETL::BufferedTransform
141
- # Opens the database if needed, calls the job's method and pass the each block to it.
142
- def on_flush: () -> void
143
- end
144
-
145
- #
146
- # The rufus-scheduler handler class.
147
- # @see https://github.com/jmettraux/rufus-scheduler#scheduling-handler-instances
148
- # For further information
149
- class PollingHandler
150
- # sord warn - Ductr::Adapter wasn't able to be resolved to a constant in this project
151
- # Creates the handler based on the given scheduler, its method name and the trigger's adapter instance.
152
- #
153
- # _@param_ `method` — The scheduler's method
154
- #
155
- # _@param_ `adapter` — The trigger's adapter
156
- def initialize: (Method method, Ductr::Adapter adapter) -> void
157
-
158
- # The callable method used by the trigger, actually calls the scheduler's method.
159
- def call: () -> void
116
+ class BufferedLookup < Ductr::SequelBase::BufferedLookup
160
117
  end
161
118
 
162
119
  #
@@ -170,35 +127,17 @@ module Ductr
170
127
  #
171
128
  # MyJob.perform_later
172
129
  # end
173
- class PollingTrigger < Ductr::RufusTrigger
174
- # Closes the connection if the scheduler is stopped.
175
- def stop: () -> void
176
-
177
- # sord duck - #call looks like a duck type, replacing with untyped
178
- # Returns a callable object, allowing rufus-scheduler to call it.
179
- #
180
- # _@param_ `scheduler` — The scheduler instance
181
- #
182
- # _@param_ `method` — The scheduler's method
183
- #
184
- # _@param_ `**` — The option passed to the trigger annotation
185
- #
186
- # _@return_ — A callable object
187
- def callable: (Method method) -> untyped
130
+ class PollingTrigger < Ductr::SequelBase::PollingTrigger
188
131
  end
189
132
 
190
133
  #
191
- # A source control that yields rows usnig the PostgreSQL streaming feature, registered as `:streamed`:
134
+ # A destination control that that writes rows one by one, registered as `:basic`:
192
135
  #
193
- # source :some_postgres_database, :streamed
194
- # def select_some_stuff(db)
195
- # db[:items].limit(42)
136
+ # destination :some_postgres_database, :basic
137
+ # def select_some_stuff(db, row)
138
+ # db[:items].update(row)
196
139
  # end
197
- #
198
- # You can select a large number of rows, without worrying about pagination handling or memory usage.
199
- class StreamedSource < Ductr::ETL::Source
200
- # Opens the database, calls the job's method and iterate over the query results.
201
- def each: () -> void
140
+ class BasicDestination < Ductr::SequelBase::BasicDestination
202
141
  end
203
142
 
204
143
  #
@@ -211,9 +150,7 @@ module Ductr
211
150
  # end
212
151
  #
213
152
  # @see more Ductr::ETL::BufferedDestination
214
- class BufferedDestination < Ductr::ETL::BufferedDestination
215
- # Open the database if needed and call the job's method to run the query.
216
- def on_flush: () -> void
153
+ class BufferedDestination < Ductr::SequelBase::BufferedDestination
217
154
  end
218
155
 
219
156
  #
@@ -221,24 +158,12 @@ module Ductr
221
158
  # Accept the `:buffer_size` option, default value is 10 000:
222
159
  #
223
160
  # destination :some_postgres_database, :buffered_upsert, buffer_size: 42
224
- # def my_destination(buffer, excluded, db)
161
+ # def my_destination(db, excluded, buffer)
225
162
  # db[:items].insert_conflict(target: :id, update: excluded).multi_insert(buffer)
226
163
  # end
227
164
  #
228
165
  # @see more Ductr::ETL::BufferedDestination
229
- class BufferedUpsertDestination < Ductr::ETL::BufferedDestination
230
- # Open the database if needed and call the job's method to run the query.
231
- def on_flush: () -> void
232
-
233
- # sord warn - Sequel::SQL::QualifiedIdentifier wasn't able to be resolved to a constant in this project
234
- # Generate the excluded keys hash e.g.
235
- #
236
- # ```ruby
237
- # {a: Sequel[:excluded][:a]}
238
- # ```
239
- #
240
- # _@return_ — The excluded keys hash
241
- def excluded: () -> ::Hash[Symbol, Sequel::SQL::QualifiedIdentifier]
166
+ class BufferedUpsertDestination < Ductr::SequelBase::BufferedUpsertDestination
242
167
  end
243
168
  end
244
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ductr-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Morel
@@ -225,6 +225,7 @@ files:
225
225
  - ductr-postgres.gemspec
226
226
  - lib/ductr/postgres.rb
227
227
  - lib/ductr/postgres/adapter.rb
228
+ - lib/ductr/postgres/basic_destination.rb
228
229
  - lib/ductr/postgres/basic_lookup.rb
229
230
  - lib/ductr/postgres/basic_source.rb
230
231
  - lib/ductr/postgres/buffered_destination.rb