swift-db-mysql 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +4 -0
- data/README.md +30 -2
- data/ext/swift/db/mysql/common.c +15 -4
- data/ext/swift/db/mysql/datetime.c +5 -0
- data/ext/swift/db/mysql/datetime.h +8 -5
- data/ext/swift/db/mysql/extconf.rb +1 -0
- data/test/test_async.rb +10 -8
- data/test/test_ssl.rb +7 -6
- metadata +28 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee5b272d79d1ac384a2e922b217fa23ee4c1ef74
|
4
|
+
data.tar.gz: e765c67b44843fb780decc4e9eff46b0c8721810
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57b271d67812362c0c2e776420db1f4673c8ac9a5b6dd7670e215a2662fc9ac0048c84530055452bed350aa2fc7c777c47b4cba08ca464c82d2b15a8ffff68d9
|
7
|
+
data.tar.gz: d1473cc7ad558e0b74a8fcad72f7abe661ded46dfc49de4cc8d29b7b3ec6ce0b9f321379115c0b71597014fcdf2e80663db16dc069acf74069865e726ae846da
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -12,8 +12,15 @@ MRI adapter for MySQL
|
|
12
12
|
|
13
13
|
## Requirements
|
14
14
|
|
15
|
-
* mysql client deveopment libraries
|
16
|
-
* uuid development libraries
|
15
|
+
* mysql client deveopment libraries (libmysqlclient-dev)
|
16
|
+
* uuid development libraries (uuid-dev)
|
17
|
+
|
18
|
+
## Building
|
19
|
+
|
20
|
+
```
|
21
|
+
git submodule update --init
|
22
|
+
rake
|
23
|
+
```
|
17
24
|
|
18
25
|
## API
|
19
26
|
|
@@ -49,6 +56,27 @@ MRI adapter for MySQL
|
|
49
56
|
#insert_id
|
50
57
|
```
|
51
58
|
|
59
|
+
## Connection options
|
60
|
+
|
61
|
+
```
|
62
|
+
╭────────────────────╥────────────┬─────────────╮
|
63
|
+
│ Name ║ Default │ Optional │
|
64
|
+
╞════════════════════╬════════════╪═════════════╡
|
65
|
+
│ db ║ - │ No │
|
66
|
+
│ host ║ 127.0.0.1 │ Yes │
|
67
|
+
│ port ║ 3306 │ Yes │
|
68
|
+
│ user ║ Etc.login │ Yes │
|
69
|
+
│ password ║ nil │ Yes │
|
70
|
+
│ encoding ║ utf8 │ Yes │
|
71
|
+
│ ssl ║ │ Yes │
|
72
|
+
│ ssl[:key] ║ - │ No │
|
73
|
+
│ ssl[:cert] ║ nil │ Yes │
|
74
|
+
│ ssl[:ca] ║ nil │ Yes │
|
75
|
+
│ ssl[:capath] ║ nil │ Yes │
|
76
|
+
│ ssl[:cipher] ║ nil │ Yes │
|
77
|
+
└────────────────────╨────────────┴─────────────┘
|
78
|
+
```
|
79
|
+
|
52
80
|
## Example
|
53
81
|
|
54
82
|
```ruby
|
data/ext/swift/db/mysql/common.c
CHANGED
@@ -4,7 +4,17 @@
|
|
4
4
|
|
5
5
|
#include "common.h"
|
6
6
|
#include "typecast.h"
|
7
|
-
|
7
|
+
|
8
|
+
#ifdef HAVE_CONST_UUID_VARIANT_NCS
|
9
|
+
#include <uuid/uuid.h>
|
10
|
+
#else
|
11
|
+
// TODO: no guarantee of being unique.
|
12
|
+
typedef unsigned char uuid_t[16];
|
13
|
+
void uuid_generate(uuid_t uuid) {
|
14
|
+
for (int i = 0; i < sizeof(uuid); i++)
|
15
|
+
uuid[i] = rand() % 256;
|
16
|
+
}
|
17
|
+
#endif
|
8
18
|
|
9
19
|
VALUE db_mysql_adapter_escape(VALUE, VALUE);
|
10
20
|
|
@@ -14,11 +24,12 @@ VALUE rb_uuid_string() {
|
|
14
24
|
char uuid_hex[sizeof(uuid_t) * 2 + 1];
|
15
25
|
|
16
26
|
uuid_generate(uuid);
|
27
|
+
|
28
|
+
memset(uuid_hex, 0, sizeof(uuid_hex));
|
17
29
|
for (n = 0; n < sizeof(uuid_t); n++)
|
18
|
-
sprintf(uuid_hex + n * 2
|
30
|
+
sprintf(uuid_hex + n * 2, "%02x", uuid[n]);
|
19
31
|
|
20
|
-
uuid_hex
|
21
|
-
return rb_str_new(uuid_hex, sizeof(uuid_t) * 2 + 1);
|
32
|
+
return rb_str_new(uuid_hex, sizeof(uuid_t) * 2);
|
22
33
|
}
|
23
34
|
|
24
35
|
size_t db_mysql_buffer_adjust(char **buffer, size_t size, size_t offset, size_t need) {
|
@@ -1,6 +1,11 @@
|
|
1
1
|
#include "datetime.h"
|
2
|
+
#include <time.h>
|
2
3
|
#include <ctype.h>
|
3
4
|
|
5
|
+
#define CONST_GET(scope, constant) rb_funcall(scope, rb_intern("const_get"), 1, rb_str_new2(constant))
|
6
|
+
#define TO_S(v) rb_funcall(v, rb_intern("to_s"), 0)
|
7
|
+
#define CSTRING(v) RSTRING_PTR(TO_S(v))
|
8
|
+
|
4
9
|
extern VALUE dtformat;
|
5
10
|
|
6
11
|
VALUE cSwiftDateTime, day_seconds;
|
@@ -1,8 +1,11 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include
|
4
|
-
#include <
|
3
|
+
#include <ruby.h>
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <stdint.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <stdbool.h>
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
extern VALUE cSwiftDateTime;
|
10
|
+
void init_swift_datetime();
|
11
|
+
VALUE datetime_parse(VALUE klass, const char *data, size_t size);
|
@@ -34,4 +34,5 @@ find_header 'mysql.h', *inc_paths.dup.unshift(mysql_inc).compact
|
|
34
34
|
find_library 'uuid', 'main', *lib_paths.dup.unshift(uuid_lib).compact
|
35
35
|
find_library 'mysqlclient', 'main', *lib_paths.dup.unshift(mysql_lib).compact
|
36
36
|
|
37
|
+
have_const(%w(UUID_VARIANT_NCS), 'uuid.h')
|
37
38
|
create_makefile('swift_db_mysql_ext')
|
data/test/test_async.rb
CHANGED
@@ -2,33 +2,35 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe 'async operations' do
|
4
4
|
it 'can query async and call block with result when ready' do
|
5
|
-
rows
|
6
|
-
|
5
|
+
rows = []
|
6
|
+
threads = []
|
7
|
+
pool = 3.times.map {Swift::DB::Mysql.new(db: 'swift_test')}
|
7
8
|
|
8
9
|
3.times do |n|
|
9
|
-
Thread.new do
|
10
|
+
threads << Thread.new do
|
10
11
|
pool[n].query("select sleep(#{(3 - n) / 10.0}), #{n + 1} as query_id") {|row| rows << row[:query_id]}
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
threads.each(&:join)
|
15
16
|
assert_equal [3, 2, 1], rows
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'returns and allows IO poll on connection file descriptor' do
|
19
20
|
|
20
|
-
rows
|
21
|
-
|
21
|
+
rows = []
|
22
|
+
threads = []
|
23
|
+
pool = 3.times.map {Swift::DB::Mysql.new(db: 'swift_test')}
|
22
24
|
|
23
25
|
3.times do |n|
|
24
|
-
Thread.new do
|
26
|
+
threads << Thread.new do
|
25
27
|
pool[n].query("select sleep(#{(3 - n) / 10.0}), #{n + 1} as query_id")
|
26
28
|
IO.select([IO.for_fd(pool[n].fileno)], [], [])
|
27
29
|
rows << pool[n].result.first[:query_id]
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
|
33
|
+
threads.each(&:join)
|
32
34
|
assert_equal [3, 2, 1], rows
|
33
35
|
end
|
34
36
|
end
|
data/test/test_ssl.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe 'adapter ssl' do
|
4
|
-
# TODO: this seems to rely on openssl versions used to build the mysql server.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
# TODO: this seems to rely on openssl versions used to build the mysql server.
|
5
|
+
it 'should connect to database with ssl options' do
|
6
|
+
skip
|
7
|
+
key = File.join(File.dirname(__FILE__), 'server.key')
|
8
|
+
cert = File.join(File.dirname(__FILE__), 'server.crt')
|
9
|
+
assert Swift::DB::Mysql.new(db: 'swift_test', ssl: {key: key, cert: cert})
|
10
|
+
end
|
10
11
|
end
|
metadata
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swift-db-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.3.0
|
4
|
+
version: 0.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bharanee Rathna
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
14
|
+
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
20
|
+
type: :development
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: '0'
|
29
|
-
name: rake
|
30
27
|
description: Swift adapter for MySQL database
|
31
28
|
email:
|
32
29
|
- deepfryed@gmail.com
|
@@ -35,53 +32,53 @@ extensions:
|
|
35
32
|
- ext/swift/db/mysql/extconf.rb
|
36
33
|
extra_rdoc_files: []
|
37
34
|
files:
|
38
|
-
-
|
39
|
-
-
|
40
|
-
- ext/swift/db/mysql/typecast.c
|
35
|
+
- CHANGELOG
|
36
|
+
- README.md
|
41
37
|
- ext/swift/db/mysql/adapter.c
|
42
|
-
- ext/swift/db/mysql/
|
43
|
-
- ext/swift/db/mysql/statement.c
|
38
|
+
- ext/swift/db/mysql/adapter.h
|
44
39
|
- ext/swift/db/mysql/common.c
|
45
|
-
- ext/swift/db/mysql/
|
40
|
+
- ext/swift/db/mysql/common.h
|
41
|
+
- ext/swift/db/mysql/datetime.c
|
46
42
|
- ext/swift/db/mysql/datetime.h
|
43
|
+
- ext/swift/db/mysql/extconf.rb
|
44
|
+
- ext/swift/db/mysql/gvl.h
|
45
|
+
- ext/swift/db/mysql/main.c
|
46
|
+
- ext/swift/db/mysql/result.c
|
47
47
|
- ext/swift/db/mysql/result.h
|
48
|
+
- ext/swift/db/mysql/statement.c
|
48
49
|
- ext/swift/db/mysql/statement.h
|
49
|
-
- ext/swift/db/mysql/
|
50
|
-
- ext/swift/db/mysql/
|
51
|
-
-
|
52
|
-
-
|
50
|
+
- ext/swift/db/mysql/typecast.c
|
51
|
+
- ext/swift/db/mysql/typecast.h
|
52
|
+
- lib/swift-db-mysql.rb
|
53
|
+
- lib/swift/db/mysql.rb
|
53
54
|
- test/helper.rb
|
54
|
-
- test/test_ssl.rb
|
55
|
-
- test/test_encoding.rb
|
56
55
|
- test/test_adapter.rb
|
57
56
|
- test/test_async.rb
|
58
|
-
-
|
59
|
-
-
|
60
|
-
- README.md
|
61
|
-
- CHANGELOG
|
57
|
+
- test/test_encoding.rb
|
58
|
+
- test/test_ssl.rb
|
62
59
|
homepage: http://github.com/deepfryed/swift-db-mysql
|
63
60
|
licenses: []
|
61
|
+
metadata: {}
|
64
62
|
post_install_message:
|
65
63
|
rdoc_options: []
|
66
64
|
require_paths:
|
67
65
|
- lib
|
68
66
|
- ext
|
69
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
68
|
requirements:
|
72
|
-
- -
|
69
|
+
- - ">="
|
73
70
|
- !ruby/object:Gem::Version
|
74
71
|
version: '0'
|
75
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
73
|
requirements:
|
78
|
-
- -
|
74
|
+
- - ">="
|
79
75
|
- !ruby/object:Gem::Version
|
80
76
|
version: '0'
|
81
77
|
requirements: []
|
82
78
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
79
|
+
rubygems_version: 2.2.0
|
84
80
|
signing_key:
|
85
|
-
specification_version:
|
81
|
+
specification_version: 4
|
86
82
|
summary: Swift mysql adapter
|
87
83
|
test_files: []
|
84
|
+
has_rdoc:
|