connectator 0.0.6 → 0.0.7
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/lib/connectator.rb +6 -3
- data/lib/connectator/base/connection.rb +2 -2
- data/lib/connectator/db2/connection.rb +3 -2
- data/lib/connectator/dbi_proxy.rb +31 -0
- data/lib/connectator/mysql/connection.rb +1 -0
- data/lib/connectator/oracle/connection.rb +1 -0
- data/lib/connectator/sql/connection.rb +2 -1
- data/lib/connectator/sybase/connection.rb +2 -1
- data/lib/connectator/using_dbi_proxy.rb +18 -0
- data/spec/connectator/db2/connection_spec.rb +13 -1
- data/spec/connectator/sql/connection_spec.rb +3 -2
- data/spec/connectator/sybase/connection_spec.rb +2 -2
- metadata +4 -19
- data/lib/connectator/base/dbi_proxy.rb +0 -33
data/lib/connectator.rb
CHANGED
@@ -2,13 +2,16 @@ require 'dbi'
|
|
2
2
|
require 'timeout'
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
|
+
require_relative 'connectator/factory'
|
6
|
+
require_relative 'connectator/pinger'
|
7
|
+
require_relative 'connectator/dbi_proxy'
|
8
|
+
require_relative 'connectator/using_dbi_proxy'
|
9
|
+
|
5
10
|
require_relative 'connectator/base/connection'
|
6
|
-
require_relative 'connectator/base/dbi_proxy'
|
7
11
|
require_relative 'connectator/db2/connection'
|
8
12
|
require_relative 'connectator/mysql/connection'
|
9
13
|
require_relative 'connectator/oracle/connection'
|
10
14
|
require_relative 'connectator/sql/connection'
|
11
15
|
require_relative 'connectator/sql/connection/server_instance_string'
|
12
16
|
require_relative 'connectator/sybase/connection'
|
13
|
-
|
14
|
-
require_relative 'connectator/pinger'
|
17
|
+
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Connectator
|
2
2
|
module DB2
|
3
3
|
class Connection < Base::Connection
|
4
|
+
include UsingDBIProxy
|
4
5
|
|
5
6
|
def initialize(opts = {})
|
6
|
-
connection_params.database = opts[:database]
|
7
7
|
connection_params.driver = 'DB2'
|
8
8
|
connection_params.protocol = 'TCPIP'
|
9
|
+
connection_params.database = opts[:database]
|
9
10
|
super(opts)
|
10
11
|
end
|
11
12
|
|
@@ -20,7 +21,7 @@ module Connectator
|
|
20
21
|
"DRIVER" => connection_params.driver,
|
21
22
|
"PROTOCOL" => connection_params.protocol,
|
22
23
|
"HOSTNAME" => connection_params.server,
|
23
|
-
"
|
24
|
+
"PORT" => connection_params.port,
|
24
25
|
"DATABASE" => connection_params.database,
|
25
26
|
"UID" => connection_params.username,
|
26
27
|
"PWD" => connection_params.password
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Connectator
|
2
|
+
class DBIProxy
|
3
|
+
|
4
|
+
def initialize(connection)
|
5
|
+
@connection = connection
|
6
|
+
end
|
7
|
+
|
8
|
+
def connection
|
9
|
+
@connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def close
|
13
|
+
connection.disconnect
|
14
|
+
end
|
15
|
+
|
16
|
+
# Do not use this method on queries that return lots of data
|
17
|
+
# because it would use a lot of memory.
|
18
|
+
def select_all_to_hash(query)
|
19
|
+
result = []
|
20
|
+
sth = connection.execute(query)
|
21
|
+
sth.fetch_hash do |row|
|
22
|
+
result << row
|
23
|
+
end
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(method, *args, &blk)
|
28
|
+
connection.send(method, *args, &blk)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Connectator
|
2
2
|
module Sql
|
3
3
|
class Connection < Base::Connection
|
4
|
+
include UsingDBIProxy
|
4
5
|
|
5
6
|
def initialize(opts = {})
|
6
7
|
connection_params.driver = 'FreeTDS'
|
@@ -24,7 +25,7 @@ module Connectator
|
|
24
25
|
"DRIVER" => connection_params.driver,
|
25
26
|
"TDS_Version" => connection_params.tds_version,
|
26
27
|
"SERVER" => server_instance_string,
|
27
|
-
"
|
28
|
+
"PORT" => connection_params.port,
|
28
29
|
"DATABASE" => connection_params.database,
|
29
30
|
"UID" => connection_params.username,
|
30
31
|
"PWD" => connection_params.password
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Connectator
|
2
2
|
module Sybase
|
3
3
|
class Connection < Base::Connection
|
4
|
+
include UsingDBIProxy
|
4
5
|
|
5
6
|
def initialize(opts = {})
|
6
7
|
connection_params.driver = 'FreeTDS'
|
@@ -20,7 +21,7 @@ module Connectator
|
|
20
21
|
"DRIVER" => connection_params.driver,
|
21
22
|
"TDS_Version" => connection_params.tds_version,
|
22
23
|
"SERVER" => connection_params.server,
|
23
|
-
"
|
24
|
+
"PORT" => connection_params.port,
|
24
25
|
"DATABASE" => connection_params.database,
|
25
26
|
"UID" => connection_params.username,
|
26
27
|
"PWD" => connection_params.password
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Include this module in any connection that you want to use
|
2
|
+
# DBI and the DBIProxy
|
3
|
+
|
4
|
+
module Connectator
|
5
|
+
module UsingDBIProxy
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def new_system_connection_proxy
|
10
|
+
DBIProxy.new(open)
|
11
|
+
end
|
12
|
+
|
13
|
+
def open
|
14
|
+
DBI.connect(connection_string)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -26,6 +26,18 @@ describe Connectator::DB2::Connection do
|
|
26
26
|
Then { connection.connection_params.database.should == 'ABCDEFG' }
|
27
27
|
|
28
28
|
Then { connection.connection_string.should ==
|
29
|
-
'DBI:ODBC:DRIVER=DB2;PROTOCOL=TCPIP;HOSTNAME=Server;
|
29
|
+
'DBI:ODBC:DRIVER=DB2;PROTOCOL=TCPIP;HOSTNAME=Server;PORT=Port;DATABASE=ABCDEFG;UID=User;PWD=Pass' }
|
30
|
+
|
31
|
+
Then { connection.send(:connection_params_hash).should ==
|
32
|
+
{
|
33
|
+
"DRIVER" => 'DB2',
|
34
|
+
"PROTOCOL" => 'TCPIP',
|
35
|
+
"HOSTNAME" => 'Server',
|
36
|
+
"PORT" => 'Port',
|
37
|
+
"DATABASE" => 'ABCDEFG',
|
38
|
+
"UID" => 'User',
|
39
|
+
"PWD" => 'Pass'
|
40
|
+
}
|
41
|
+
}
|
30
42
|
end
|
31
43
|
end
|
@@ -24,13 +24,14 @@ describe Connectator::Sql::Connection do
|
|
24
24
|
Then { connection.connection_params.database.should == 'master' }
|
25
25
|
|
26
26
|
Then { connection.connection_string.should ==
|
27
|
-
"DBI:ODBC:DRIVER=FreeTDS;TDS_Version=8.0;SERVER=Server;
|
27
|
+
"DBI:ODBC:DRIVER=FreeTDS;TDS_Version=8.0;SERVER=Server;PORT=Port;DATABASE=master;UID=User;PWD=Pass" }
|
28
|
+
|
28
29
|
Then { connection.send(:connection_params_hash).should ==
|
29
30
|
{
|
30
31
|
"DRIVER" => 'FreeTDS',
|
31
32
|
"TDS_Version" => '8.0',
|
32
33
|
"SERVER" => 'Server',
|
33
|
-
"
|
34
|
+
"PORT" => 'Port',
|
34
35
|
"DATABASE" => 'master',
|
35
36
|
"UID" => 'User',
|
36
37
|
"PWD" => 'Pass'
|
@@ -24,14 +24,14 @@ describe Connectator::Sybase::Connection do
|
|
24
24
|
Then { connection.connection_params.database.should == 'master' }
|
25
25
|
|
26
26
|
Then { connection.connection_string.should ==
|
27
|
-
"DBI:ODBC:DRIVER=FreeTDS;TDS_Version=5.0;SERVER=Server;
|
27
|
+
"DBI:ODBC:DRIVER=FreeTDS;TDS_Version=5.0;SERVER=Server;PORT=Port;DATABASE=master;UID=User;PWD=Pass" }
|
28
28
|
|
29
29
|
Then { connection.send(:connection_params_hash).should ==
|
30
30
|
{
|
31
31
|
"DRIVER" => 'FreeTDS',
|
32
32
|
"TDS_Version" => '5.0',
|
33
33
|
"SERVER" => 'Server',
|
34
|
-
"
|
34
|
+
"PORT" => 'Port',
|
35
35
|
"DATABASE" => 'master',
|
36
36
|
"UID" => 'User',
|
37
37
|
"PWD" => 'Pass'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connectator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.2.5
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: ruby-oci8
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: bundler
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,9 +116,10 @@ extra_rdoc_files: []
|
|
132
116
|
files:
|
133
117
|
- lib/connectator.rb
|
134
118
|
- lib/connectator/factory.rb
|
119
|
+
- lib/connectator/dbi_proxy.rb
|
120
|
+
- lib/connectator/using_dbi_proxy.rb
|
135
121
|
- lib/connectator/oracle/connection.rb
|
136
122
|
- lib/connectator/base/connection.rb
|
137
|
-
- lib/connectator/base/dbi_proxy.rb
|
138
123
|
- lib/connectator/pinger.rb
|
139
124
|
- lib/connectator/db2/connection.rb
|
140
125
|
- lib/connectator/sybase/connection.rb
|
@@ -165,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
150
|
version: '0'
|
166
151
|
segments:
|
167
152
|
- 0
|
168
|
-
hash:
|
153
|
+
hash: 3410537790936780615
|
169
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
155
|
none: false
|
171
156
|
requirements:
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Connectator
|
2
|
-
module Base
|
3
|
-
class DBIProxy
|
4
|
-
|
5
|
-
def initialize(connection)
|
6
|
-
@connection = connection
|
7
|
-
end
|
8
|
-
|
9
|
-
def connection
|
10
|
-
@connection
|
11
|
-
end
|
12
|
-
|
13
|
-
def close
|
14
|
-
connection.disconnect
|
15
|
-
end
|
16
|
-
|
17
|
-
# Do not use this method on queries that return lots of data
|
18
|
-
# because it would use a lot of memory.
|
19
|
-
def select_all_to_hash(query)
|
20
|
-
result = []
|
21
|
-
sth = connection.execute(query)
|
22
|
-
sth.fetch_hash do |row|
|
23
|
-
result << row
|
24
|
-
end
|
25
|
-
result
|
26
|
-
end
|
27
|
-
|
28
|
-
def method_missing(method, *args, &blk)
|
29
|
-
connection.send(method, *args, &blk)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|