my_general 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/my_general.rb +1 -0
- data/lib/my_general/instance.rb +60 -16
- data/lib/my_general/version.rb +1 -1
- data/test.db +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8f84cc91082b51a74ab1c8b0cc3b895841e53f3b0d25a777f9ce362733fb7c9
|
4
|
+
data.tar.gz: '0499ab72306d9933feca4084370219f50e9a4987f889a326303eb3dbf46f2de7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e61891e2fb0b60aaa3b36b1fd0f05b5f83974ce58504e770cbd86c258a788d846ea77e64ec727fc87ea561a0b421927b8cbc0c0a57af7a0a527404f8296512c4
|
7
|
+
data.tar.gz: b45df2362797283c1651d37f81cb5ebd1107d1a9bf2ed4dff97925c598c3f23076af1f09e81ac4aebcce16e6103fc74d1542a0b38d8e0bd3ce32baff205bf4e2
|
data/lib/my_general.rb
CHANGED
data/lib/my_general/instance.rb
CHANGED
@@ -2,9 +2,17 @@ class MyGeneral::Instance
|
|
2
2
|
def initialize(log_file, database_file)
|
3
3
|
@complexity = nil
|
4
4
|
@db = nil
|
5
|
+
@time = nil
|
6
|
+
@new_command = false
|
7
|
+
@command = 'Query'
|
8
|
+
@buffer = 'SELECT 1'
|
9
|
+
|
10
|
+
@insert_count = 0
|
11
|
+
@success_count = 0
|
5
12
|
|
6
13
|
@log_file = log_file
|
7
14
|
@database_file = database_file
|
15
|
+
@progressbar = nil
|
8
16
|
end
|
9
17
|
|
10
18
|
def complexity
|
@@ -22,33 +30,69 @@ class MyGeneral::Instance
|
|
22
30
|
puts "[2/4] 🔌 Dailing Database... OK [Connected]"
|
23
31
|
puts '[3/4] ⏳ Importing Data...'
|
24
32
|
run_data
|
25
|
-
puts "[3/4] ⏳ Importing Data... OK [#{
|
33
|
+
puts "[3/4] ⏳ Importing Data... OK [#{@success_count}/#{@insert_count}]"
|
26
34
|
puts '[4/4] 🚩 Finished!'
|
27
35
|
end
|
28
36
|
|
29
37
|
def run_data
|
30
|
-
progressbar = ProgressBar.create
|
31
|
-
progressbar.total = complexity
|
38
|
+
@progressbar = ProgressBar.create(format: '%t: |%B| %c/%C %E')
|
39
|
+
@progressbar.total = complexity
|
32
40
|
File.open(@log_file, 'r') do |file|
|
41
|
+
3.times { file.readline } # Skip 3 lines
|
33
42
|
until file.eof?
|
34
43
|
line = file.readline
|
35
|
-
|
36
|
-
progressbar.increment
|
44
|
+
parse_line(line)
|
45
|
+
@progressbar.increment
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
def parse_line(line)
|
51
|
+
date = line.split("\t")[0]
|
52
|
+
if date =~ /^[0-9]{6}/ # Is Date?
|
53
|
+
@time = DateTime.parse("#{20}#{date}")
|
54
|
+
@command = line.split("\t")[1].split(' ')[-1]
|
55
|
+
@new_command = true
|
56
|
+
elsif line.start_with?("\t\t")
|
57
|
+
@command = line.split("\t")[2].split(' ')[-1]
|
58
|
+
@new_command = true
|
59
|
+
else
|
60
|
+
@new_command = false
|
61
|
+
end
|
62
|
+
|
63
|
+
flush
|
64
|
+
|
65
|
+
if @command == 'Query'
|
66
|
+
@buffer << line.split("\t")[-1]
|
67
|
+
end
|
68
|
+
rescue => e
|
69
|
+
# Ignore
|
70
|
+
end
|
71
|
+
|
72
|
+
def flush
|
73
|
+
if @new_command & !@buffer.empty?
|
74
|
+
# Do query
|
75
|
+
run_query
|
76
|
+
# Refresh variables
|
77
|
+
@new_command = false
|
78
|
+
@buffer = ''
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
VERBS = ['SET', 'INSERT', 'UPDATE', 'DELETE', 'CREATE', 'ALTER', 'DROP'].freeze
|
83
|
+
|
84
|
+
def run_query
|
85
|
+
# return if @time < DateTime.parse("2017-05-13 07:08:00") # Ignore from last backup
|
86
|
+
return if @buffer.upcase.start_with?('CREATE DATABASE') # Ignore database scale query
|
87
|
+
return unless VERBS.map do |verb|
|
88
|
+
@buffer.upcase.start_with?(verb)
|
89
|
+
end.reduce(:|) # Ignore unless exact verb
|
90
|
+
@insert_count += 1
|
91
|
+
@db.run(@buffer)
|
92
|
+
@success_count += 1
|
49
93
|
rescue => e
|
50
|
-
progressbar.log("When executing #{
|
51
|
-
progressbar.log('We met a problem:')
|
52
|
-
progressbar.log(e.inspect)
|
94
|
+
@progressbar.log("When executing #{@time} #{@buffer}")
|
95
|
+
@progressbar.log('We met a problem:')
|
96
|
+
@progressbar.log(e.inspect)
|
53
97
|
end
|
54
98
|
end
|
data/lib/my_general/version.rb
CHANGED
data/test.db
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_general
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir:
|
10
10
|
- bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-01-
|
12
|
+
date: 2018-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-progressbar
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/my_general.rb
|
81
81
|
- lib/my_general/instance.rb
|
82
82
|
- lib/my_general/version.rb
|
83
|
+
- test.db
|
83
84
|
homepage: https://github.com/dsh0416/my_general
|
84
85
|
licenses:
|
85
86
|
- MIT
|