onlyoffice_mysql_helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a4dc9f484d18654ce5d10d7302fac2d193c650069b84fb7bc28f57d41fa5cf64
4
+ data.tar.gz: f3ca7face439c1bd4a5c47b6487c4dccf3be0a8ca584a3a1dde1273628d6556e
5
+ SHA512:
6
+ metadata.gz: 368edb533b097c7febd99784aa209ad13e3550dcf28834888ace3815677fe301a76b479452d5fbfd6f9c098921253b82c74525425dad4b2b51e2b9e7820d6dc1
7
+ data.tar.gz: 384af581103aa4b1d149c421acbabb0d1a4cea0892166fdc9f02c2c3ab9d4adc2e69eb63dbab7374c7729d19d0f99372fba429ae60d3f213c6a9351dcfc40630
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onlyoffice_logger_helper'
4
+ require 'onlyoffice_mysql_helper/mysql_helper'
5
+ require 'onlyoffice_mysql_helper/mysql_logger'
6
+ require 'onlyoffice_mysql_helper/version'
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mysql2'
4
+ module OnlyofficeMysqlHelper
5
+ # Class for using mysql
6
+ class MySQLHelper
7
+ attr_accessor :mysql
8
+ attr_accessor :database
9
+ SQL_SERVER_ADDRESS_LOCAL = '127.0.0.1'
10
+ SQL_SERVER_USER_LOCAL = 'root'
11
+ SQL_SERVER_PASSWORD_LOCAL = ''
12
+
13
+ def initialize(address: SQL_SERVER_ADDRESS_LOCAL,
14
+ database: 'performance_test',
15
+ user: SQL_SERVER_USER_LOCAL,
16
+ password: SQL_SERVER_PASSWORD_LOCAL)
17
+ @connection = Mysql2::Client.new(host: address,
18
+ username: user,
19
+ password: password, database: database)
20
+ @database = database
21
+ end
22
+
23
+ def add_record(table_name, hash)
24
+ send_query do
25
+ "INSERT INTO `#{table_name}` (`id`, #{from_query_keys(hash)}) "\
26
+ "VALUES (NULL,#{from_query_values(hash)});"
27
+ end
28
+ end
29
+
30
+ def create_table(name, columns = 'id INT PRIMARY KEY AUTO_INCREMENT')
31
+ send_query { "CREATE TABLE IF NOT EXISTS `#{name}`(#{columns});" }
32
+ end
33
+
34
+ def select_records(table_name, condition = '')
35
+ send_query do
36
+ query = "SELECT * FROM `#{table_name}`"
37
+ query += " #{condition}" unless condition == ''
38
+ query + ';'
39
+ end
40
+ end
41
+
42
+ def tables
43
+ send_query { 'SHOW TABLES;' }
44
+ end
45
+
46
+ def delete_record(table_name, condition)
47
+ send_query { "DELETE FROM `#{table_name}` WHERE #{condition};" }
48
+ end
49
+
50
+ def drop_table(table_name)
51
+ send_query { "DROP TABLE `#{table_name}`;" }
52
+ end
53
+
54
+ private
55
+
56
+ def send_query
57
+ yield
58
+ OnlyofficeLoggerHelper.log("Query: #{yield}")
59
+ @connection.query(yield)
60
+ end
61
+
62
+ def from_query_keys(hash)
63
+ query_keys = ''
64
+ hash.each_key do |key_value|
65
+ query_keys += "`#{key_value}`,"
66
+ end
67
+ query_keys.chop!
68
+ end
69
+
70
+ def from_query_values(hash)
71
+ query_values = ''
72
+ hash.each_value do |value|
73
+ query_values += "'#{value.to_s.delete("'")}',"
74
+ end
75
+ query_values.chop!
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeMysqlHelper
4
+ # Log action in mysql
5
+ class MySQLLogger
6
+ attr_accessor :mysql
7
+ attr_accessor :table
8
+ attr_accessor :hash
9
+
10
+ def initialize(mysql = MySQLHelper.new, table = nil, hash = {})
11
+ @mysql = mysql
12
+ @table = table
13
+ @hash = hash
14
+ end
15
+
16
+ # Create table for logging purposes
17
+ # @param table_name [String] name of table to create
18
+ # @return [Void]
19
+ def create_log_table(table_name, column)
20
+ table_command = 'id INT PRIMARY KEY AUTO_INCREMENT, '\
21
+ "#{column} VARCHAR(25) NOT NULL, "\
22
+ 'time VARCHAR(255) NOT NULL, '\
23
+ 'operation VARCHAR(255) NOT NULL'
24
+ @mysql.create_table(table_name, table_command)
25
+ end
26
+
27
+ def log_actions(action, hash)
28
+ mysql_hash = hash.merge(@hash)
29
+ mysql_hash[:time] = Time.now
30
+ mysql_hash[:operation] = "Start: #{action}"
31
+ @mysql.add_record(@table, mysql_hash)
32
+
33
+ yield
34
+
35
+ mysql_hash[:time] = Time.now
36
+ mysql_hash[:operation] = "Finished: #{action}"
37
+ @mysql.add_record(@table, mysql_hash)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeMysqlHelper
4
+ NAME = 'onlyoffice_mysql_helper'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeMysqlHelper
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onlyoffice_mysql_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ONLYOFFICE
8
+ - Pavel Lobashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-04-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mysql2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: onlyoffice_logger_helper
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '13.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '13.0'
56
+ description: Simple MySQL wrapper. Used in QA of ONLYOFFICE
57
+ email:
58
+ - shockwavenn@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/onlyoffice_mysql_helper.rb
64
+ - lib/onlyoffice_mysql_helper/mysql_helper.rb
65
+ - lib/onlyoffice_mysql_helper/mysql_logger.rb
66
+ - lib/onlyoffice_mysql_helper/name.rb
67
+ - lib/onlyoffice_mysql_helper/version.rb
68
+ homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_mysql_helper
69
+ licenses:
70
+ - AGPL-3.0
71
+ metadata:
72
+ bug_tracker_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_mysql_helper/issues
73
+ changelog_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_mysql_helper/blob/master/CHANGELOG.md
74
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_mysql_helper
75
+ homepage_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_mysql_helper
76
+ source_code_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_mysql_helper
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '2.3'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.1.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Simple MySQL wrapper
96
+ test_files: []