rsconn 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +31 -2
- data/lib/rsconn.rb +1 -1
- data/lib/rsconn/jdbc_url.rb +1 -1
- data/lib/rsconn/postgres.rb +14 -10
- data/lib/rsconn/version.rb +1 -1
- data/spec/dev_redshift.rb +10 -1
- data/spec/jdbc_url_spec.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c73efb8028b4d0dff9f7eb0a69c9ebded1bf2da
|
4
|
+
data.tar.gz: c81d08bff44458589a05d2969b7125b4c3f3043a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e6875b2bb4e679d072ea8c50daa57153468748b0c2399f80772146b4280e5d74c777c8ac46fdadeb579e2090659cdd14a130fd3e651338616c5e0b9b7ee9613
|
7
|
+
data.tar.gz: f243366883222b1b1afac47dbee1742e407ecc3964566b324d39f5040697f38a06b84e4877400e3f2a91bac92c71cd3049e1dd4efaa88f9094ed4be17b298df4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# rsconn
|
2
2
|
|
3
|
-
|
3
|
+
A convenience wrapper to make interaction with a Redshift cluster easier.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,32 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
This is an example of connecting to and using a Redshift database using a JDBC URL.
|
22
|
+
|
23
|
+
require 'rsconn'
|
24
|
+
|
25
|
+
url = Rsconn::JdbcUrl.new(ENV['RSCONN_JDBC_URL'])
|
26
|
+
|
27
|
+
db_conn = Rsconn::Redshift.new(
|
28
|
+
url.host,
|
29
|
+
url.port,
|
30
|
+
url.database,
|
31
|
+
ENV['RSCONN_USER'],
|
32
|
+
ENV['RSCONN_PASSWORD'],
|
33
|
+
)
|
34
|
+
|
35
|
+
# For updates, inserts, deletes, etc., use #execute.
|
36
|
+
db_conn.execute('CREATE TABLE reg.students (id integer, name varchar(100))')
|
37
|
+
db_conn.execute("INSERT INTO reg.students VALUES (1, 'Dean')")
|
38
|
+
|
39
|
+
# Queries return an easy to use data structure - there's no need to manually
|
40
|
+
# create and iterate through cursors
|
41
|
+
rows = db_conn.query('SELECT * FROM reg.students WHERE id = 1')
|
42
|
+
|
43
|
+
puts "Use the column name: #{rows.first['name']}"
|
44
|
+
puts "Or use the column index: {rows.first[1]}"
|
45
|
+
|
46
|
+
# To run non-query SQL statements from a script, use #execute_script
|
22
47
|
|
23
48
|
## Contributing
|
24
49
|
|
@@ -27,3 +52,7 @@ TODO: Write usage instructions here
|
|
27
52
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
53
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
54
|
5. Create a new Pull Request
|
55
|
+
|
56
|
+
### Running tests
|
57
|
+
|
58
|
+
The tests need to connect to a Redshift cluster. Set the environment variables `RSCONN_JDBC_URL`, `RSCONN_USER`, `RSCONN_PASSWORD` and make sure the cluster has a `test` schema.
|
data/lib/rsconn.rb
CHANGED
@@ -5,7 +5,7 @@ module Rsconn
|
|
5
5
|
class Redshift < Postgres
|
6
6
|
attr_reader :query_group, :query_slot_count
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(host, port, database, user, password, options={})
|
9
9
|
super
|
10
10
|
@query_group = options.fetch(:query_group, nil)
|
11
11
|
@query_slot_count = options.fetch(:query_slot_count, nil)
|
data/lib/rsconn/jdbc_url.rb
CHANGED
data/lib/rsconn/postgres.rb
CHANGED
@@ -14,15 +14,17 @@ module Rsconn
|
|
14
14
|
class Postgres
|
15
15
|
attr_reader :conn
|
16
16
|
|
17
|
-
def initialize(
|
18
|
-
fail_if_invalid_connection_credentials(
|
17
|
+
def initialize(host, port, database, user, password, options={})
|
18
|
+
fail_if_invalid_connection_credentials(host, port, database, user, password)
|
19
19
|
|
20
|
+
@host = host
|
21
|
+
@port = port
|
22
|
+
@database = database
|
23
|
+
@user = user
|
24
|
+
@password = password
|
20
25
|
@abort_on_error = options.fetch(:abort_on_error, true)
|
21
26
|
@max_retries = options.fetch(:max_retries, 3)
|
22
27
|
@quiet = options.fetch(:quiet, false)
|
23
|
-
@jdbc_url = JdbcUrl.new(jdbc_url)
|
24
|
-
@user = user
|
25
|
-
@password = password
|
26
28
|
@error_occurred = false
|
27
29
|
@retry_count = 0
|
28
30
|
|
@@ -94,18 +96,20 @@ module Rsconn
|
|
94
96
|
|
95
97
|
private
|
96
98
|
|
97
|
-
def fail_if_invalid_connection_credentials(
|
98
|
-
fail ArgumentError, '
|
99
|
+
def fail_if_invalid_connection_credentials(host, port, database, user, password)
|
100
|
+
fail ArgumentError, 'host needs to be a string' unless host.is_a?(String)
|
101
|
+
fail ArgumentError, 'database needs to be a string' unless database.is_a?(String)
|
99
102
|
fail ArgumentError, 'user needs to be a string' unless user.is_a?(String)
|
100
103
|
fail ArgumentError, 'password needs to be a string' unless password.is_a?(String)
|
104
|
+
fail ArgumentError, 'port needs to be a integer' unless port.to_s =~ /\A\d+\z/
|
101
105
|
end
|
102
106
|
|
103
107
|
def init_connection
|
104
108
|
with_error_handling do
|
105
109
|
@conn = PGconn.open(
|
106
|
-
:host => @
|
107
|
-
:port => @
|
108
|
-
:dbname => @
|
110
|
+
:host => @host,
|
111
|
+
:port => @port,
|
112
|
+
:dbname => @database,
|
109
113
|
:user => @user,
|
110
114
|
:password => @password,
|
111
115
|
)
|
data/lib/rsconn/version.rb
CHANGED
data/spec/dev_redshift.rb
CHANGED
@@ -5,8 +5,17 @@ module Rsconn
|
|
5
5
|
class DevRedshift < Redshift
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
+
unless ENV['RSCONN_JDBC_URL'] && ENV['RSCONN_USER'] && ENV['RSCONN_PASSWORD']
|
9
|
+
fail 'The environment variables RSCONN_JDBC_URL, RSCONN_USER, and ' +
|
10
|
+
'RSCONN_PASSWORD must be set to run the tests'
|
11
|
+
end
|
12
|
+
|
13
|
+
url = JdbcUrl.new(ENV['RSCONN_JDBC_URL'])
|
14
|
+
|
8
15
|
super(
|
9
|
-
|
16
|
+
url.host,
|
17
|
+
url.port,
|
18
|
+
url.database,
|
10
19
|
ENV['RSCONN_USER'],
|
11
20
|
ENV['RSCONN_PASSWORD'],
|
12
21
|
options
|
data/spec/jdbc_url_spec.rb
CHANGED
@@ -7,7 +7,8 @@ module Rsconn
|
|
7
7
|
HOST = 'host.redshift.amazonaws.com'
|
8
8
|
PORT = 5439
|
9
9
|
DATABASE = 'dbname'
|
10
|
-
|
10
|
+
OPTIONS = 'tcpKeepAlive=true'
|
11
|
+
JDBC_URL = "jdbc:postgresql://#{HOST}:#{PORT}/#{DATABASE}?#{OPTIONS}"
|
11
12
|
MYSQL_URL = "jdbc:mysql://#{HOST}:#{PORT}/#{DATABASE}"
|
12
13
|
|
13
14
|
describe '#new' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsconn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Morin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|