embulk-output-sqlite3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +3 -0
- data/embulk-output-sqlite3.gemspec +19 -0
- data/lib/embulk/output/sqlite3.rb +122 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3302026b7025675685d138a633e0b74dbaa50df2
|
4
|
+
data.tar.gz: 4c85792d76b73ff224b9c5395022d2e1e48d5c44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9b82794acbf13f12f79cfb3b72abbd7d1c288aa583ba81a4b31131101d221097214aa63305268d75cb76dbf4d0e1cbe1628e56f4b515eda10c1676f26f0ffca
|
7
|
+
data.tar.gz: 1d588103e1b8285e74f9692f1fd23a5ac15ceb0f5a84e6fef93e86454c10342ec70624472bab0bfc2e37bf6af6ca9229eadc028bba2b433c3077db27e492917b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Yuichi Takada
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Sqlite3 output plugin for Embulk
|
2
|
+
|
3
|
+
embulk-output-sqlite3 provides output plugin for Embulk.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: output
|
8
|
+
* **Load all or nothing**: no
|
9
|
+
* **Resume supported**: no
|
10
|
+
* **Cleanup supported**: yes
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
|
14
|
+
- **database**: path of sqlite3 database (string, required)
|
15
|
+
- **table**: name of insert table(string, required)
|
16
|
+
|
17
|
+
## Example
|
18
|
+
|
19
|
+
```yaml
|
20
|
+
out:
|
21
|
+
type: sqlite3
|
22
|
+
database: '/tmp/test.db'
|
23
|
+
table: 'load01'
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
## Build
|
28
|
+
|
29
|
+
```
|
30
|
+
$ rake
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/takady/embulk-output-sqlite3/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "embulk-output-sqlite3"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Yuichi Takada"]
|
5
|
+
spec.email = ["takadyuichi@gmail.com"]
|
6
|
+
spec.summary = "SQLite3 output plugin for Embulk"
|
7
|
+
spec.description = spec.summary
|
8
|
+
spec.homepage = "https://github.com/takady/embulk-output-sqlite3"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files -z`.split("\x0")
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
17
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
18
|
+
spec.add_dependency "jdbc-sqlite3"
|
19
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Output
|
3
|
+
require 'jdbc/sqlite3'
|
4
|
+
Jdbc::SQLite3.load_driver
|
5
|
+
|
6
|
+
class Sqlite3OutputPlugin < OutputPlugin
|
7
|
+
Plugin.register_output("sqlite3", self)
|
8
|
+
|
9
|
+
def self.transaction(config, schema, count, &control)
|
10
|
+
columns = schema.map {|c| "`#{c.name}`" }
|
11
|
+
column_types = schema.map {|c| "#{to_sqlite_column_type(c.type.to_s)}" }
|
12
|
+
|
13
|
+
task = {
|
14
|
+
'database' => config.param('database', :string),
|
15
|
+
'table' => config.param('table', :string),
|
16
|
+
'columns' => columns,
|
17
|
+
'column_types' => column_types,
|
18
|
+
}
|
19
|
+
|
20
|
+
connect(task) do |sqlite|
|
21
|
+
execute_sql(sqlite, %[create table if not exists #{task['table']}(#{to_sqlite_schema(schema)})])
|
22
|
+
end
|
23
|
+
|
24
|
+
commit_reports = yield(task)
|
25
|
+
next_config_diff = {}
|
26
|
+
return next_config_diff
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.to_sqlite_schema(schema)
|
30
|
+
schema.map {|column| "`#{column.name}` #{to_sqlite_column_type(column.type.to_s)}" }.join(',')
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.to_sqlite_column_type(type)
|
34
|
+
case type
|
35
|
+
when 'long' then
|
36
|
+
'integer'
|
37
|
+
when 'string' then
|
38
|
+
'text'
|
39
|
+
when 'timestamp' then
|
40
|
+
'text'
|
41
|
+
when 'double' then
|
42
|
+
'real'
|
43
|
+
else
|
44
|
+
type
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.connect(task)
|
49
|
+
url = "jdbc:sqlite:#{task['database']}"
|
50
|
+
sqlite = org.sqlite.JDBC.new.connect(url, java.util.Properties.new)
|
51
|
+
if block_given?
|
52
|
+
begin
|
53
|
+
yield sqlite
|
54
|
+
ensure
|
55
|
+
sqlite.close
|
56
|
+
end
|
57
|
+
end
|
58
|
+
sqlite
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.execute_sql(sqlite, sql, *args)
|
62
|
+
stmt = sqlite.createStatement
|
63
|
+
begin
|
64
|
+
stmt.execute(sql)
|
65
|
+
ensure
|
66
|
+
stmt.close
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def init
|
71
|
+
@sqlite = self.class.connect(task)
|
72
|
+
@records = 0
|
73
|
+
end
|
74
|
+
|
75
|
+
def close
|
76
|
+
@sqlite.close
|
77
|
+
end
|
78
|
+
|
79
|
+
def add(page)
|
80
|
+
prep = @sqlite.prepareStatement(%[insert into #{@task['table']}(#{@task['columns'].join(',')}) values (#{@task['columns'].map{|c| '?' }.join(',')})])
|
81
|
+
begin
|
82
|
+
page.each do |record|
|
83
|
+
|
84
|
+
@task['column_types'].each_with_index do |type, index|
|
85
|
+
case type
|
86
|
+
when 'integer' then
|
87
|
+
prep.setInt(index+1, record[index])
|
88
|
+
when 'string' then
|
89
|
+
prep.setString(index+1, record[index])
|
90
|
+
when 'timestamp' then
|
91
|
+
prep.setString(index+1, record[index].to_s)
|
92
|
+
when 'double' then
|
93
|
+
prep.setString(index+1, record[index].to_f)
|
94
|
+
else
|
95
|
+
prep.setString(index+1, record[index].to_s)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
prep.execute
|
100
|
+
@records += 1
|
101
|
+
end
|
102
|
+
ensure
|
103
|
+
prep.close
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def finish
|
108
|
+
end
|
109
|
+
|
110
|
+
def abort
|
111
|
+
end
|
112
|
+
|
113
|
+
def commit
|
114
|
+
commit_report = {
|
115
|
+
"records" => @records
|
116
|
+
}
|
117
|
+
return commit_report
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-sqlite3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuichi Takada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jdbc-sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: SQLite3 output plugin for Embulk
|
56
|
+
email:
|
57
|
+
- takadyuichi@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- embulk-output-sqlite3.gemspec
|
68
|
+
- lib/embulk/output/sqlite3.rb
|
69
|
+
homepage: https://github.com/takady/embulk-output-sqlite3
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: SQLite3 output plugin for Embulk
|
93
|
+
test_files: []
|