pg_conn 0.12.1 → 0.13.0
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/version.rb +1 -1
- data/lib/pg_conn.rb +27 -3
- 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: 7c975d085fc3e3f58a72fbb13d0e5ce9428254969e8723c8af0d6577381f0f70
|
4
|
+
data.tar.gz: 6a786d3466d2c0661b22ee738212a3b8a37afca86a99dbde59773e5d47b7a5f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6710fbd23379b8e1b13bd41dda8ce206fcefca30c93f43f2be0f4b7e437d854d50c89aa429cb70f52901eb7d4b515a810012801adc334b2082307dcc4ca2aaa9
|
7
|
+
data.tar.gz: 838a84b8f67710abcee3381f3691e93fab21c9d07ec48efa1480faec5c4b7621a5904d1000f2a62666c998f30b499de06c74eada70fac6609ea601beabf7b976
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -44,11 +44,11 @@ module PgConn
|
|
44
44
|
|
45
45
|
# Name of user
|
46
46
|
def user() @pg_connection.user end
|
47
|
-
alias_method :username, :user # Obsolete
|
47
|
+
alias_method :username, :user # Obsolete FIXME Is it?
|
48
48
|
|
49
49
|
# Name of database
|
50
50
|
def name() @pg_connection.db end
|
51
|
-
alias_method :database, :name # Obsolete
|
51
|
+
alias_method :database, :name # Obsolete FIXME Is it?
|
52
52
|
|
53
53
|
# Database manipulation methods: #exist?, #create, #drop, #list
|
54
54
|
attr_reader :rdbms
|
@@ -253,7 +253,7 @@ module PgConn
|
|
253
253
|
end
|
254
254
|
|
255
255
|
# Quote array as a parenthesis-enclosed list of identifiers
|
256
|
-
def quote_identifier_list(
|
256
|
+
def quote_identifier_list(identifiers) = "(#{identifiers.map { quote_identifier(_1) }.join(', ')})"
|
257
257
|
|
258
258
|
# Quote array as a parenthesis-enclosed list of literals
|
259
259
|
def quote_literal_list(values) = "(#{values.map { quote_literal(_1) }.join(', ')})"
|
@@ -547,6 +547,30 @@ module PgConn
|
|
547
547
|
end
|
548
548
|
end
|
549
549
|
|
550
|
+
# Insert record(s) in a table
|
551
|
+
def insert(schema = nil, table, array_or_hash)
|
552
|
+
table = [schema, table].compact.join(".")
|
553
|
+
array = array_or_hash.is_a?(Array) ? array_or_hash : [array_or_hash]
|
554
|
+
identifiers = quote_identifier_list(array.first.keys)
|
555
|
+
literals = array.map { |hash| quote_literal_list(hash.values) }.join(", ")
|
556
|
+
exec %(insert into #{table} #{identifiers} values #{literals})
|
557
|
+
end
|
558
|
+
|
559
|
+
# Update record(s)
|
560
|
+
def update(schema = nil, table, expr, hash)
|
561
|
+
table = [schema, table].compact.join(".")
|
562
|
+
assignments = hash.map { |k,v| "#{k} = #{quote_literal(v)}" }.join(", ")
|
563
|
+
constraint = (expr.is_a?(String) ? expr : "id = #{quote_literal(expr)}")
|
564
|
+
exec %(update #{table} set #{assignments} where #{constraint})
|
565
|
+
end
|
566
|
+
|
567
|
+
# Delete record(s)
|
568
|
+
def delete(schema = nil, table, expr)
|
569
|
+
table = [schema, table].compact.join(".")
|
570
|
+
constraint = (expr.is_a?(String) ? expr : "id = #{quote_literal(expr)}")
|
571
|
+
exec %(delete from #{table} where #{constraint})
|
572
|
+
end
|
573
|
+
|
550
574
|
# Execute SQL statement(s) in a transaction and return the number of
|
551
575
|
# affected records (if any). Also sets #timestamp unless a transaction is
|
552
576
|
# already in progress. The +sql+ argument can be a command (String) or an
|
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.
|
4
|
+
version: 0.13.0
|
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-
|
11
|
+
date: 2024-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|