pgtk 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '086e1f1a4816734b011bc9098f6f893f316e3c9390b07d3d1276bb9f6ecb8ddd'
4
- data.tar.gz: 5368c2f9d9340123d49d564cc73c3843a3113329d1aabc52471e023db9cfed4b
3
+ metadata.gz: 43d3924569fc077b07d4db33232357d4d761af2cb81ccdad35d80ef7aae042b7
4
+ data.tar.gz: 02473caa0bc03c9138afda1213cc128819d72f4e464f9589a17e0f1a940f4dd2
5
5
  SHA512:
6
- metadata.gz: a1e4bb81b2048ef7e91add95a53a3a0d3901905fc9da7e817ec9284bf9857f0af313f9fdeff09b27936edab995c75a218381b81307ce422ef0ee96c457491d15
7
- data.tar.gz: c30da95c961a30e558f48500a3dafd7434c462b9288b09ffa006713ccbb340bdc118a64996381d07f30f741b89280396043e763ec8d6fba3a4f9eacfc39550df
6
+ metadata.gz: 1a1796c83e25523b9113591ce9edfc4bd2078c23b3338a417cb2519be34a420545dd8b5fffb3d6fc2f6a351b89d3ca566b758efecb3d51513a3a25836ccbb287
7
+ data.tar.gz: 13f8ef96a5e44c8230fc7cffc7c3e785a8fdc028d7e897c31e0834217ae3f2b037a9feae704ab466f585f83dd8acb28233c5cd44a72dcce10925a2370d804a3e
data/README.md CHANGED
@@ -46,7 +46,7 @@ Pgtk::PgsqlTask.new :pgsql do |t|
46
46
  t.user = 'test'
47
47
  t.password = 'test'
48
48
  t.dbname = 'test'
49
- t.yaml = 'target/config.yml' # YAML file to be created with connection details
49
+ t.yaml = 'target/pgsql-config.yml' # YAML file to be created with connection details
50
50
  end
51
51
  ```
52
52
 
@@ -56,7 +56,7 @@ And this too:
56
56
  require 'pgtk/liquibase_task'
57
57
  Pgtk::LiquibaseTask.new liquibase: :pgsql do |t|
58
58
  t.master = 'liquibase/master.xml' # Master XML file path
59
- t.yaml = 'target/config.yml' # YAML file with connection details
59
+ t.yaml = ['target/pgsql-config.yml', 'config.yml'] # YAML files with connection details
60
60
  end
61
61
  ```
62
62
 
@@ -79,7 +79,7 @@ From inside your app you may find this class useful:
79
79
 
80
80
  ```ruby
81
81
  require 'pgtk/pool'
82
- yaml = YAML.load_file('target/config.yml')
82
+ yaml = YAML.load_file('config.yml')
83
83
  pgsql = Pgtk::Pool.new(
84
84
  port: yaml['pgsql']['port'],
85
85
  dbname: yaml['pgsql']['dbname'],
@@ -102,6 +102,30 @@ pgsql.connect do |c|
102
102
  end
103
103
  ```
104
104
 
105
+ To make your PostgreSQL database visible in your unit test, I would
106
+ recommend you create a method `test_pgsql` in your `test__helper.rb` file
107
+ (which is `required` in all unit tests) and implement it like this:
108
+
109
+ ```ruby
110
+ require 'yaml'
111
+ require 'minitest/autorun'
112
+ require 'pgtk/pool'
113
+ module Minitest
114
+ class Test
115
+ def test_pgsql
116
+ config = YAML.load_file('target/pgsql-config.yml')
117
+ @test_pgsql ||= Pgtk::Pool.new(
118
+ host: config['pgsql']['host'],
119
+ port: config['pgsql']['port'],
120
+ dbname: config['pgsql']['dbname'],
121
+ user: config['pgsql']['user'],
122
+ password: config['pgsql']['password']
123
+ ).start
124
+ end
125
+ end
126
+ end
127
+ ```
128
+
105
129
  Should work. Well, it works in [zold-io/wts.zold.io](https://github.com/zold-io/wts.zold.io)
106
130
  and [yegor256/mailanes](https://github.com/yegor256/mailanes). They both are
107
131
  open source, you can see how they use `pgtk`.
data/appveyor.yml CHANGED
@@ -2,7 +2,7 @@ version: '{build}'
2
2
  skip_tags: true
3
3
  clone_depth: 10
4
4
  services:
5
- - postgresql101
5
+ - postgresql
6
6
  branches:
7
7
  only:
8
8
  - master
@@ -15,13 +15,13 @@ install:
15
15
  - cmd: git --version
16
16
  - cmd: java -version
17
17
  - cmd: mvn --version
18
- - cmd: PATH=C:\Program Files\PostgreSQL\10\bin\;%PATH%
18
+ - cmd: PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%
19
19
  - cmd: psql --version
20
20
  build_script:
21
21
  - bundle update
22
22
  - bundle install
23
23
  test_script:
24
- - rake
24
+ - bundle exec rake
25
25
  cache:
26
26
  - C:\Ruby200\bin -> pgtk.gemspec
27
27
  - C:\Ruby200\lib\ruby\gems\2.0.0 -> pgtk.gemspec
@@ -56,7 +56,13 @@ class Pgtk::LiquibaseTask < Rake::TaskLib
56
56
  def run
57
57
  raise "Option 'master' is mandatory" unless @master
58
58
  raise "Option 'yaml' is mandatory" unless @yaml
59
- yml = YAML.load_file(@yaml)
59
+ yml = YAML.load_file(
60
+ if @yaml.is_a?(Array)
61
+ @yaml.drop_while { |f| !File.exist?(f) }.first
62
+ else
63
+ @yaml
64
+ end
65
+ )
60
66
  raise "YAML at #{yaml} is missing 'pgsql' section" unless yml['pgsql']
61
67
  pom = File.expand_path(File.join(__dir__, '../../resources/pom.xml'))
62
68
  raise "Liquibase master is absent at #{@master}" unless File.exist?(@master)
data/lib/pgtk/pool.rb CHANGED
@@ -39,8 +39,13 @@ class Pgtk::Pool
39
39
  @pool = Queue.new
40
40
  end
41
41
 
42
- # Start it with a fixed number of connections.
43
- def start(max = 1)
42
+ # Start it with a fixed number of connections. The amount of connections
43
+ # is specified in +max+ argument and should be big enough to handle
44
+ # the amount of parallel connections you may have to the database. However,
45
+ # keep in mind that not all servers will allow you to have many connections
46
+ # open at the same time. For example, Heroku free PostgreSQL database
47
+ # allows only one connection open.
48
+ def start(max = 8)
44
49
  max.times do
45
50
  @pool << PG.connect(
46
51
  dbname: @dbname, host: @host, port: @port,
@@ -50,7 +55,40 @@ class Pgtk::Pool
50
55
  self
51
56
  end
52
57
 
53
- # Make a query and return the result as an array of hashes.
58
+ # Make a query and return the result as an array of hashes. For example,
59
+ # in order to fetch the list of all books belonging to the user:
60
+ #
61
+ # books = pool.exec('SELECT * FROM book WHERE owner = $1', ['yegor256'])
62
+ # books.each do |row|
63
+ # puts 'ID: ' + row['id'].to_i
64
+ # puts 'Created: ' + Time.parse(row['created'])
65
+ # puts 'Title: ' + row['title']
66
+ # end
67
+ #
68
+ # All values in the retrieved hash are strings. No matter what types of
69
+ # of data you have in the database, you get strings here. It's your job
70
+ # to convert them to the type you need.
71
+ #
72
+ # In order to insert a new row (pay attention to the +RETURNING+ clause
73
+ # at the end of the SQL query):
74
+ #
75
+ # id = pool.exec(
76
+ # 'INSERT INTO book (owner, title) VALUES ($1, $2) RETURNING id',
77
+ # ['yegor256', 'Elegant Objects']
78
+ # )[0]['id'].to_i
79
+ #
80
+ # You can also pass a block to this method, if you want to get an instance
81
+ # of +PG::Result+ instead of an array of hashes:
82
+ #
83
+ # pool.exec('SELECT * FROM book WHERE owner = $1', ['yegor256']) do |res|
84
+ # res.each do |row|
85
+ # puts 'ID: ' + row['id'].to_i
86
+ # puts 'Title: ' + row['title']
87
+ # end
88
+ # end
89
+ #
90
+ # More details about +exec_params+, which is called here, you can find
91
+ # here: https://www.rubydoc.info/gems/pg/0.17.1/PG%2FConnection:exec_params
54
92
  def exec(query, args = [], result = 0)
55
93
  connect do |c|
56
94
  c.exec_params(query, args, result) do |res|
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.2.1'
31
+ VERSION = '0.2.2'
32
32
  end
@@ -45,7 +45,7 @@ class TestLiquibaseTask < Minitest::Test
45
45
  Rake::Task['pgsql2'].invoke
46
46
  Pgtk::LiquibaseTask.new(:liquibase2) do |t|
47
47
  t.master = File.join(__dir__, '../test-resources/master.xml')
48
- t.yaml = File.join(dir, 'cfg.yml')
48
+ t.yaml = ['file-is-absent', File.join(dir, 'cfg.yml')]
49
49
  t.quiet = true
50
50
  end
51
51
  Rake::Task['liquibase2'].invoke
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.2.1
4
+ version: 0.2.2
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-04-15 00:00:00.000000000 Z
11
+ date: 2019-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace