pg_conn 0.13.1 → 0.13.3

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: 30f37deaa02a7ce6c10c42be3b5432ac3e80c21fd82ec8a0d33d10cfc29ad904
4
- data.tar.gz: b78696618951f214e39f5e075ad1d657e86d0d5dda691b5f9b081e51b45b40a1
3
+ metadata.gz: 57162c4e497d2a3146227e38dc53fc62401b64594f77ddb62f9e52696e351767
4
+ data.tar.gz: cef0246edde288bac0c4aa49cdf8f45b96d8d7831543725c58ed416a44cbde25
5
5
  SHA512:
6
- metadata.gz: 68bab843ada37c8214bd7281bda915a6ec509dd337b4cae40384308d60408bfdc7de4abd10eefc94123248d438db4f01942ba7bdc2fd4e17f3dd28096e07aaac
7
- data.tar.gz: 1a64027e97471f53ab114f617de495be2f4adab7e64cd30cf63b91a9a698462cae13531b990c3f96241d008e7a343b7163bcde8bd1d0371efb1935a741215384
6
+ metadata.gz: f5839de957b29863938720f536b327e98c66f13fcf8c7e69b8d2909f47d801b33ae30f8690ba09fa5fdbb5144b6bb3d758addfb0b8c7dc0a89bafcd6af9d473d
7
+ data.tar.gz: aa5dc57e654267165b376168d8721cb34004ec0aeecf7efabf3547b96d4080ad49eaf5aff0f221b5d91a5dbf35e97b885b5b1e00f951cc02d65d82d281df0136
@@ -69,11 +69,12 @@ 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 unless if :public is false. Uses the current
73
- # database if @database is nil
72
+ # schema is recreated afterwards unless if :public is false. Uses the
73
+ # current database if @database is nil
74
74
  #
75
75
  # Note that the database can have active users logged in while the database
76
- # is emptied
76
+ # is emptied. TODO Explain what happens if the users have active
77
+ # transactions. Should the be terminated?
77
78
  #
78
79
  def empty!(database = nil, public: true, exclude: [])
79
80
  local = !database.nil?
@@ -86,7 +87,7 @@ module PgConn
86
87
  .join(", ")
87
88
  conn.exec "drop schema #{schemas} cascade"
88
89
 
89
- # FIXME SECURITY Why grant 'create' to public?
90
+ # FIXME FIXME FIXME SECURITY Why grant 'create' to public?
90
91
  conn.exec %(
91
92
  create schema public authorization postgres;
92
93
  grant usage, create on schema public to public
@@ -102,6 +103,7 @@ module PgConn
102
103
  create(to_database, owner: owner, template: from_database)
103
104
  end
104
105
 
106
+ # TODO: This code is replicated across many project. Should be moved to PgConn
105
107
  def load(database, file, role: ENV['USER'], gzip: nil)
106
108
  command_opt = role ? "-c \"set role #{role}\";\n" : nil
107
109
  if gzip
@@ -116,6 +118,7 @@ module PgConn
116
118
  status == 0 or raise PsqlError.new(stderr)
117
119
  end
118
120
 
121
+ # TODO: This code is replicated across many project. Should be moved to PgConn
119
122
  def save(database, file, data: true, schema: true, gzip: nil)
120
123
  data_opt = data ? nil : "--schema-only"
121
124
  schema_opt = schema ? nil : "--data-only"
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.13.1"
2
+ VERSION = "0.13.3"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require "pg"
2
2
  require 'ostruct'
3
3
 
4
- require "pg_conn/version"
5
- require "pg_conn/role_methods"
6
- require "pg_conn/schema_methods"
7
- require "pg_conn/rdbms_methods"
8
- require "pg_conn/session_methods"
4
+ require_relative "pg_conn/version"
5
+ require_relative "pg_conn/role_methods"
6
+ require_relative "pg_conn/schema_methods"
7
+ require_relative "pg_conn/rdbms_methods"
8
+ require_relative "pg_conn/session_methods"
9
9
 
10
10
  module PgConn
11
11
  class Error < StandardError; end
@@ -263,7 +263,7 @@ module PgConn
263
263
  # exist?(table, id)
264
264
  # eists?(table, where_clause)
265
265
  #
266
- # Return true iff the query returns exactly one value. Use '!empty?' to
266
+ # Return true iff the query returns exactly one record. Use '!empty?' to
267
267
  # check if the query returns one or more records
268
268
  def exist?(*args)
269
269
  arg1, arg2 = *args
@@ -562,14 +562,28 @@ module PgConn
562
562
  def update(schema = nil, table, expr, hash)
563
563
  table = [schema, table].compact.join(".")
564
564
  assignments = hash.map { |k,v| "#{k} = #{quote_literal(v)}" }.join(", ")
565
- constraint = (expr.is_a?(String) ? expr : "id = #{quote_literal(expr)}")
565
+ constraint =
566
+ case expr
567
+ when String; expr
568
+ when Integer; "id = #{quote_literal(expr)}"
569
+ when Array; "id in #{quote_literal_list(expr)}"
570
+ else
571
+ raise ArgumentError
572
+ end
566
573
  exec %(update #{table} set #{assignments} where #{constraint})
567
574
  end
568
575
 
569
576
  # Delete record(s)
570
577
  def delete(schema = nil, table, expr)
571
578
  table = [schema, table].compact.join(".")
572
- constraint = (expr.is_a?(String) ? expr : "id = #{quote_literal(expr)}")
579
+ constraint =
580
+ case expr
581
+ when String; expr
582
+ when Integer; "id = #{quote_literal(expr)}"
583
+ when Array; "id in #{quote_literal_list(expr)}"
584
+ else
585
+ raise ArgumentError
586
+ end
573
587
  exec %(delete from #{table} where #{constraint})
574
588
  end
575
589
 
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.13.1
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-15 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg