mysql_framework 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/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mysql_framework.rb +15 -0
- data/lib/mysql_framework/connector.rb +84 -0
- data/lib/mysql_framework/logger.rb +15 -0
- data/lib/mysql_framework/scripts.rb +5 -0
- data/lib/mysql_framework/scripts/base.rb +58 -0
- data/lib/mysql_framework/scripts/manager.rb +137 -0
- data/lib/mysql_framework/scripts/table.rb +11 -0
- data/lib/mysql_framework/sql_column.rb +54 -0
- data/lib/mysql_framework/sql_condition.rb +20 -0
- data/lib/mysql_framework/sql_query.rb +131 -0
- data/lib/mysql_framework/sql_table.rb +23 -0
- data/lib/mysql_framework/version.rb +3 -0
- data/spec/lib/mysql_framework/connector_spec.rb +192 -0
- data/spec/lib/mysql_framework/logger_spec.rb +20 -0
- data/spec/lib/mysql_framework/scripts/base_spec.rb +91 -0
- data/spec/lib/mysql_framework/scripts/manager_spec.rb +161 -0
- data/spec/lib/mysql_framework/sql_column_spec.rb +73 -0
- data/spec/lib/mysql_framework/sql_condition_spec.rb +13 -0
- data/spec/lib/mysql_framework/sql_query_spec.rb +223 -0
- data/spec/lib/mysql_framework/sql_table_spec.rb +26 -0
- data/spec/spec_helper.rb +52 -0
- data/spec/support/procedure.sql +5 -0
- data/spec/support/scripts/create_demo_table.rb +34 -0
- data/spec/support/scripts/create_test_proc.rb +27 -0
- data/spec/support/scripts/create_test_table.rb +34 -0
- data/spec/support/tables/demo.rb +15 -0
- data/spec/support/tables/test.rb +15 -0
- metadata +157 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe MysqlFramework::SqlTable do
|
6
|
+
let(:table) { described_class.new('gems') }
|
7
|
+
|
8
|
+
describe '#[](column)' do
|
9
|
+
it 'returns a new SqlColumn class for the specified column' do
|
10
|
+
expect(table[:version]).to be_a(MysqlFramework::SqlColumn)
|
11
|
+
expect(table[:version].to_s).to eq('`gems`.`version`')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#to_s' do
|
16
|
+
it 'returns the tablename wrapped in backticks' do
|
17
|
+
expect(table.to_s).to eq('`gems`')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#to_sym' do
|
22
|
+
it 'returns the table name as a symbol' do
|
23
|
+
expect(table.to_sym).to eq(:gems)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter 'spec/'
|
4
|
+
end
|
5
|
+
|
6
|
+
ENV['MYSQL_DATABASE'] ||= 'test_database'
|
7
|
+
ENV['MYSQL_HOST'] ||= '127.0.0.1'
|
8
|
+
ENV['MYSQL_PARTITIONS'] ||= '5'
|
9
|
+
ENV['MYSQL_PASSWORD'] ||= ''
|
10
|
+
ENV['MYSQL_PORT'] ||= '3306'
|
11
|
+
ENV['MYSQL_USERNAME'] ||= 'root'
|
12
|
+
ENV['REDIS_URL'] ||= 'redis://127.0.0.1:6379'
|
13
|
+
|
14
|
+
require 'bundler'
|
15
|
+
require 'mysql_framework'
|
16
|
+
require 'securerandom'
|
17
|
+
|
18
|
+
require_relative 'support/scripts/create_test_table'
|
19
|
+
require_relative 'support/scripts/create_demo_table'
|
20
|
+
require_relative 'support/scripts/create_test_proc'
|
21
|
+
require_relative 'support/tables/test'
|
22
|
+
require_relative 'support/tables/demo'
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.expect_with :rspec do |expectations|
|
26
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
27
|
+
end
|
28
|
+
|
29
|
+
config.mock_with :rspec do |mocks|
|
30
|
+
mocks.verify_partial_doubles = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
client = Mysql2::Client.new({
|
35
|
+
host: ENV.fetch('MYSQL_HOST'),
|
36
|
+
port: ENV.fetch('MYSQL_PORT'),
|
37
|
+
username: ENV.fetch('MYSQL_USERNAME'),
|
38
|
+
password: ENV.fetch('MYSQL_PASSWORD'),
|
39
|
+
})
|
40
|
+
client.query("DROP DATABASE IF EXISTS `#{ENV.fetch('MYSQL_DATABASE')}`;")
|
41
|
+
client.query("CREATE DATABASE `#{ENV.fetch('MYSQL_DATABASE')}`;")
|
42
|
+
|
43
|
+
connector = MysqlFramework::Connector.new
|
44
|
+
connector.query("DROP TABLE IF EXISTS `#{ENV.fetch('MYSQL_DATABASE')}`.`gems`")
|
45
|
+
connector.query("CREATE TABLE `#{ENV.fetch('MYSQL_DATABASE')}`.`gems` (
|
46
|
+
`id` CHAR(36) NOT NULL,
|
47
|
+
`name` VARCHAR(255) NULL,
|
48
|
+
`author` VARCHAR(255) NULL,
|
49
|
+
`created_at` DATETIME,
|
50
|
+
`updated_at` DATETIME,
|
51
|
+
PRIMARY KEY (`id`)
|
52
|
+
)")
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MysqlFramework
|
4
|
+
module Support
|
5
|
+
module Scripts
|
6
|
+
class CreateDemoTable < MysqlFramework::Scripts::Base
|
7
|
+
def initialize
|
8
|
+
@identifier = 201806021520 # 15:20 02/06/2018
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply
|
12
|
+
mysql_connector.query(<<~SQL)
|
13
|
+
CREATE TABLE IF NOT EXISTS `#{database_name}`.`demo` (
|
14
|
+
`id` CHAR(36) NOT NULL,
|
15
|
+
`name` VARCHAR(255) NULL,
|
16
|
+
`created_at` DATETIME NOT NULL,
|
17
|
+
|
18
|
+
`updated_at` DATETIME NOT NULL,
|
19
|
+
PRIMARY KEY (`id`)
|
20
|
+
)
|
21
|
+
SQL
|
22
|
+
end
|
23
|
+
|
24
|
+
def rollback
|
25
|
+
raise 'Rollback not supported in test.'
|
26
|
+
end
|
27
|
+
|
28
|
+
def tags
|
29
|
+
[MysqlFramework::Support::Tables::DemoTable::NAME]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MysqlFramework
|
4
|
+
module Support
|
5
|
+
module Scripts
|
6
|
+
class CreateTestProc < MysqlFramework::Scripts::Base
|
7
|
+
def initialize
|
8
|
+
@identifier = 201807031200 # 12:90 03/07/2018
|
9
|
+
end
|
10
|
+
|
11
|
+
PROC_FILE = 'spec/support/procedure.sql'
|
12
|
+
|
13
|
+
def apply
|
14
|
+
update_procedure('test_procedure', PROC_FILE)
|
15
|
+
end
|
16
|
+
|
17
|
+
def rollback
|
18
|
+
raise 'Rollback not supported in test.'
|
19
|
+
end
|
20
|
+
|
21
|
+
def tags
|
22
|
+
[MysqlFramework::Support::Tables::TestTable::NAME, 'TestProc']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MysqlFramework
|
4
|
+
module Support
|
5
|
+
module Scripts
|
6
|
+
class CreateTestTable < MysqlFramework::Scripts::Base
|
7
|
+
def initialize
|
8
|
+
@identifier = 201801011030 # 10:30 01/01/2018
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply
|
12
|
+
mysql_connector.query(<<~SQL)
|
13
|
+
CREATE TABLE IF NOT EXISTS `#{database_name}`.`test` (
|
14
|
+
`id` CHAR(36) NOT NULL,
|
15
|
+
`name` VARCHAR(255) NULL,
|
16
|
+
`action` VARCHAR(255) NULL,
|
17
|
+
`created_at` DATETIME NOT NULL,
|
18
|
+
`updated_at` DATETIME NOT NULL,
|
19
|
+
PRIMARY KEY (`id`)
|
20
|
+
)
|
21
|
+
SQL
|
22
|
+
end
|
23
|
+
|
24
|
+
def rollback
|
25
|
+
raise 'Rollback not supported in test.'
|
26
|
+
end
|
27
|
+
|
28
|
+
def tags
|
29
|
+
[MysqlFramework::Support::Tables::TestTable::NAME]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql_framework
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sage
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mysql2
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redlock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A lightweight framework to provide managers for working with MySQL.
|
98
|
+
email:
|
99
|
+
- support@sageone.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- bin/console
|
105
|
+
- bin/setup
|
106
|
+
- lib/mysql_framework.rb
|
107
|
+
- lib/mysql_framework/connector.rb
|
108
|
+
- lib/mysql_framework/logger.rb
|
109
|
+
- lib/mysql_framework/scripts.rb
|
110
|
+
- lib/mysql_framework/scripts/base.rb
|
111
|
+
- lib/mysql_framework/scripts/manager.rb
|
112
|
+
- lib/mysql_framework/scripts/table.rb
|
113
|
+
- lib/mysql_framework/sql_column.rb
|
114
|
+
- lib/mysql_framework/sql_condition.rb
|
115
|
+
- lib/mysql_framework/sql_query.rb
|
116
|
+
- lib/mysql_framework/sql_table.rb
|
117
|
+
- lib/mysql_framework/version.rb
|
118
|
+
- spec/lib/mysql_framework/connector_spec.rb
|
119
|
+
- spec/lib/mysql_framework/logger_spec.rb
|
120
|
+
- spec/lib/mysql_framework/scripts/base_spec.rb
|
121
|
+
- spec/lib/mysql_framework/scripts/manager_spec.rb
|
122
|
+
- spec/lib/mysql_framework/sql_column_spec.rb
|
123
|
+
- spec/lib/mysql_framework/sql_condition_spec.rb
|
124
|
+
- spec/lib/mysql_framework/sql_query_spec.rb
|
125
|
+
- spec/lib/mysql_framework/sql_table_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/support/procedure.sql
|
128
|
+
- spec/support/scripts/create_demo_table.rb
|
129
|
+
- spec/support/scripts/create_test_proc.rb
|
130
|
+
- spec/support/scripts/create_test_table.rb
|
131
|
+
- spec/support/tables/demo.rb
|
132
|
+
- spec/support/tables/test.rb
|
133
|
+
homepage: https://github.com/sage/mysql_framework
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.7.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: A lightweight framework to provide managers for working with MySQL.
|
157
|
+
test_files: []
|