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 +4 -4
- data/lib/pg_conn/rdbms_methods.rb +7 -4
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +22 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57162c4e497d2a3146227e38dc53fc62401b64594f77ddb62f9e52696e351767
|
4
|
+
data.tar.gz: cef0246edde288bac0c4aa49cdf8f45b96d8d7831543725c58ed416a44cbde25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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"
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require "pg"
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
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 =
|
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 =
|
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.
|
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-
|
11
|
+
date: 2024-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|