mysql2json_es 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/lib/mysql2json_elasticsearch.rb +53 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8570692cc74cbb5e1344f3dd8982011e1c6a36e9
|
4
|
+
data.tar.gz: 42a40bb80be6a0fbccc65e74e3e2e34d53f5d1c3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c0345279d83713325996095bb8db0dc2fbc01411f11440daa3464d10d7c652d07192af5ae980722c74ade8aa5e0bd17fb4a93451a031da687858a6e4c6fdc8c
|
7
|
+
data.tar.gz: 127465583bb94cb697e314949b87fdf921e1ada26e42c7e4244ea5ae70f4850c6b0efee595d6c53f13fc2beb1a434e655cc1f4416c976c66568f9a18925a036d
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'mysql2'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
def is_json_valid(object)
|
5
|
+
JSON.parse(object)
|
6
|
+
return true
|
7
|
+
rescue JSON::ParserError
|
8
|
+
return false
|
9
|
+
end
|
10
|
+
|
11
|
+
def convert(results)
|
12
|
+
non_json_data = []
|
13
|
+
|
14
|
+
results = Array(results)
|
15
|
+
|
16
|
+
results.each_index do |index|
|
17
|
+
non_json_data.push(results[index]);
|
18
|
+
index += 1
|
19
|
+
puts 'row: '+index.to_s+' parsed'
|
20
|
+
end
|
21
|
+
|
22
|
+
non_json_data.each do |k,v|
|
23
|
+
v.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
non_json_data_hash = Hash[(1...non_json_data.size).zip non_json_data]
|
27
|
+
json_data = non_json_data_hash.to_json
|
28
|
+
|
29
|
+
if is_json_valid(json_data)
|
30
|
+
json_data = json_data.to_s
|
31
|
+
else
|
32
|
+
json_data = 'ParserError: Could not parse to json, retry.'
|
33
|
+
end
|
34
|
+
|
35
|
+
return json_data
|
36
|
+
end
|
37
|
+
|
38
|
+
class Mysql2json
|
39
|
+
def self.query(q, client)
|
40
|
+
results = client.query(q)
|
41
|
+
return convert(results)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.query_export(q, client, filename)
|
45
|
+
results = client.query(q)
|
46
|
+
json_data = convert(results)
|
47
|
+
file = File.open(filename, 'w+')
|
48
|
+
file.write(json_data)
|
49
|
+
file.close()
|
50
|
+
puts 'Data written to %s' % filename
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql2json_es
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Wright
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mysql2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.11
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.11
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.7
|
41
|
+
description: Convert mysql data into json for elasticsearch
|
42
|
+
email: jawerty210@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/mysql2json_elasticsearch.rb
|
48
|
+
homepage: http://rubygems.org/gems/mysql2json_es
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.0.3
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: A simple script to convert mysql data into json, modified for elasticsearch
|
72
|
+
test_files: []
|