mysql_import 0.4.0 → 0.4.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 +4 -4
- data/README.md +64 -1
- data/lib/mysql_import/logger.rb +4 -2
- data/lib/mysql_import/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7019a15ca8ae5846ef8014d300a886464a8ab02e
|
4
|
+
data.tar.gz: 2c8cf6cf654037eb44e047a7cf44874032a4f42d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 758364cd6d87430daff77c55734aa09e1e9273352138410f91c40352920eb56e5b1a7d3a3d0140269c2ae7cf3f218b481059abfe1ad784716680b33a4845c178
|
7
|
+
data.tar.gz: b251b30800e0a56517d8073faa8dae7b73a247e45f2909e91c2cac7c8cf96681fa9c39d1f1d3ebb615526863525d258482e3183c3eacc795329ecb7ab5a29dce
|
data/README.md
CHANGED
@@ -57,6 +57,56 @@ importer.import
|
|
57
57
|
# => Import to `users` table from three csv files
|
58
58
|
```
|
59
59
|
|
60
|
+
### Options
|
61
|
+
|
62
|
+
#### #initialize
|
63
|
+
|
64
|
+
Key that can be passed to the second argument of the option of `MysqlImport#initialize` is the four types.
|
65
|
+
|
66
|
+
concurrency: The number of threads to use. Ruby' GIL is released when the IO waiting occurs in mysql, you might be effective by concurrent processing. (default: 2)
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
importer = MysqlImport.new(db_config, concurrency: 4)
|
70
|
+
```
|
71
|
+
|
72
|
+
log: This is an option for the logger. (default: nil)
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# File path
|
76
|
+
importer = MysqlImport.new(db_config, log: '/path/to/import.log')
|
77
|
+
```
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# nil(This is the same as `/dev/null`)
|
81
|
+
importer = MysqlImport.new(db_config, log: nil)
|
82
|
+
```
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
# STDOUT / STDERR
|
86
|
+
importer = MysqlImport.new(db_config, log: $stdout)
|
87
|
+
```
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# Custom logger
|
91
|
+
importer = MysqlImport.new(db_config, log: CustomLogger.new)
|
92
|
+
```
|
93
|
+
|
94
|
+
debug: This is a flag to the level of the logger to debug. (default: false)
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
importer = MysqlImport.new(db_config, log: $stdout, debug: true)
|
98
|
+
```
|
99
|
+
|
100
|
+
sql_opts: This is the option of import to be passed directly to the second argument of `LoadDataInfile2#initialize`.
|
101
|
+
|
102
|
+
See more details for import options.
|
103
|
+
|
104
|
+
https://github.com/nalabjp/load_data_infile2#sql-options
|
105
|
+
|
106
|
+
#### #add
|
107
|
+
|
108
|
+
The second argument of `MysqlImport#add` will be passed directly to the second argument of `LoadDataInfile2#import`.
|
109
|
+
|
60
110
|
See more details for import options.
|
61
111
|
|
62
112
|
https://github.com/nalabjp/load_data_infile2#sql-options
|
@@ -67,6 +117,8 @@ If you want to import only a specific file, you can specify the file.
|
|
67
117
|
|
68
118
|
The specification of the file will be used regular expression
|
69
119
|
|
120
|
+
#### String
|
121
|
+
|
70
122
|
```ruby
|
71
123
|
importer = MysqlImport.new(db_config)
|
72
124
|
importer.add('/path/to/users.csv')
|
@@ -74,11 +126,22 @@ importer.add('/path/to/groups.csv')
|
|
74
126
|
importer.add('/path/to/departments.csv')
|
75
127
|
importer.import('users')
|
76
128
|
# => Only import to `users` table
|
129
|
+
```
|
130
|
+
|
131
|
+
#### Array
|
77
132
|
|
78
|
-
|
133
|
+
```ruby
|
134
|
+
importer.import(['users', 'groups'])
|
79
135
|
# => Import to `users` and `groups` table
|
80
136
|
```
|
81
137
|
|
138
|
+
If empry:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
importer.import([])
|
142
|
+
# => Do not import anything
|
143
|
+
```
|
144
|
+
|
82
145
|
### Hook
|
83
146
|
|
84
147
|
You are able to set the hook immediately before and after import.
|
data/lib/mysql_import/logger.rb
CHANGED
@@ -6,17 +6,19 @@ class MysqlImport
|
|
6
6
|
case out
|
7
7
|
when String
|
8
8
|
obj = ::Logger.new(out)
|
9
|
+
obj.level = ::Logger::INFO
|
9
10
|
when NilClass
|
10
11
|
obj = ::Logger.new(nil)
|
11
12
|
when STDOUT, STDERR
|
12
13
|
obj = ::Logger.new(out)
|
13
14
|
obj.formatter = ->(_, _, _, message) { "#{String === message ? message : message.inspect}\n" }
|
15
|
+
obj.level = ::Logger::INFO
|
14
16
|
else
|
15
17
|
obj = out
|
16
18
|
end
|
17
19
|
|
18
|
-
obj.level =
|
19
|
-
|
20
|
+
obj.level = ::Logger::DEBUG if debug
|
21
|
+
super(obj)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
data/lib/mysql_import/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nalabjp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: load_data_infile2
|
@@ -139,4 +139,3 @@ signing_key:
|
|
139
139
|
specification_version: 4
|
140
140
|
summary: Simple concurrent importer for MySQL
|
141
141
|
test_files: []
|
142
|
-
has_rdoc:
|