pgtk 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/pgtk/version.rb +1 -1
- data/lib/pgtk/wire.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baa19244cc0bb678a2a694232365acc92b72102ec96c2fe41f9a47d36487a0d3
|
4
|
+
data.tar.gz: ea5749be062492fceb1fbac012f1b55c9b6a43991f3718e4d8b65e05bf67a0e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 706e072b93b40d26ae5efda68870cb6f9c59eaa0e0d13205a2be858871c4c1e1a487a4ff07384d68a80bd0ece19cee214d58631ddab51cd5c66c807907cd5512
|
7
|
+
data.tar.gz: a92669230a4f7c92a0ededd321e795648a712f0f9951bc0e410ea89b782c1479156c1b4b8105b943e6eee5505121fd23f7e23d01a322053d7dc28214bd5c72d4
|
data/README.md
CHANGED
@@ -84,6 +84,20 @@ From inside your app you may find this class useful:
|
|
84
84
|
require 'pgtk/pool'
|
85
85
|
pgsql = Pgtk::Pool.new(Pgtk::Wire::Yaml.new('config.yml'))
|
86
86
|
pgsql.start(5) # Start it with five simultaneous connections
|
87
|
+
```
|
88
|
+
|
89
|
+
You can also let it pick the connection parameters from the environment
|
90
|
+
variable `DATABASE_URL`, formatted like
|
91
|
+
`postgres://user:password@host:5432/dbname`:
|
92
|
+
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
pgsql = Pgtk::Pool.new(Pgtk::Wire::Env.new)
|
96
|
+
```
|
97
|
+
|
98
|
+
Now you can fetch some data from the DB:
|
99
|
+
|
100
|
+
```ruby
|
87
101
|
name = pgsql.exec('SELECT name FROM user WHERE id = $1', [id])[0]['name']
|
88
102
|
```
|
89
103
|
|
data/lib/pgtk/version.rb
CHANGED
data/lib/pgtk/wire.rb
CHANGED
@@ -39,7 +39,9 @@ end
|
|
39
39
|
class Pgtk::Wire::Direct
|
40
40
|
# Constructor.
|
41
41
|
def initialize(host:, port:, dbname:, user:, password:)
|
42
|
+
raise "The host can't be nil" if host.nil?
|
42
43
|
@host = host
|
44
|
+
raise "The host can't be nil" if host.nil?
|
43
45
|
@port = port
|
44
46
|
@dbname = dbname
|
45
47
|
@user = user
|
@@ -62,12 +64,15 @@ end
|
|
62
64
|
class Pgtk::Wire::Env
|
63
65
|
# Constructor.
|
64
66
|
def initialize(var = 'DATABASE_URL')
|
67
|
+
raise "The name of the environmant variable can't be nil" if var.nil?
|
65
68
|
@var = var
|
66
69
|
end
|
67
70
|
|
68
71
|
# Create a new connection to PostgreSQL server.
|
69
72
|
def connection
|
70
|
-
|
73
|
+
v = ENV[@var]
|
74
|
+
raise "The environment variable #{@var.inspect} is not set" if v.nil?
|
75
|
+
uri = URI(v)
|
71
76
|
Pgtk::Wire::Direct.new(
|
72
77
|
host: uri.host,
|
73
78
|
port: uri.port,
|
@@ -85,12 +90,15 @@ end
|
|
85
90
|
class Pgtk::Wire::Yaml
|
86
91
|
# Constructor.
|
87
92
|
def initialize(file, node = 'pgsql')
|
93
|
+
raise "The name of the file can't be nil" if file.nil?
|
88
94
|
@file = file
|
95
|
+
raise "The name of the node in the YAML file can't be nil" if node.nil?
|
89
96
|
@node = node
|
90
97
|
end
|
91
98
|
|
92
99
|
# Create a new connection to PostgreSQL server.
|
93
100
|
def connection
|
101
|
+
raise "The file #{@file.inspect} not found" unless File.exist?(@file)
|
94
102
|
cfg = YAML.load_file(@file)
|
95
103
|
Pgtk::Wire::Direct.new(
|
96
104
|
host: cfg['pgsql']['host'],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgtk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|