pg_conn 0.3.7 → 0.4.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: 589bec28c740660ad6dd0f09101eda54af26aad2f03a43a27ed7ffa6e422fdf3
4
- data.tar.gz: 17ccef8e37a0699331e7c518d1a856652750719dbd2c1a3d04af5173f0d625f5
3
+ metadata.gz: afa2c9841fc7aa38cc0535f7aeb7f307e9c2b5fea377a06ccd8f70bde28eb3fa
4
+ data.tar.gz: 371188d5dcaa4f89bfc29ac8afdbc4497e3d59516ffc6e85de1b79b2a1a8e6e1
5
5
  SHA512:
6
- metadata.gz: 91c48594e61dc7caef44a22de75165f5815e69b4dc2e1b181b024291b5bb7cd3ec9eee97aced702a459424afcc093406af9e6d6cb631b128e8117f0084249ac4
7
- data.tar.gz: d485db7de8dd27c0eb81db8c1d6940f02ba822a88514e6d13999747c55e902121306e1a0c04105be8881dd0f84819f73aa46101432004b22745e2e9848b0d3d6
6
+ metadata.gz: 693d6fbb2fa03e452304a859f5e541f5a28e14f26ff445d2cdc5ae6861265dce28529f571d3046bc49917b827256b00c6fe1588e832ec65cc3fd21c7e2c7587b
7
+ data.tar.gz: f3690ecdcfc7a50cb0f47b7269d6b515fee41f08b0a51f1c542c4d73fbdf6dae21d7008efaa9f749a2c2d2961e8d9ff2f2a098d8c5d7e379607ec45f80878ea3
data/TODO CHANGED
@@ -1,4 +1,11 @@
1
1
  TODO
2
+ o Option to accept no records when using #value, #tuple, and #struct. The
3
+ alternative is to use the 'one-table' as base table in the query and then
4
+ left join the rest
5
+ o Implement search_path
6
+ o Proper implementation of call of functions and procedures: Functions should
7
+ be called through #value, #tuple etc. and procedures through #call.
8
+ Proceduer output parameters needs handling too
2
9
  o Create an abstract PgConnBase and have PgStmts (writes statements to array)
3
10
  and PgConn (sends statements to server) classes derived from it
4
11
  o fix silent
@@ -69,13 +69,13 @@ module PgConn
69
69
  end
70
70
 
71
71
  # Hollow-out a database by removing all schemas in the database. The public
72
- # schema is recreated afterwards. Use the current database if @database is
73
- # nil
72
+ # schema is recreated afterwards if :public is true. Uses the current
73
+ # database if @database is nil
74
74
  #
75
75
  # Note that the database can have active users logged in while the database
76
76
  # is emptied
77
77
  #
78
- def empty!(database = nil, exclude: [])
78
+ def empty!(database = nil, public: true, exclude: [])
79
79
  local = !database.nil?
80
80
  begin
81
81
  conn = local ? PgConn.new(database) : self.conn
@@ -84,11 +84,11 @@ module PgConn
84
84
  .values("select nspname from pg_namespace where nspowner != 10 or nspname = 'public'")
85
85
  .select { |schema| !exclude.include?(schema) }
86
86
  .join(", ")
87
+ conn.exec "drop schema #{schemas} cascade"
87
88
  conn.exec %(
88
- drop schema #{schemas} cascade;
89
89
  create schema public authorization postgres;
90
90
  grant usage, create on schema public to public
91
- )
91
+ ) if public
92
92
  ensure
93
93
  conn&.terminate if local
94
94
  end
@@ -35,8 +35,8 @@ module PgConn
35
35
  true
36
36
  end
37
37
 
38
- # List schemas. By built-in schemas are not listed unless the :all option
39
- # is true. The :exclude option can be used to exclude named schemas
38
+ # List schemas. Built-in schemas are not listed unless the :all option is
39
+ # true. The :exclude option can be used to exclude named schemas
40
40
  def list(all: false, exclude: [])
41
41
  conn.values(%(
42
42
  select schema_name
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.3.7"
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -438,7 +438,8 @@ module PgConn
438
438
  # (like #value or #values), a tuple if the record has multiple columns
439
439
  # (like #tuple), and an array of of tuples if the result contained more
440
440
  # than one record with multiple columns (like #tuples)
441
- def call(name, *args)
441
+ #
442
+ def call(name, *args, proc: false)
442
443
  args_sql = args.map { |arg| # TODO: Use pg's encoder
443
444
  case arg
444
445
  when NilClass; "null"
@@ -451,19 +452,24 @@ module PgConn
451
452
  raise ArgumentError, "Unrecognized value: #{arg.inspect}"
452
453
  end
453
454
  }.join(", ")
454
- r = pg_exec "select * from #{name}(#{args_sql})"
455
- if r.ntuples == 0
456
- raise Error, "No records returned"
457
- elsif r.ntuples == 1
458
- if r.nfields == 1
459
- r.values[0][0]
455
+ if proc
456
+ pg_exec "call #{name}(#{args_sql})"
457
+ return nil
458
+ else
459
+ r = pg_exec "select * from #{name}(#{args_sql})"
460
+ if r.ntuples == 0
461
+ raise Error, "No records returned"
462
+ elsif r.ntuples == 1
463
+ if r.nfields == 1
464
+ r.values[0][0]
465
+ else
466
+ r.values[0]
467
+ end
468
+ elsif r.nfields == 1
469
+ r.column_values(0)
460
470
  else
461
- r.values[0]
471
+ r&.values
462
472
  end
463
- elsif r.nfields == 1
464
- r.column_values(0)
465
- else
466
- r&.values
467
473
  end
468
474
  end
469
475
 
@@ -582,6 +588,7 @@ module PgConn
582
588
  rescue PgConn::Rollback
583
589
  pop_trancaction(commit: false)
584
590
  return nil
591
+ # FIXME: Rescue other postgres errors and wipe-out stack
585
592
  end
586
593
  pop_transaction(commit: commit)
587
594
  result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_conn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.1.4
109
+ rubygems_version: 3.1.2
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Gem pg_conn