ductr-sqlite 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING.LESSER ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ductr-sqlite.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ductr-sqlite (0.1.1)
5
+ annotable (~> 0.1)
6
+ ductr (~> 0.1)
7
+ sequel (~> 5.66)
8
+ sqlite3 (~> 1.6)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activejob (7.0.4.3)
14
+ activesupport (= 7.0.4.3)
15
+ globalid (>= 0.3.6)
16
+ activesupport (7.0.4.3)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ annotable (0.1.2)
22
+ ast (2.4.2)
23
+ colorize (0.8.1)
24
+ commander (4.6.0)
25
+ highline (~> 2.0.0)
26
+ concurrent-ruby (1.2.2)
27
+ diff-lcs (1.5.0)
28
+ docile (1.4.0)
29
+ ductr (0.1.0)
30
+ activejob (~> 7.0)
31
+ annotable (~> 0.1)
32
+ colorize (~> 0.8)
33
+ kiba (~> 4.0)
34
+ rufus-scheduler (~> 3.8)
35
+ thor (~> 1.2)
36
+ zeitwerk (~> 2.6)
37
+ et-orbi (1.2.7)
38
+ tzinfo
39
+ fugit (1.8.1)
40
+ et-orbi (~> 1, >= 1.2.7)
41
+ raabro (~> 1.4)
42
+ globalid (1.1.0)
43
+ activesupport (>= 5.0)
44
+ highline (2.0.3)
45
+ i18n (1.12.0)
46
+ concurrent-ruby (~> 1.0)
47
+ json (2.6.3)
48
+ kiba (4.0.0)
49
+ minitest (5.18.0)
50
+ parallel (1.22.1)
51
+ parlour (5.0.0)
52
+ commander (~> 4.5)
53
+ parser
54
+ rainbow (~> 3.0)
55
+ sorbet-runtime (>= 0.5)
56
+ parser (3.2.1.1)
57
+ ast (~> 2.4.1)
58
+ raabro (1.4.0)
59
+ rainbow (3.1.1)
60
+ rake (13.0.6)
61
+ redcarpet (3.6.0)
62
+ regexp_parser (2.7.0)
63
+ rexml (3.2.5)
64
+ rspec (3.12.0)
65
+ rspec-core (~> 3.12.0)
66
+ rspec-expectations (~> 3.12.0)
67
+ rspec-mocks (~> 3.12.0)
68
+ rspec-core (3.12.1)
69
+ rspec-support (~> 3.12.0)
70
+ rspec-expectations (3.12.2)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.12.0)
73
+ rspec-mocks (3.12.4)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.12.0)
76
+ rspec-support (3.12.0)
77
+ rubocop (1.48.1)
78
+ json (~> 2.3)
79
+ parallel (~> 1.10)
80
+ parser (>= 3.2.0.0)
81
+ rainbow (>= 2.2.2, < 4.0)
82
+ regexp_parser (>= 1.8, < 3.0)
83
+ rexml (>= 3.2.5, < 4.0)
84
+ rubocop-ast (>= 1.26.0, < 2.0)
85
+ ruby-progressbar (~> 1.7)
86
+ unicode-display_width (>= 2.4.0, < 3.0)
87
+ rubocop-ast (1.27.0)
88
+ parser (>= 3.2.1.0)
89
+ rubocop-capybara (2.17.1)
90
+ rubocop (~> 1.41)
91
+ rubocop-rspec (2.19.0)
92
+ rubocop (~> 1.33)
93
+ rubocop-capybara (~> 2.17)
94
+ ruby-progressbar (1.13.0)
95
+ rufus-scheduler (3.8.2)
96
+ fugit (~> 1.1, >= 1.1.6)
97
+ sequel (5.66.0)
98
+ simplecov (0.22.0)
99
+ docile (~> 1.1)
100
+ simplecov-html (~> 0.11)
101
+ simplecov_json_formatter (~> 0.1)
102
+ simplecov-html (0.12.3)
103
+ simplecov_json_formatter (0.1.4)
104
+ sorbet-runtime (0.5.10712)
105
+ sord (4.0.0)
106
+ commander (~> 4.5)
107
+ parlour (~> 5.0)
108
+ sorbet-runtime
109
+ yard
110
+ sqlite3 (1.6.1-x86_64-linux)
111
+ thor (1.2.1)
112
+ tzinfo (2.0.6)
113
+ concurrent-ruby (~> 1.0)
114
+ unicode-display_width (2.4.2)
115
+ webrick (1.7.0)
116
+ yard (0.9.28)
117
+ webrick (~> 1.7.0)
118
+ zeitwerk (2.6.7)
119
+
120
+ PLATFORMS
121
+ x86_64-linux
122
+
123
+ DEPENDENCIES
124
+ ductr-sqlite!
125
+ rake (~> 13.0)
126
+ redcarpet (~> 3.5)
127
+ rspec (~> 3.11)
128
+ rubocop (~> 1.29)
129
+ rubocop-rspec (~> 2.11)
130
+ simplecov (~> 0.21)
131
+ sord (~> 4.0)
132
+ yard (~> 0.9)
133
+
134
+ BUNDLED WITH
135
+ 2.3.26
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # SQLite adapter for Ductr ETL
2
+ This gem provides useful controls to operate Ductr with SQLite databases.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's `Gemfile`:
7
+
8
+ ```ruby
9
+ gem 'ductr-sqlite'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ ```bash
15
+ $ bundle install
16
+ ```
17
+
18
+ Require `ductr/sqlite` in the `config/app.rb` file:
19
+
20
+ ```ruby
21
+ require "ductr/sqlite"
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ You can now use the adapter in your YAML configuration:
27
+
28
+ ```yml
29
+ adapters:
30
+ some_sqlite_database:
31
+ adapter: "sqlite"
32
+ database: "example.db"
33
+ ```
34
+
35
+ You can pass any option recognized by sequel.
36
+ See [the Sequel SQLite options list](https://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/SQLite/Database.html#method-i-connect) for further details.
37
+
38
+ The configured adapter can now be used in Ductr jobs e.g.:
39
+
40
+ ```ruby
41
+ source :some_sqlite_database, :paginated, page_size: 42
42
+ def select_some_stuff(db, offset, limit)
43
+ db[:items].offset(offset).limit(limit)
44
+ end
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ductr-io/ductr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ductr-io/ductr-sqlite/blob/main/CODE_OF_CONDUCT.md).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the Ductr::SQLite project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ductr-io/ductr-sqlite/blob/main/CODE_OF_CONDUCT.md).
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [LGPLv3 or later](https://opensource.org/license/lgpl-3-0/).
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
13
+
14
+ require "sord"
15
+
16
+ desc "Generates RBS file from the yard documentation"
17
+ task :sord do
18
+ options = {
19
+ rbs: true,
20
+ sord_comments: true,
21
+ regenerate: true,
22
+ break_params: 4,
23
+ replace_errors_with_untyped: false,
24
+ replace_unresolved_with_untyped: false,
25
+ exclude_messages: nil,
26
+ include_messages: nil,
27
+ keep_original_comments: false,
28
+ skip_constants: false,
29
+ use_original_initialize_return: false,
30
+ exclude_untyped: false
31
+ }
32
+
33
+ plugin = Sord::ParlourPlugin.new(options)
34
+ plugin.parlour = Parlour::RbsGenerator.new(break_params: options[:break_params])
35
+ plugin.generate(plugin.parlour.root)
36
+
37
+ File.write("sig/ductr/sqlite.rbs", plugin.parlour.send(:rbs))
38
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ductr/sqlite/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ductr-sqlite"
7
+ spec.version = Ductr::SQLite::VERSION
8
+ spec.authors = ["Mathieu MOREL"]
9
+ spec.email = ["mathieu@lamanufacture.dev"]
10
+ spec.licenses = ["LGPL-3.0-or-later"]
11
+
12
+ spec.summary = "SQLite adapter for Ductr using the `sequel` gem"
13
+ spec.description = "Allows rocket to interact with SQLite DMBS."
14
+ spec.homepage = "https://github.com/ductr-io/ductr"
15
+ spec.required_ruby_version = ">= 3.1.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+ spec.metadata["rubygems_mfa_required"] = "true"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_dependency "annotable", "~> 0.1"
36
+ spec.add_dependency "ductr", "~> 0.1"
37
+ spec.add_dependency "sequel", "~> 5.66"
38
+ spec.add_dependency "sqlite3", "~> 1.6"
39
+
40
+ spec.add_development_dependency "rake", "~> 13.0"
41
+ spec.add_development_dependency "redcarpet", "~> 3.5"
42
+ spec.add_development_dependency "rspec", "~> 3.11"
43
+ spec.add_development_dependency "rubocop", "~> 1.29"
44
+ spec.add_development_dependency "rubocop-rspec", "~> 2.11"
45
+ spec.add_development_dependency "simplecov", "~> 0.21"
46
+ spec.add_development_dependency "sord", "~> 4.0"
47
+ spec.add_development_dependency "yard", "~> 0.9"
48
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module SQLite
5
+ #
6
+ # The SQLite adapter class implement the required #open! and #close! methods to handle the database connection.
7
+ # The adapter is registered as `:sqlite` to use it, add `adapter: sqlite` to the YAML configuration e.g.:
8
+ #
9
+ # ```yml
10
+ # # config/development.yml
11
+ # adapters:
12
+ # some_sqlite_database:
13
+ # adapter: "sqlite"
14
+ # database: "example.db"
15
+ # ```
16
+ #
17
+ class Adapter < Ductr::Adapter
18
+ Ductr.adapter_registry.add(self, as: :sqlite)
19
+
20
+ # @return [Sequel::Database, nil] The database connection instance
21
+ attr_reader :db
22
+
23
+ #
24
+ # Opens the database connection with the adapter's configuration.
25
+ #
26
+ # @return [Sequel::Database] The database connection instance
27
+ #
28
+ def open!
29
+ @db = Sequel.sqlite(**config)
30
+ end
31
+
32
+ #
33
+ # Closes the database connection.
34
+ # In the specific case of SQLite, we just destroy the connection instance.
35
+ #
36
+ # @return [void]
37
+ #
38
+ def close!
39
+ @db = nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module SQLite
5
+ #
6
+ # A destination control that write rows one by one, registered as `:basic`:
7
+ #
8
+ # destination :some_sqlite_database, :basic
9
+ # def my_destination(row, db)
10
+ # db[:items].insert(row)
11
+ # end
12
+ #
13
+ class BasicDestination < Ductr::ETL::Destination
14
+ Adapter.destination_registry.add(self, as: :basic)
15
+
16
+ #
17
+ # Opens the database if needed and call the job's method to insert one row at time.
18
+ #
19
+ # @param [Hash<Symbol, Object>] row The row to insert, preferably a Hash
20
+ #
21
+ # @return [void]
22
+ #
23
+ def write(row)
24
+ call_method(row, adapter.db)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module SQLite
5
+ #
6
+ # A lookup control that execute one query per row, registered as `:basic`.
7
+ # The job's method must return a row which will merged with the current row:
8
+ #
9
+ # lookup :some_sqlite_database, :basic
10
+ # def my_lookup(row, db)
11
+ # db[:items_bis].where(item: row[:id]).limit(1)
12
+ # end
13
+ #
14
+ # As the control merge the looked up row with the current row,
15
+ # ensure that column names are different or they will be overwritten.
16
+ #
17
+ # If the lookup returns a falsy value, nothing won't be merged with the current row.
18
+ #
19
+ class BasicLookup < Ductr::ETL::Transform
20
+ Adapter.lookup_registry.add(self, as: :basic)
21
+
22
+ #
23
+ # Calls the job's method to merge its result with the current row.
24
+ #
25
+ # @param [Hash<Symbol, Object>] row The current row, preferably a Hash
26
+ #
27
+ # @return [Hash<Symbol, Object>] The row merged with looked up row or the untouched row if nothing was found
28
+ #
29
+ def process(row)
30
+ matching_row = call_method(row, adapter.db).first
31
+ return row unless matching_row
32
+
33
+ row.merge matching_row
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module SQLite
5
+ #
6
+ # A source control that yields rows one by one, registered as `:basic`:
7
+ #
8
+ # source :some_sqlite_database, :basic
9
+ # def select_some_stuff(db)
10
+ # db[:items].limit(42)
11
+ # end
12
+ #
13
+ # Do not try to select a large number of rows, as they will all be loaded into memory.
14
+ #
15
+ class BasicSource < Ductr::ETL::Source
16
+ Adapter.source_registry.add(self, as: :basic)
17
+
18
+ #
19
+ # Opens the database, calls the job's method and iterate over the query results.
20
+ #
21
+ # @yield The each block
22
+ #
23
+ # @return [void]
24
+ #
25
+ def each(&)
26
+ call_method(adapter.db).each(&)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module SQLite
5
+ #
6
+ # A destination control that accumulates rows in a buffer to write them by batch, registered as `:buffered`.
7
+ # Accept the `:buffer_size` option, default value is 10 000:
8
+ #
9
+ # destination :some_sqlite_database, :buffered, buffer_size: 42
10
+ # def my_destination(buffer, db)
11
+ # db[:items].multi_insert(buffer)
12
+ # end
13
+ #
14
+ # @see more Ductr::ETL::BufferedDestination
15
+ #
16
+ class BufferedDestination < Ductr::ETL::BufferedDestination
17
+ Adapter.destination_registry.add(self, as: :buffered)
18
+
19
+ #
20
+ # Open the database if needed and call the job's method to run the query.
21
+ #
22
+ # @return [void]
23
+ #
24
+ def on_flush
25
+ call_method(buffer, adapter.db)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ module SQLite
5
+ #
6
+ # A lookup control that execute the query for a bunch of rows, registered as `:buffered`.
7
+ # Accept the `:buffer_size` option, default value is 10 000.
8
+ # You have to implement your own row matching logic:
9
+ #
10
+ # lookup :some_sqlite_database, :buffered, buffer_size: 42
11
+ # def my_lookup(db, buffer, &)
12
+ # ids = buffer.map {|row| row[:id]}
13
+ # db[:items].where(item: ids).each do |row|
14
+ # match = buffer.find { |r| r[:id] == row[:item] }
15
+ #
16
+ # next yield(row) unless match
17
+ #
18
+ # yield(row.merge match)
19
+ # end
20
+ # end
21
+ #
22
+ class BufferedLookup < Ductr::ETL::BufferedTransform
23
+ Adapter.lookup_registry.add(self, as: :buffered)
24
+
25
+ #
26
+ # Opens the database if needed, calls the job's method and pass the each block to it.
27
+ #
28
+ # @yield The each block
29
+ #
30
+ # @return [void]
31
+ #
32
+ def on_flush(&)
33
+ call_method(adapter.db, buffer, &)
34
+ end
35
+ end
36
+ end
37
+ end