ductr-postgres 0.2.1 → 0.2.3

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: 6520956f9b414c8d7d5160d2372a918d3049eb6e2e77253ca452508873d2be53
4
+ data.tar.gz: ea1a31f688bac96edb6086979cb8971801d4627aee0f388ca446e7eba8146382
5
5
  SHA512:
6
- metadata.gz: 6b73627f397c2407fae4295204ca5d5a1de413ad06249cb812593f1a4ca796dae5a6563764c815d2e63d99f6b2740236836205d5780e461abd2db2d19b1ac650
7
- data.tar.gz: 8a2587f3ed3db58bafc84e9b0a3b26b569068d18a7048e945024d93a4544cf6e57ed23a963618cf6efa22abb0521ffaab9aeb0e5ff37af79c7ba929bcb18ac4a
6
+ metadata.gz: a266df884d476d6959462c84163db5b4845b2b2f6bb410f0b787a9c87c22fb4312c3d281a646adc3c6a806710d3b95869da037992a1a33224742ece1a7a7ea57
7
+ data.tar.gz: b378256691dec18c7bf1cf037f616e75335bbb1bbe0eb99d9e08cd180974b5fd85f508472078142eb0a3967e56d39e20923bd8b2bd45428657cdc8c07acc562c
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)
@@ -31,12 +31,7 @@ module Ductr
31
31
  # @return [Sequel::Database] The database connection instance
32
32
  #
33
33
  def open!
34
- @db = Sequel.postgres(**config)
35
-
36
- @db.extension(:pg_streaming)
37
- @db.stream_all_queries = true
38
-
39
- @db
34
+ @db = new_connection
40
35
  end
41
36
 
42
37
  #
@@ -47,6 +42,20 @@ module Ductr
47
42
  def close!
48
43
  @db.disconnect
49
44
  end
45
+
46
+ #
47
+ # Open a new connection, ensure to close it with the #disconnect method.
48
+ #
49
+ # @return [Sequel::Database] The database connection instance
50
+ #
51
+ def new_connection
52
+ db = Sequel.postgres(**config)
53
+
54
+ db.extension(:pg_streaming)
55
+ db.stream_all_queries = true
56
+
57
+ db
58
+ end
50
59
  end
51
60
  end
52
61
  end
@@ -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].where(id: row[:id]).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.3"
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
  #
@@ -52,8 +51,10 @@ module Ductr
52
51
  def close!: () -> void
53
52
 
54
53
  # sord warn - Sequel::Database wasn't able to be resolved to a constant in this project
54
+ # Open a new connection, ensure to close it with the #disconnect method.
55
+ #
55
56
  # _@return_ — The database connection instance
56
- attr_reader db: Sequel::Database?
57
+ def new_connection: () -> Sequel::Database
57
58
  end
58
59
 
59
60
  #
@@ -69,13 +70,19 @@ module Ductr
69
70
  # ensure that column names are different or they will be overwritten.
70
71
  #
71
72
  # 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]
73
+ class BasicLookup < Ductr::SequelBase::BasicLookup
74
+ end
75
+
76
+ #
77
+ # A source control that yields rows usnig the PostgreSQL streaming feature, registered as `:basic`:
78
+ #
79
+ # source :some_postgres_database, :basic
80
+ # def select_some_stuff(db)
81
+ # db[:items].limit(42)
82
+ # end
83
+ #
84
+ # You can select a large number of rows, without worrying about pagination handling or memory usage.
85
+ class BasicSource < Ductr::SequelBase::BasicSource
79
86
  end
80
87
 
81
88
  #
@@ -93,32 +100,7 @@ module Ductr
93
100
  # def merge_with_stuff(db, ids)
94
101
  # db[:items_bis].where(item: ids)
95
102
  # 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)]
103
+ class MatchLookup < Ductr::SequelBase::MatchLookup
122
104
  end
123
105
 
124
106
  #
@@ -137,26 +119,7 @@ module Ductr
137
119
  # yield(row.merge match)
138
120
  # end
139
121
  # 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
122
+ class BufferedLookup < Ductr::SequelBase::BufferedLookup
160
123
  end
161
124
 
162
125
  #
@@ -170,35 +133,17 @@ module Ductr
170
133
  #
171
134
  # MyJob.perform_later
172
135
  # 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
136
+ class PollingTrigger < Ductr::SequelBase::PollingTrigger
188
137
  end
189
138
 
190
139
  #
191
- # A source control that yields rows usnig the PostgreSQL streaming feature, registered as `:streamed`:
140
+ # A destination control that that writes rows one by one, registered as `:basic`:
192
141
  #
193
- # source :some_postgres_database, :streamed
194
- # def select_some_stuff(db)
195
- # db[:items].limit(42)
142
+ # destination :some_postgres_database, :basic
143
+ # def select_some_stuff(db, row)
144
+ # db[:items].where(id: row[:id]).update(**row)
196
145
  # 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
146
+ class BasicDestination < Ductr::SequelBase::BasicDestination
202
147
  end
203
148
 
204
149
  #
@@ -211,9 +156,7 @@ module Ductr
211
156
  # end
212
157
  #
213
158
  # @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
159
+ class BufferedDestination < Ductr::SequelBase::BufferedDestination
217
160
  end
218
161
 
219
162
  #
@@ -221,24 +164,12 @@ module Ductr
221
164
  # Accept the `:buffer_size` option, default value is 10 000:
222
165
  #
223
166
  # destination :some_postgres_database, :buffered_upsert, buffer_size: 42
224
- # def my_destination(buffer, excluded, db)
167
+ # def my_destination(db, excluded, buffer)
225
168
  # db[:items].insert_conflict(target: :id, update: excluded).multi_insert(buffer)
226
169
  # end
227
170
  #
228
171
  # @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]
172
+ class BufferedUpsertDestination < Ductr::SequelBase::BufferedUpsertDestination
242
173
  end
243
174
  end
244
175
  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.3
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