embulk-plugin-mysql 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/embulk-plugin-mysql.gemspec +25 -0
- data/lib/embulk/mysql/version.rb +8 -0
- data/lib/embulk/output_mysql.rb +99 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b419b7be3f8e73c1dd850388c59207c006a1cf47
|
4
|
+
data.tar.gz: f78ceaac6039b01d4e0474f18de2381bf84c271d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d9c90036cb074bde6abea859a622623b31d56a4ced846b09ba4fcfa1f59c0fd202e2e936060dc51de9588649d97da51ac38d03da3247dd5099ed3539cb60bc2
|
7
|
+
data.tar.gz: dc46c6c7bd08a632f5ffff1a2c3079dd25f0b6755e2a43c452025c9103c7ae4541a30bb26b5ef48a219576b18a48a60b6aa1bc6ea50eab7b33b1b2b79136ae63
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 shiracha
|
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,71 @@
|
|
1
|
+
# embulk-plugin-mysql
|
2
|
+
|
3
|
+
embulk-plugin-mysql is a plugin for embulk.
|
4
|
+
Currently, this plugin only useful for output.
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Make your work space directory.
|
10
|
+
2. Make your bundle file such as followings:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'embulk'
|
14
|
+
gem 'embulk-plugin-mysql'
|
15
|
+
```
|
16
|
+
|
17
|
+
3. execute bundle install
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
4. make and guess embulk config
|
24
|
+
|
25
|
+
You can use output type config to mysql. see also Settings section.
|
26
|
+
|
27
|
+
```yaml
|
28
|
+
exec: {}
|
29
|
+
in:
|
30
|
+
type: file
|
31
|
+
paths: [test.csv]
|
32
|
+
out:
|
33
|
+
type: mysql
|
34
|
+
host: 127.0.0.1
|
35
|
+
username: root
|
36
|
+
password: abcdefghijklmn
|
37
|
+
database: embulk_test
|
38
|
+
table: test000
|
39
|
+
```
|
40
|
+
|
41
|
+
then guess, and run.
|
42
|
+
|
43
|
+
```bash
|
44
|
+
$ bundle exec embulk guess partial-config.yml -o config.yml
|
45
|
+
$ bundle exec embulk run config.yml
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
## Settings
|
50
|
+
|
51
|
+
You can use output settings as followings:
|
52
|
+
|
53
|
+
| Setting element | value |
|
54
|
+
|-----------------------|----------------------------|
|
55
|
+
| type | mysql |
|
56
|
+
| host | _Your mysql host address_ |
|
57
|
+
| port | _Your mysql port number_ |
|
58
|
+
| username | _Your mysql user name_ |
|
59
|
+
| password | _Your mysql password_ |
|
60
|
+
| database | _Your mysql database name_ |
|
61
|
+
| table | _Your mysql table name_ |
|
62
|
+
|
63
|
+
if password is empty or not setted, then embulk-plugin-mysql don't use authorization.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it ( https://github.com/shiracha/embulk-plugin-mysql/fork )
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'embulk/mysql/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'embulk-plugin-mysql'
|
8
|
+
spec.version = Embulk::Plugin::MySQL::VERSION
|
9
|
+
spec.authors = ['shiracha']
|
10
|
+
spec.email = ['shiracha.rikyu@gmail.com']
|
11
|
+
spec.summary = 'Embulk plugin for MySQL.'
|
12
|
+
spec.description = 'Embulk plugin for MySQL.'
|
13
|
+
spec.homepage = 'https://github.com/shiracha/embulk-plugin-mysql'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
|
24
|
+
spec.add_dependency "ruby-mysql", "~> 2.9.13"
|
25
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'mysql'
|
2
|
+
|
3
|
+
module Embulk
|
4
|
+
module Plugin
|
5
|
+
module MySQL
|
6
|
+
|
7
|
+
class NotSupportedSchema < Exception; end
|
8
|
+
|
9
|
+
class OutputMysql < OutputPlugin
|
10
|
+
Plugin.register_output('mysql', self)
|
11
|
+
|
12
|
+
# TODO: use Mysql.prepare
|
13
|
+
|
14
|
+
def self.transaction(config, schema, count, &control)
|
15
|
+
task = {
|
16
|
+
'host' => config.param('host', :string),
|
17
|
+
'port' => config.param('port', :integer, default: 3306),
|
18
|
+
'username' => config.param('username', :string),
|
19
|
+
'password' => config.param('password', :string, default: ''),
|
20
|
+
'database' => config.param('database', :string),
|
21
|
+
'table' => config.param('table', :string),
|
22
|
+
}
|
23
|
+
yield task
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.resume(task, schema, count, &control)
|
28
|
+
# TODO: Supporting resume
|
29
|
+
yield(task)
|
30
|
+
{}
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(task, schema, index)
|
34
|
+
super
|
35
|
+
|
36
|
+
@task = task
|
37
|
+
@schema = schema
|
38
|
+
|
39
|
+
@mysql = self.class.connect task
|
40
|
+
|
41
|
+
sql_schema = self.class.to_mysql_schema schema
|
42
|
+
|
43
|
+
# TODO: RESUMING IS NOT SUPPORTED ON THIS PLUGIN!!!
|
44
|
+
@mysql.query("DROP TABLE IF EXISTS #{quoted_table_name}")
|
45
|
+
@mysql.query("CREATE TABLE #{quoted_table_name} (#{sql_schema})")
|
46
|
+
end
|
47
|
+
|
48
|
+
def close
|
49
|
+
@mysql.close
|
50
|
+
end
|
51
|
+
|
52
|
+
def add(page)
|
53
|
+
require 'pp'
|
54
|
+
statement =
|
55
|
+
page.each do |record|
|
56
|
+
# TODO: Support BULK-INSERT or LOAD INFILE
|
57
|
+
@mysql.query("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{self.class.to_sql_values(record)})")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def quoted_table_name
|
64
|
+
Mysql.quote @task['table']
|
65
|
+
end
|
66
|
+
|
67
|
+
def quoted_column_names
|
68
|
+
@schema.names.map { |name| Mysql.quote name }.join(',')
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.connect(task)
|
72
|
+
Mysql.connect(task['host'], task['username'], task['password'], task['database'], task['port'])
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.to_mysql_schema(schema)
|
76
|
+
schema.names.zip(schema.types)
|
77
|
+
.map { |name, type| "#{Mysql.quote(name)} #{to_sql_type(type)}" }
|
78
|
+
.join(',')
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.to_sql_type(type)
|
82
|
+
case type
|
83
|
+
when :boolean then 'BOOLEAN'
|
84
|
+
when :long then 'BIGINT'
|
85
|
+
when :double then 'DOUBLE'
|
86
|
+
when :string then 'TEXT'
|
87
|
+
when :timestamp then 'TIMESTAMP'
|
88
|
+
else fail NotSupportedSchema, "embulk-plugin-output-mysql cannot take column type #{type}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.to_sql_values(values)
|
93
|
+
values.map {|v| "'#{Mysql.quote(v.to_s)}'"}.join(",")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-plugin-mysql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shiracha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.7'
|
19
|
+
name: bundler
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.0'
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
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
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.9.13
|
47
|
+
name: ruby-mysql
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.9.13
|
55
|
+
description: Embulk plugin for MySQL.
|
56
|
+
email:
|
57
|
+
- shiracha.rikyu@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-plugin-mysql.gemspec
|
68
|
+
- lib/embulk/mysql/version.rb
|
69
|
+
- lib/embulk/output_mysql.rb
|
70
|
+
homepage: https://github.com/shiracha/embulk-plugin-mysql
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.1.9
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Embulk plugin for MySQL.
|
94
|
+
test_files: []
|