pg_helper 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 0.2.1 (2011.03.31)
2
+ * yard documentation added
3
+
4
+ ## 0.2.0 (2011.03.31)
5
+ * changed Jeweler to Bundler
6
+
7
+ ## 0.1.0 (2011.03.21)
8
+ * Hello World!
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ PgHelper
2
+ =============
3
+
4
+ Because sometimes I don't want ActiveRecord to parse all fields, nor think about connection.
5
+ All features are actually provided by [Pg gem](http://rubygems.org/gems/pg)
6
+
7
+
8
+ Features
9
+ -------
10
+
11
+ * Small
12
+ * Ability to pass query params to PostgreSql
13
+ * No parsing of strings
14
+ * also works as rails plugin `rails plugin install https://github.com/webervin/pg_helper.git`
@@ -1,20 +1,44 @@
1
-
1
+ #Main module of PgHelper gem/plugin
2
2
  module PgHelper
3
+
4
+ #Indicates that query returned unexpected columnt count
3
5
  class PgHelperErrorInvalidColumnCount < PGError; end
6
+
7
+ #Indicates that query returned too much rows
4
8
  class PgHelperErrorInvalidRowCount < PGError; end
9
+
10
+ # Indicates that transaction was called while inside transaction
5
11
  class PgHelperErrorNestedTransactionNotAllowed < PGError; end
12
+
13
+ #For use inside transaction to cause rollback.
6
14
  class PgHelperErrorRollback < PGError; end
15
+
16
+ #Indicates that call is invalid outside transaction
7
17
  class PgHelperErrorInvalidOutsideTransaction < PGError; end
18
+
19
+ #Invalid argument
8
20
  class PgHelperErrorParamsMustBeArrayOfStrings < PGError; end
9
21
 
22
+ #Main api class
10
23
  class QueryHelper
11
- attr_accessor :connection_params, :pg_connection
12
24
 
25
+ # @return [Hash] connection params
26
+ attr_accessor :connection_params
27
+
28
+ # Active database connection
29
+ # @return [PGconn] connection see {http://rubygems.org/gems/pg Pg gem on rubygems} for details
30
+ attr_accessor :pg_connection
31
+
32
+
33
+ # Creates a new instance of the QueryHelper
13
34
  def initialize(params)
14
35
  @connection_params = params
15
36
  reconnect
16
37
  end
17
38
 
39
+ # @param [String] query SQL select that should return one cell, may include $1, $2 etc to be replaced by arguments
40
+ # @param [Array<String>] params query arguments to be passed on to PostgreSql
41
+ # @return [String]
18
42
  def value(query, params = [])
19
43
  exec(query, params) do |pg_result|
20
44
  verify_single_cell!(pg_result)
@@ -22,6 +46,9 @@ class QueryHelper
22
46
  end
23
47
  end
24
48
 
49
+ # @param [String] query SQL select that should return one column, may include $1, $2 etc to be replaced by arguments
50
+ # @param [Array<String>] params query arguments to be passed on to PostgreSql
51
+ # @return [Array<String>] Values of selected column
25
52
  def get_column(query, params = [])
26
53
  exec(query, params) do |pg_result|
27
54
  require_single_column!(pg_result)
@@ -29,17 +56,24 @@ class QueryHelper
29
56
  end
30
57
  end
31
58
 
59
+ # @param [String] query SQL update, may include $1, $2 etc to be replaced by arguments
60
+ # @param [Array<String>] params query arguments to be passed on to PostgreSql
61
+ # @return [Integer] Number of rows changed
32
62
  def modify(query, params = [])
33
63
  exec(query, params) do |pg_result|
34
64
  pg_result.cmd_tuples
35
65
  end
36
66
  end
37
67
 
68
+ # Executes content of given block inside database transaction
69
+ #@yield [QueryHelper]
38
70
  def transaction(&block)
39
71
  verify_transaction_possible!(&block)
40
72
  perform_transaction(&block)
41
73
  end
42
74
 
75
+ # Aborts current transaction, or raises exception if invoked outside transaction.
76
+ #@return [void]
43
77
  def rollback!
44
78
  raise PgHelperErrorInvalidOutsideTransaction if connection_idle?
45
79
  raise PgHelperErrorRollback.new
@@ -1,3 +1,5 @@
1
+ #Main module of PgHelper gem/plugin
1
2
  module PgHelper
2
- VERSION = "0.2.0"
3
+ # @return [String] gem version
4
+ VERSION = "0.2.1"
3
5
  end
data/lib/pg_helper.rb CHANGED
@@ -4,4 +4,4 @@ require 'pg'
4
4
 
5
5
  # require all of the library files
6
6
  # note, you may need to specify these explicitly if there are any load order dependencies
7
- require 'pg_helper/query_helper.rb'
7
+ require 'pg_helper/query_helper.rb'
data/pg_helper.gemspec CHANGED
@@ -9,11 +9,10 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Ervin"]
10
10
  s.email = %q{webervin@gmail.com}
11
11
  s.homepage = %q{http://github.com/webervin/pg_helper}
12
+ s.rubyforge_project = "pg_helper"
12
13
  s.summary = %q{Tiny wraper for 'pg' gem}
13
14
  s.description = %q{Makes even easier to use postgresql without activerecord}
14
-
15
-
16
- s.rubyforge_project = "pg_helper"
15
+ s.has_rdoc = 'yard'
17
16
 
18
17
  s.files = `git ls-files`.split("\n")
19
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -27,4 +26,7 @@ Gem::Specification.new do |s|
27
26
  s.add_development_dependency 'wirble'
28
27
  s.add_development_dependency 'metric_fu'
29
28
  s.add_development_dependency 'ZenTest'
29
+ s.add_development_dependency 'yard'
30
+ s.add_development_dependency 'bluecloth' #yard hidden dependency
31
+
30
32
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_helper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ervin
@@ -102,6 +102,34 @@ dependencies:
102
102
  version: "0"
103
103
  version_requirements: *id006
104
104
  name: ZenTest
105
+ - !ruby/object:Gem::Dependency
106
+ prerelease: false
107
+ type: :development
108
+ requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ version_requirements: *id007
118
+ name: yard
119
+ - !ruby/object:Gem::Dependency
120
+ prerelease: false
121
+ type: :development
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ version_requirements: *id008
132
+ name: bluecloth
105
133
  description: Makes even easier to use postgresql without activerecord
106
134
  email: webervin@gmail.com
107
135
  executables: []
@@ -113,8 +141,9 @@ extra_rdoc_files: []
113
141
  files:
114
142
  - .gitignore
115
143
  - Gemfile
144
+ - HISTORY.md
145
+ - README.md
116
146
  - Rakefile
117
- - VERSION
118
147
  - autotest/discover.rb
119
148
  - init.rb
120
149
  - lib/pg_helper.rb
@@ -123,7 +152,7 @@ files:
123
152
  - pg_helper.gemspec
124
153
  - spec/lib/pg_helper_spec.rb
125
154
  - spec/spec_helper.rb
126
- has_rdoc: true
155
+ has_rdoc: yard
127
156
  homepage: http://github.com/webervin/pg_helper
128
157
  licenses: []
129
158
 
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0