patriot-mysql2-client 0.6.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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzBkMTNjMzc0ZGNjNTI2YTljNjdhZDQyZDRiZTZhMDUyZmIzODA2MQ==
5
+ data.tar.gz: !binary |-
6
+ NzVkMGRkY2E2MDFjZWMxNTk0NDc5ZDU1MDBjZjhmNzNkNDI5MmY3Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTViZWZkNzgwNjUzZjA5MjcyMjA2ZWFlYTBkODMzN2ZhM2E1ZTAwNjA4YThi
10
+ ZjdkMGZlMDE4NDBjNTk2MGRlZTExY2M0NTM2ZjAxZjhkMmJlYTRiMWQyYTMx
11
+ YzRkN2QwNjk0YmRhOWYxZjlhNjkyNDRjZTUzYjdmNmZlNDczMWE=
12
+ data.tar.gz: !binary |-
13
+ N2FmNTU4Yzk3NDIzMTYxMDg5MzIzZGUxYjJjOGQzNDg4YTE4Y2E0MTk1MDI5
14
+ NTMwNzU3YTRmOGVmYTRiMjFmMjFmZTU3ZGU2ZGFiY2VhNjE2MGZmNTI3YjMx
15
+ YmU5MTUzZTY1N2YwYTFhNzlhODQ1MDk5MDU2MjZlNmMzNDM3MzU=
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'patriot'
2
+ require 'patriot/util/db_client/mysql2_client'
@@ -0,0 +1,70 @@
1
+ require 'mysql2'
2
+ module Patriot
3
+ module Util
4
+ module DBClient
5
+ # return a mysql2 client
6
+ # @param dbconf [Hash] dbclient configuration
7
+ def mysql2(dbconf = {})
8
+ return Patriot::Util::DBClient::MySQL2Client.new(dbconf)
9
+ end
10
+
11
+ # NOT thread safe
12
+ class MySQL2Client < Patriot::Util::DBClient::Base
13
+ include Patriot::Util::DBClient
14
+
15
+ # @param dbconf [Hash] dbclient configuration
16
+ def initialize(dbconf)
17
+ conf = dbconf
18
+ conf[:port] = dbconf[:port].to_i
19
+ @connection = Mysql2::Client.new(conf)
20
+ end
21
+
22
+ # @see Patriot::Util::DBClient::Base#do_select
23
+ def do_select(query)
24
+ return @connection.query(query).map{|r| HashRecord.new(r)}
25
+ end
26
+
27
+ # @see Patriot::Util::DBClient::Base#build_insert_query
28
+ def build_insert_query(tbl, value, option = {})
29
+ option = {:ignore => false}.merge(option)
30
+ cols, vals = [], []
31
+ value.each do |c,v|
32
+ cols << c
33
+ vals << quote(v)
34
+ end
35
+ if option[:ignore]
36
+ return "INSERT IGNORE INTO #{tbl} (#{cols.join(',')}) VALUES (#{vals.join(',')})"
37
+ else
38
+ return "INSERT INTO #{tbl} (#{cols.join(',')}) VALUES (#{vals.join(',')})"
39
+ end
40
+ end
41
+
42
+ # @see Patriot::Util::DBClient::Base#do_insert
43
+ def do_insert(query)
44
+ @connection.query(query)
45
+ return @connection.last_id
46
+ end
47
+
48
+ # @see Patriot::Util::DBClient::Base#do_update
49
+ def do_update(query)
50
+ @connection.query(query)
51
+ return @connection.affected_rows
52
+ end
53
+
54
+ # @see Patriot::Util::DBClient::Base#close
55
+ def close()
56
+ @connection.close unless @connection.nil?
57
+ end
58
+
59
+ # @see Patriot::Util::DBClient::Base#quote
60
+ def quote(v)
61
+ return 'NULL' if v.nil?
62
+ return "'#{v.to_s}'" if v.is_a?(DateTime)
63
+ val = (v.is_a?(String) ? "'#{Mysql2::Client.escape(v)}'" : v)
64
+ return val
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: patriot-mysql2-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Teruyoshi Zenmyo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-29 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.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: patriot-workflow-scheduler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ description: A db adapter implementation to use mysql as jobstore
42
+ email:
43
+ - zenmyo_teruyoshi@cyberagent.co.jp
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - init.rb
49
+ - lib/patriot/util/db_client/mysql2_client.rb
50
+ homepage: https://github.com/CyberAgent/patriot-workflow-scheduler
51
+ licenses:
52
+ - Apache License, Version 2.0
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: patriot-mysql2-client
70
+ rubygems_version: 2.4.7
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: MySQL2 Client for Patriot Workflow Scheduler
74
+ test_files: []
75
+ has_rdoc: