pgtk 0.7.3 → 0.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c04374b388a6c39cd472eaeb7f6d6b6c9f7792db1137c63b42bc2c90b42e294
4
- data.tar.gz: 15f7583738ef3edbefb70daf873bbbca0153100fe9e71ecf4748e9d0b778be34
3
+ metadata.gz: baa19244cc0bb678a2a694232365acc92b72102ec96c2fe41f9a47d36487a0d3
4
+ data.tar.gz: ea5749be062492fceb1fbac012f1b55c9b6a43991f3718e4d8b65e05bf67a0e4
5
5
  SHA512:
6
- metadata.gz: 27dd1a20cf6b6c57751ccc64f663c24fccd8a018706c0d61eb4f607f6461237aeee75ae5992b140b67fa0dbf6c4ec5d1ef29a7c498ea17b79f2f22007e0a5c6d
7
- data.tar.gz: 532936b37210fd0559d85d01014ece69e7a72fe8e7d47224fd1558414d0c9907d463e4b381a374eb6063e08ea2a5848af5e8a47e50f6074e69fccef0874ec8cf
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
@@ -28,5 +28,5 @@ require_relative '../pgtk'
28
28
  # License:: MIT
29
29
  module Pgtk
30
30
  # Current version of the library.
31
- VERSION = '0.7.3'
31
+ VERSION = '0.7.4'
32
32
  end
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
- uri = URI(ENV[@var])
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.3
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-07-18 00:00:00.000000000 Z
11
+ date: 2019-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace