spectre-mysql 1.0.0 → 2.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 +4 -4
- data/lib/spectre/mysql.rb +99 -102
- metadata +43 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9db989b8a26228411dfc8f886d44667f8bfd62b93e64312ef3b92aebc4ad5ce1
|
4
|
+
data.tar.gz: 97f5a35097724a2eaf57b1b770190766e7a9859695e9586c51a7408b271603b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a34d8b08f8dd3170d35e373e81f5f891e0ba7b03dab72cad7a93dcba0731cc01a24a5a222bdd75740d9ce578a35621480dc8e6e0faaab5ca023f123ac80c77c8
|
7
|
+
data.tar.gz: 966d579814fdb941c64baf3a989a2a2ecd18ebcd81ef54310e7075b6edf0c8d7bb3e84b9f568b47ab68b36ee674f15224221aa98db4ee131e8fd33c286d5af02
|
data/lib/spectre/mysql.rb
CHANGED
@@ -1,102 +1,99 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'mysql2'
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@__query['query']
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
Spectre.delegate :mysql, :result, to: self
|
101
|
-
end
|
102
|
-
end
|
1
|
+
require 'logger'
|
2
|
+
require 'mysql2'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Spectre
|
6
|
+
module MySQL
|
7
|
+
class MySqlQuery
|
8
|
+
include Spectre::Delegate if defined? Spectre::Delegate
|
9
|
+
|
10
|
+
def initialize query
|
11
|
+
@__query = query
|
12
|
+
end
|
13
|
+
|
14
|
+
def host hostname
|
15
|
+
@__query['host'] = hostname
|
16
|
+
end
|
17
|
+
|
18
|
+
def username user
|
19
|
+
@__query['username'] = user
|
20
|
+
end
|
21
|
+
|
22
|
+
def password pass
|
23
|
+
@__query['password'] = pass
|
24
|
+
end
|
25
|
+
|
26
|
+
def database name
|
27
|
+
@__query['database'] = name
|
28
|
+
end
|
29
|
+
|
30
|
+
def query statement
|
31
|
+
@__query['query'] = [] unless @__query.key? 'query'
|
32
|
+
@__query['query'].append(statement)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Client
|
37
|
+
include Spectre::Delegate if defined? Spectre::Delegate
|
38
|
+
|
39
|
+
def initialize config, logger
|
40
|
+
@config = config['mysql'] || {}
|
41
|
+
@logger = logger
|
42
|
+
|
43
|
+
@result = nil
|
44
|
+
@last_conn = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def mysql(name = nil, &)
|
48
|
+
query = {}
|
49
|
+
|
50
|
+
if !name.nil? and @config.key? name
|
51
|
+
query.merge! @config[name]
|
52
|
+
|
53
|
+
unless query['host']
|
54
|
+
raise "No `host' set for MySQL client '#{name}'. Check your MySQL config in your environment."
|
55
|
+
end
|
56
|
+
|
57
|
+
elsif !name.nil?
|
58
|
+
query['host'] = name
|
59
|
+
elsif @last_conn.nil?
|
60
|
+
raise 'No name given and there was no previous MySQL connection to use'
|
61
|
+
end
|
62
|
+
|
63
|
+
MySqlQuery.new(query).instance_eval(&) if block_given?
|
64
|
+
|
65
|
+
unless name.nil?
|
66
|
+
@last_conn = {
|
67
|
+
host: query['host'],
|
68
|
+
username: query['username'],
|
69
|
+
password: query['password'],
|
70
|
+
database: query['database'],
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
@logger.info "Connecting to database #{query['username']}@#{query['host']}:#{query['database']}"
|
75
|
+
|
76
|
+
client = ::Mysql2::Client.new(**@last_conn)
|
77
|
+
|
78
|
+
res = []
|
79
|
+
|
80
|
+
query['query']&.each do |statement|
|
81
|
+
@logger.info("Executing statement '#{statement}'")
|
82
|
+
res = client.query(statement, cast_booleans: true)
|
83
|
+
end
|
84
|
+
|
85
|
+
@result = res.map { |row| OpenStruct.new row } if res
|
86
|
+
|
87
|
+
client.close
|
88
|
+
end
|
89
|
+
|
90
|
+
def result
|
91
|
+
raise 'No MySQL query has been executed yet' unless @result
|
92
|
+
|
93
|
+
@result
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Engine.register(MySQL::Client, :mysql, :result) if defined? Engine
|
99
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectre-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Neubauer
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-21 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: bigdecimal
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: logger
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
13
40
|
- !ruby/object:Gem::Dependency
|
14
41
|
name: mysql2
|
15
42
|
requirement: !ruby/object:Gem::Requirement
|
16
43
|
requirements:
|
17
44
|
- - ">="
|
18
45
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
46
|
+
version: '0'
|
20
47
|
type: :runtime
|
21
48
|
prerelease: false
|
22
49
|
version_requirements: !ruby/object:Gem::Requirement
|
23
50
|
requirements:
|
24
51
|
- - ">="
|
25
52
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
53
|
+
version: '0'
|
27
54
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
55
|
+
name: ostruct
|
29
56
|
requirement: !ruby/object:Gem::Requirement
|
30
57
|
requirements:
|
31
58
|
- - ">="
|
32
59
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
60
|
+
version: '0'
|
34
61
|
type: :runtime
|
35
62
|
prerelease: false
|
36
63
|
version_requirements: !ruby/object:Gem::Requirement
|
37
64
|
requirements:
|
38
65
|
- - ">="
|
39
66
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
67
|
+
version: '0'
|
41
68
|
description: Adds MySQL access functionality to the spectre framework
|
42
69
|
email:
|
43
|
-
-
|
70
|
+
- christian.neubauer@ionos.com
|
44
71
|
executables: []
|
45
72
|
extensions: []
|
46
73
|
extra_rdoc_files: []
|
47
74
|
files:
|
48
75
|
- lib/spectre/mysql.rb
|
49
|
-
homepage: https://
|
76
|
+
homepage: https://github.com/ionos-spectre/spectre-mysql
|
50
77
|
licenses:
|
51
|
-
-
|
78
|
+
- GPL-3.0-or-later
|
52
79
|
metadata:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
changelog_uri: https://bitbucket.org/cneubaur/spectre-mysql/src/master/CHANGELOG.md
|
57
|
-
post_install_message:
|
80
|
+
homepage_uri: https://github.com/ionos-spectre/spectre-mysql
|
81
|
+
source_code_uri: https://github.com/ionos-spectre/spectre-mysql
|
82
|
+
changelog_uri: https://github.com/ionos-spectre/spectre-mysql/blob/develop/CHANGELOG.md
|
58
83
|
rdoc_options: []
|
59
84
|
require_paths:
|
60
85
|
- lib
|
@@ -62,15 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
87
|
requirements:
|
63
88
|
- - ">="
|
64
89
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
90
|
+
version: '3.4'
|
66
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
92
|
requirements:
|
68
93
|
- - ">="
|
69
94
|
- !ruby/object:Gem::Version
|
70
95
|
version: '0'
|
71
96
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
-
signing_key:
|
97
|
+
rubygems_version: 3.6.2
|
74
98
|
specification_version: 4
|
75
99
|
summary: MySQL module for spectre
|
76
100
|
test_files: []
|