pgtk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df81fe94f842797b07e43250ce3c554de8ce3dcb3149529e596ceb946e5476f4
4
+ data.tar.gz: a995aff368837b7dcf118e06db328e47f7aa49a08db945264503ea72f2c0ef5c
5
+ SHA512:
6
+ metadata.gz: de8a01282af8ca4cef9eb2d3c91ea3631ecb0f2960491472bc43f8ac89767478b845153ec256b91ef3e35dcaffba21fc64681561ee9aca0a6ed2aee683befb43
7
+ data.tar.gz: 0a0342d5bf4b22c46f16366975cf7e972ff4a508e07753cce2917989c0da79b80951a4b724cb879abda576f63b4f2ba288bfafe0f4da82ee18dd83b126d4a5c9
@@ -0,0 +1,9 @@
1
+ errors:
2
+ - yegor256@gmail.com
3
+ # alerts:
4
+ # github:
5
+ # - yegor256
6
+
7
+ tags:
8
+ - pdd
9
+ - bug
@@ -0,0 +1,7 @@
1
+ # Check out all text files in UNIX format, with LF as end of line
2
+ # Don't change this file. If you have any ideas about it, please
3
+ # submit a separate issue about it and we'll discuss.
4
+
5
+ * text=auto eol=lf
6
+ *.rb ident
7
+ *.xml ident
@@ -0,0 +1,7 @@
1
+ coverage/
2
+ Gemfile.lock
3
+ .idea/
4
+ *.gem
5
+ .bundle/
6
+ .DS_Store
7
+ rdoc/
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude coverage/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'assets/**/*'
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.3
7
+
8
+ Style/ClassAndModuleChildren:
9
+ Enabled: false
10
+ Layout/EndOfLine:
11
+ EnforcedStyle: lf
12
+ Metrics/BlockLength:
13
+ Max: 50
14
+ Layout/EmptyLineAfterGuardClause:
15
+ Enabled: false
16
+ Metrics/AbcSize:
17
+ Max: 50
18
+ Metrics/CyclomaticComplexity:
19
+ Max: 10
20
+ Metrics/MethodLength:
21
+ Max: 100
22
+ Metrics/PerceivedComplexity:
23
+ Max: 10
@@ -0,0 +1,35 @@
1
+ assets:
2
+ rubygems.yml: zerocracy/home#assets/rubygems.yml
3
+ s3cfg: zerocracy/home#assets/s3cfg
4
+ install: |
5
+ export PATH=$PATH:/usr/lib/postgresql/10/bin
6
+ sudo apt-get -y update
7
+ sudo apt-get -y install libpq-dev
8
+ export GEM_HOME=~/.ruby
9
+ export GEM_PATH=$GEM_HOME:$GEM_PATH
10
+ sudo apt-get -y update
11
+ sudo gem install pdd
12
+ release:
13
+ script: |-
14
+ bundle install
15
+ rake
16
+ rm -rf *.gem
17
+ sed -i "s/1\.0\.snapshot/${tag}/g" lib/pgtk/version.rb
18
+ git add lib/pgtk/version.rb
19
+ git commit -m "version set to ${tag}"
20
+ gem build pgtk.gemspec
21
+ chmod 0600 ../rubygems.yml
22
+ gem push *.gem --config-file ../rubygems.yml
23
+ commanders:
24
+ - yegor256
25
+ architect:
26
+ - yegor256
27
+ merge:
28
+ script: |-
29
+ bundle install
30
+ rake
31
+ pdd
32
+ deploy:
33
+ script: |-
34
+ echo "There is nothing to deploy"
35
+ exit -1
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2019 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ if Gem.win_platform? then
22
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
23
+ SimpleCov::Formatter::HTMLFormatter
24
+ ]
25
+ SimpleCov.start do
26
+ add_filter "/test/"
27
+ add_filter "/features/"
28
+ end
29
+ else
30
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
31
+ [SimpleCov::Formatter::HTMLFormatter]
32
+ )
33
+ SimpleCov.start do
34
+ add_filter "/test/"
35
+ add_filter "/features/"
36
+ minimum_coverage 60
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ sudo: required
3
+ rvm:
4
+ - 2.6.0
5
+ cache: bundler
6
+ branches:
7
+ only:
8
+ - master
9
+ addons:
10
+ postgresql: "10"
11
+ apt:
12
+ packages:
13
+ - postgresql-10
14
+ - postgresql-client-10
15
+ install:
16
+ - travis_retry bundle update
17
+ services:
18
+ - postgresql
19
+ script:
20
+ - bundle exec rake
21
+ after_success:
22
+ - "bash <(curl -s https://codecov.io/bash)"
23
+
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ source 'https://rubygems.org'
24
+ ruby '~>2.3'
25
+ gemspec
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2019 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,122 @@
1
+ <img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" height="64px"/>
2
+
3
+ [![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org)
4
+ [![Managed by Zerocracy](https://www.0crat.com/badge/C3RFVLU72.svg)](https://www.0crat.com/p/C3RFVLU72)
5
+ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/pgtk)](http://www.rultor.com/p/yegor256/pgtk)
6
+ [![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
7
+
8
+ [![Build Status](https://travis-ci.org/yegor256/pgtk.svg)](https://travis-ci.org/yegor256/pgtk)
9
+ [![Build status](https://ci.appveyor.com/api/projects/status/tbeaa0d4dk38xdb5?svg=true)](https://ci.appveyor.com/project/yegor256/pgtk)
10
+ [![PDD status](http://www.0pdd.com/svg?name=yegor256/pgtk)](http://www.0pdd.com/p?name=yegor256/pgtk)
11
+ [![Gem Version](https://badge.fury.io/rb/pgtk.svg)](http://badge.fury.io/rb/pgtk)
12
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3a5bebac001e5288b00d/maintainability)](https://codeclimate.com/github/yegor256/pgtk/maintainability)
13
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/pgtk.svg)](https://codecov.io/github/yegor256/pgtk?branch=master)
14
+
15
+ This small Ruby gem helps you integrate PostgreSQL with your Ruby
16
+ web app, through [Liquibase](https://www.liquibase.org/). It also adds a simple connection pool
17
+ and query processor, to make SQL manipulation simpler.
18
+
19
+ First of all, on top of
20
+ [Ruby](https://www.ruby-lang.org/en/) and
21
+ [Bundler](https://bundler.io/)
22
+ you need to have
23
+ [PostgreSQL](https://www.postgresql.org/),
24
+ [Java 8+](https://java.com/en/download/), and
25
+ [Maven 3.2+](https://maven.apache.org/) installed.
26
+ In Ubuntu 16+ this should be enough:
27
+
28
+ ```bash
29
+ $ sudo apt-get install -y postgresql-10 postgresql-client-10
30
+ $ sudo apt-get install -y default-jre maven
31
+ ```
32
+
33
+ Then, add this to your [`Gemfile`](https://bundler.io/gemfile.html):
34
+
35
+ ```ruby
36
+ gem 'pgtk'
37
+ ```
38
+
39
+ Then, add this to your [`Rakefile`](https://github.com/ruby/rake/blob/master/doc/rakefile.rdoc):
40
+
41
+ ```ruby
42
+ require 'pgtk/pgsql_task'
43
+ Pgtk::PgsqlTask.new :pgsql do |t|
44
+ t.dir = 'target/pgsql' # Temp directory with PostgreSQL files
45
+ t.fresh_start = true # To delete the directory on every start
46
+ t.user = 'test'
47
+ t.password = 'test'
48
+ t.dbname = 'test'
49
+ t.yaml = 'target/config.yml' # YAML file to be created with connection details
50
+ end
51
+ ```
52
+
53
+ And this too:
54
+
55
+ ```ruby
56
+ require 'pgtk/liquibase_task'
57
+ Pgtk::LiquibaseTask.new liquibase: :pgsql do |t|
58
+ t.master = 'liquibase/master.xml' # Master XML file path
59
+ t.yaml = 'target/config.yml' # YAML file with connection details
60
+ end
61
+ ```
62
+
63
+ You should create that `liquibase/master.xml` file in your repository,
64
+ and a number of other XML files with Liquibase changes. This
65
+ [example](https://github.com/zold-io/wts.zold.io/tree/master/liquibase)
66
+ will help you understand them.
67
+
68
+ Now, you can do this:
69
+
70
+ ```bash
71
+ $ bundle exec rake pgsql liquibase
72
+ ```
73
+
74
+ A temporary PostgreSQL server will be started and the entire set of
75
+ Liquibase SQL changes will be applied. You will be able to connect
76
+ to it from your application, using the file `target/config.yml`.
77
+
78
+ From inside your app you may find this class useful:
79
+
80
+ ```ruby
81
+ require 'pgtk/pool'
82
+ yaml = YAML.load_file('target/config.yml')
83
+ pgsql = Pgtk::Pool.new(
84
+ port: yaml['pgsql']['port'],
85
+ dbname: yaml['pgsql']['dbname'],
86
+ user: yaml['pgsql']['user'],
87
+ password: yaml['pgsql']['password']
88
+ )
89
+ pgsql.start(5) # Start it with five simultaneous connections
90
+ name = pgsql.exec('SELECT name FROM user WHERE id = $1', [id])[0]['name']
91
+ ```
92
+
93
+ You may also use it if you need direct access to the connection,
94
+ for example in order to run a set of requests in a transaction:
95
+
96
+ ```ruby
97
+ pgsql.connect do |c|
98
+ c.transaction do |conn|
99
+ conn.exec_params('DELETE FROM user WHERE id = $1', [id])
100
+ conn.exec_params('INSERT INTO user (name, phone) VALUES ($1, $2)', [name, phone])
101
+ end
102
+ end
103
+ ```
104
+
105
+ Should work. Well, it works in [zold-io/wts.zold.io](https://github.com/zold-io/wts.zold.io)
106
+ and [yegor256/mailanes](https://github.com/yegor256/mailanes). They both are
107
+ open source, you can see how they use `pgtk`.
108
+
109
+ ## How to contribute
110
+
111
+ Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
112
+ Make sure your build is green before you contribute
113
+ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
114
+ [Bundler](https://bundler.io/) installed. Then:
115
+
116
+ ```
117
+ $ bundle update
118
+ $ bundle exec rake
119
+ ```
120
+
121
+ If it's clean and you don't see any error messages, submit your pull request.
122
+
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'rake'
25
+ require 'rdoc'
26
+ require 'rake/clean'
27
+
28
+ def name
29
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
30
+ end
31
+
32
+ def version
33
+ Gem::Specification.load(Dir['*.gemspec'].first).version
34
+ end
35
+
36
+ task default: %i[clean test rubocop xcop copyright]
37
+
38
+ require 'rake/testtask'
39
+ desc 'Run all unit tests'
40
+ Rake::TestTask.new(:test) do |test|
41
+ Rake::Cleaner.cleanup_files(['coverage'])
42
+ test.libs << 'lib' << 'test'
43
+ test.pattern = 'test/**/test_*.rb'
44
+ test.verbose = false
45
+ end
46
+
47
+ require 'rdoc/task'
48
+ desc 'Build RDoc documentation'
49
+ Rake::RDocTask.new do |rdoc|
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "#{name} #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
55
+
56
+ require 'rubocop/rake_task'
57
+ desc 'Run RuboCop on all directories'
58
+ RuboCop::RakeTask.new(:rubocop) do |task|
59
+ task.fail_on_error = true
60
+ task.requires << 'rubocop-rspec'
61
+ end
62
+
63
+ require 'xcop/rake_task'
64
+ desc 'Validate all XML/XSL/XSD/HTML files for formatting'
65
+ Xcop::RakeTask.new :xcop do |task|
66
+ task.license = 'LICENSE.txt'
67
+ task.includes = ['**/*.xml', '**/*.xsl', '**/*.xsd', '**/*.html']
68
+ task.excludes = ['target/**/*', 'coverage/**/*']
69
+ end
70
+
71
+ task :copyright do
72
+ sh "grep -q -r '#{Date.today.strftime('%Y')}' \
73
+ --include '*.rb' \
74
+ --include '*.txt' \
75
+ --include 'Rakefile' \
76
+ ."
77
+ end
@@ -0,0 +1,21 @@
1
+ version: '{build}'
2
+ skip_tags: true
3
+ clone_depth: 10
4
+ branches:
5
+ only:
6
+ - master
7
+ except:
8
+ - gh-pages
9
+ os: Windows Server 2012
10
+ install:
11
+ - cmd: SET PATH=C:\Ruby23-x64\bin;%PATH%
12
+ - cmd: ruby --version
13
+ - cmd: git --version
14
+ build_script:
15
+ - bundle update
16
+ - bundle install
17
+ test_script:
18
+ - rake
19
+ cache:
20
+ - C:\Ruby200\bin -> pgtk.gemspec
21
+ - C:\Ruby200\lib\ruby\gems\2.0.0 -> pgtk.gemspec
@@ -0,0 +1,3 @@
1
+ default: --format pretty
2
+ travis: --format progress
3
+ html_report: --format progress --format html --out=features_report.html