swift-db-postgres 0.1.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.
- data/CHANGELOG +3 -0
- data/README.md +131 -0
- data/ext/swift/db/postgres/adapter.c +580 -0
- data/ext/swift/db/postgres/adapter.h +14 -0
- data/ext/swift/db/postgres/common.c +59 -0
- data/ext/swift/db/postgres/common.h +35 -0
- data/ext/swift/db/postgres/datetime.c +99 -0
- data/ext/swift/db/postgres/datetime.h +8 -0
- data/ext/swift/db/postgres/extconf.rb +33 -0
- data/ext/swift/db/postgres/main.c +28 -0
- data/ext/swift/db/postgres/result.c +172 -0
- data/ext/swift/db/postgres/result.h +10 -0
- data/ext/swift/db/postgres/statement.c +169 -0
- data/ext/swift/db/postgres/statement.h +9 -0
- data/ext/swift/db/postgres/typecast.c +112 -0
- data/ext/swift/db/postgres/typecast.h +24 -0
- data/lib/swift-db-postgres.rb +1 -0
- data/lib/swift/db/postgres.rb +1 -0
- data/test/helper.rb +8 -0
- data/test/test_adapter.rb +106 -0
- data/test/test_async.rb +34 -0
- data/test/test_encoding.rb +30 -0
- data/test/test_ssl.rb +15 -0
- metadata +87 -0
data/test/test_async.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'async operations' do
|
4
|
+
it 'can query async and call block with result when ready' do
|
5
|
+
rows = []
|
6
|
+
pool = 3.times.map {Swift::DB::Postgres.new(db: 'swift_test')}
|
7
|
+
|
8
|
+
3.times do |n|
|
9
|
+
Thread.new do
|
10
|
+
pool[n].query("select pg_sleep(#{(3 - n) / 10.0}), #{n + 1} as query_id") {|row| rows << row[:query_id]}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Thread.list.reject {|thread| Thread.current == thread}.each(&:join)
|
15
|
+
assert_equal [3, 2, 1], rows
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns and allows IO poll on connection file descriptor' do
|
19
|
+
|
20
|
+
rows = []
|
21
|
+
pool = 3.times.map {Swift::DB::Postgres.new(db: 'swift_test')}
|
22
|
+
|
23
|
+
3.times do |n|
|
24
|
+
Thread.new do
|
25
|
+
pool[n].query("select pg_sleep(#{(3 - n) / 10.0}), #{n + 1} as query_id")
|
26
|
+
IO.select([IO.for_fd(pool[n].fileno)], [], [])
|
27
|
+
rows << pool[n].result.first[:query_id]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Thread.list.reject {|thread| Thread.current == thread}.each(&:join)
|
32
|
+
assert_equal [3, 2, 1], rows
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'utf-8 encoding' do
|
4
|
+
before do
|
5
|
+
assert db.execute('drop table if exists users')
|
6
|
+
assert db.execute('create table users (name text)')
|
7
|
+
|
8
|
+
@text = ["King of \u2665s", "\xA1\xB8".force_encoding('euc-jp')]
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should store and retrieve utf8 characters with Statement#execute' do
|
12
|
+
@text.each do |name|
|
13
|
+
db.prepare('insert into users (name) values(?)').execute(name)
|
14
|
+
value = db.prepare('select * from users limit 1').execute.first[:name]
|
15
|
+
assert_equal Encoding::UTF_8, value.encoding
|
16
|
+
assert_equal name.encode('utf-8'), value
|
17
|
+
db.execute('delete from users')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should store and retrieve utf8 characters Adapter#execute' do
|
22
|
+
@text.each do |name|
|
23
|
+
db.execute('insert into users (name) values(?)', name)
|
24
|
+
value = db.execute('select * from users limit 1').first[:name]
|
25
|
+
assert_equal Encoding::UTF_8, value.encoding
|
26
|
+
assert_equal name.encode('utf-8'), value
|
27
|
+
db.execute('delete from users')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/test/test_ssl.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'adapter ssl' do
|
4
|
+
it 'should connect to database with ssl options' do
|
5
|
+
db.execute('create extension if not exists sslinfo')
|
6
|
+
key = File.join(File.dirname(__FILE__), 'server.key')
|
7
|
+
cert = File.join(File.dirname(__FILE__), 'server.crt')
|
8
|
+
|
9
|
+
assert db = Swift::DB::Postgres.new(db: 'swift_test', ssl: {sslmode: 'require', sslcert: cert, sslkey: key})
|
10
|
+
assert db.execute('select ssl_is_used()').first[:ssl_is_used]
|
11
|
+
|
12
|
+
assert db = Swift::DB::Postgres.new(db: 'swift_test', ssl: {sslmode: 'disable'})
|
13
|
+
assert !db.execute('select ssl_is_used()').first[:ssl_is_used]
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swift-db-postgres
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bharanee Rathna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Swift adapter for PostgreSQL database
|
31
|
+
email:
|
32
|
+
- deepfryed@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions:
|
35
|
+
- ext/swift/db/postgres/extconf.rb
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- ext/swift/db/postgres/datetime.c
|
39
|
+
- ext/swift/db/postgres/common.c
|
40
|
+
- ext/swift/db/postgres/typecast.c
|
41
|
+
- ext/swift/db/postgres/statement.c
|
42
|
+
- ext/swift/db/postgres/adapter.c
|
43
|
+
- ext/swift/db/postgres/main.c
|
44
|
+
- ext/swift/db/postgres/result.c
|
45
|
+
- ext/swift/db/postgres/typecast.h
|
46
|
+
- ext/swift/db/postgres/common.h
|
47
|
+
- ext/swift/db/postgres/datetime.h
|
48
|
+
- ext/swift/db/postgres/result.h
|
49
|
+
- ext/swift/db/postgres/adapter.h
|
50
|
+
- ext/swift/db/postgres/statement.h
|
51
|
+
- ext/swift/db/postgres/extconf.rb
|
52
|
+
- test/test_ssl.rb
|
53
|
+
- test/test_encoding.rb
|
54
|
+
- test/helper.rb
|
55
|
+
- test/test_async.rb
|
56
|
+
- test/test_adapter.rb
|
57
|
+
- lib/swift/db/postgres.rb
|
58
|
+
- lib/swift-db-postgres.rb
|
59
|
+
- README.md
|
60
|
+
- CHANGELOG
|
61
|
+
homepage: http://github.com/deepfryed/swift-db-postgres
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
- ext
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.24
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Swift postgres adapter
|
86
|
+
test_files: []
|
87
|
+
has_rdoc:
|