mysql2-replication 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6ae9d1fad0e2e04991f29377512bbb06a581e22816940081f5700858d049fe7
4
+ data.tar.gz: 9fb9fbc2a541d0a7d0ac6a5e88a2c7c8a43fcb1a1f37fe7c8ed9b98b2e47e7d5
5
+ SHA512:
6
+ metadata.gz: 0f372f65fca1c3325715e64bd494762133571ad32626b696ffe93824a55bcb05e60c40f73da3d9794df0a6af8e298ebdb53ada2e023eb987e68626141a145407
7
+ data.tar.gz: 77abcac0b26e45cca163d14ea83e7204f262ad2407a2265744c124ac7dc6d5590a00fdbc78ec292f2df1ce7719bd3a9b7eca35c7de8f6a0bb925277d8a0b0fed
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # -*- ruby -*-
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec
6
+
7
+ gem "bundler"
8
+ gem "rake"
9
+ gem "test-unit"
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Sutou Kouhei <kou@clear-code.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # mysql2-replication
2
+
3
+ ## Description
4
+
5
+ mysql2-replication is an extension of [mysql2 gem](https://rubygems.org/gems/mysql2). It adds support for replication client feature based on `libmariadb.so` that is a MySQL/MariaDB client library provided by MariaDB.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install mysql2-replication
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require "mysql2-replication"
17
+
18
+ client = Mysql2::Client.new(username: "root",
19
+ password: "secret")
20
+ # Get the latest binlog file and position from source.
21
+ # You can specify them manually.
22
+ master_status = client.query("SHOW MASTER STATUS").first
23
+ file = master_status["File"]
24
+ position = master_status["Position"]
25
+
26
+ replication_client = Mysql2Replication::Client(client)
27
+ replication_client.file_name = file
28
+ replication_client.start_position = position
29
+ replication_client.open do
30
+ replication_client.each do |event|
31
+ pp event
32
+ end
33
+ end
34
+ ```
35
+
36
+ ## License
37
+
38
+ The MIT license. See `LICENSE.txt` for details.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "bundler/gem_helper"
5
+
6
+ base_dir = File.join(__dir__)
7
+
8
+ helper = Bundler::GemHelper.new(base_dir)
9
+ def helper.version_tag
10
+ version
11
+ end
12
+
13
+ helper.install
14
+ spec = helper.gemspec
15
+
16
+ desc "Run tests"
17
+ task :test do
18
+ ruby("test/run.rb")
19
+ end
20
+
21
+ task default: :test
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "ostruct"
5
+
6
+ require "mysql2-replication"
7
+
8
+ options = OpenStruct.new
9
+ options.user = nil
10
+ options.password = nil
11
+ options.host = nil
12
+ options.port = nil
13
+ options.socket = nil
14
+ options.file_name = nil
15
+ options.start_position = nil
16
+
17
+ parser = OptionParser.new
18
+ parser.version = Mysql2Replication::VERSION
19
+ parser.on("--user=USER",
20
+ "User to be connected") do |user|
21
+ options.user = user
22
+ end
23
+ parser.on("--password=PASSWORD",
24
+ "Password for the user") do |password|
25
+ options.password = password
26
+ end
27
+ parser.on("--host=HOST",
28
+ "Host to be connected") do |host|
29
+ options.host = host
30
+ end
31
+ parser.on("--port=PORT", Integer,
32
+ "Port to be connected") do |port|
33
+ options.port = port
34
+ end
35
+ parser.on("--socket=SOCKET",
36
+ "Socket to be connected") do |socket|
37
+ options.socket = socket
38
+ end
39
+ parser.on("--file-name=NAME",
40
+ "File name to be read") do |file_name|
41
+ options.file_name = file_name
42
+ end
43
+ parser.on("--start-position=POSITION", Integer,
44
+ "Start position to be read") do |position|
45
+ options.start_position = position
46
+ end
47
+
48
+ parser.parse!
49
+
50
+ client = Mysql2::Client.new(username: options.user,
51
+ password: options.password,
52
+ host: options.host,
53
+ port: options.port,
54
+ socket: options.socket)
55
+ if options.file_name.nil? and options.start_position.nil?
56
+ master_status = client.query("SHOW MASTER STATUS").first
57
+ options.file_name = master_status["File"]
58
+ options.start_position = master_status["Position"]
59
+ end
60
+
61
+ replication_client = Mysql2Replication::Client.new(client)
62
+ if options.file_name
63
+ replication_client.file_name = options.file_name
64
+ end
65
+ replication_client.start_position = options.start_position || 4
66
+ replication_client.open do
67
+ replication_client.each do |event|
68
+ pp event
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module Mysql2Replication
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "bigdecimal"
2
+ require "date"
3
+
4
+ require "mysql2"
5
+ require "mysql2_replication.so"
6
+
7
+ require "mysql2-replication/version"
@@ -0,0 +1,36 @@
1
+ # -*- ruby -*-
2
+
3
+ clean_white_space = lambda do |entry|
4
+ entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
5
+ end
6
+
7
+ require_relative "lib/mysql2-replication/version"
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "mysql2-replication"
11
+ spec.version = Mysql2Replication::VERSION
12
+ spec.homepage = "https://github.com/groonga/mysql2-replication"
13
+ spec.authors = ["Sutou Kouhei"]
14
+ spec.email = ["kou@clear-code.com"]
15
+
16
+ readme = File.read("README.md")
17
+ readme.force_encoding("UTF-8")
18
+ entries = readme.split(/^\#\#\s(.*)$/)
19
+ clean_white_space.call(entries[entries.index("Description") + 1])
20
+ description = clean_white_space.call(entries[entries.index("Description") + 1])
21
+ spec.summary, spec.description, = description.split(/\n\n+/, 3)
22
+ spec.license = "GPL-3.0+"
23
+ spec.files = [
24
+ "README.md",
25
+ "LICENSE.txt",
26
+ "Rakefile",
27
+ "Gemfile",
28
+ "#{spec.name}.gemspec",
29
+ ]
30
+ spec.files += Dir.glob("lib/**/*.rb")
31
+ Dir.chdir("bin") do
32
+ spec.executables = Dir.glob("*")
33
+ end
34
+
35
+ spec.add_runtime_dependency("mysql2")
36
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mysql2-replication
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sutou Kouhei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-16 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: ''
28
+ email:
29
+ - kou@clear-code.com
30
+ executables:
31
+ - mysql2-replication-dump
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - bin/mysql2-replication-dump
40
+ - lib/mysql2-replication.rb
41
+ - lib/mysql2-replication/version.rb
42
+ - mysql2-replication.gemspec
43
+ homepage: https://github.com/groonga/mysql2-replication
44
+ licenses:
45
+ - GPL-3.0+
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.3.0.dev
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: mysql2-replication is an extension of [mysql2 gem](https://rubygems.org/gems/mysql2).
66
+ It adds support for replication client feature based on `libmariadb.so` that is
67
+ a MySQL/MariaDB client library provided by MariaDB.
68
+ test_files: []