pg_conn 0.17.3 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/TODO +4 -1
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +55 -12
- 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: f7b067cc4d9e831d6c30c135a351a05362953d75414d888a9c012105117dfcd1
|
4
|
+
data.tar.gz: 17eeef29e2844094019bf16890a98cade8b788f2465eb63797a46cdac66d3b93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e77389acba0ebdd70d4e22440db2449129184bec8a775019d9e8e5a1e601990b276be89482286f4e24c7a35767f3aeba8293a6e2de9832600a16183dfe97db
|
7
|
+
data.tar.gz: 348441a6c040059ad68f648146c468d52e914841411f282efde924cee707d97ef7616092612b7d82844a0ededbb05e8bc33122cf408458f040cd9701214ddebc
|
data/TODO
CHANGED
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -327,8 +327,8 @@ module PgConn
|
|
327
327
|
# Return a single value. It is an error if the query doesn't return a
|
328
328
|
# single record with a single column. If :transaction is true, the query
|
329
329
|
# will be executed in a transaction and also be committed if :commit is
|
330
|
-
# true (this is the default). It can be used to execute 'insert'
|
331
|
-
# with a 'returning' clause
|
330
|
+
# true (this is the default). It can also be used to execute 'insert'
|
331
|
+
# statements with a 'returning' clause
|
332
332
|
def value(query) #, transaction: false, commit: true)
|
333
333
|
r = pg_exec(query)
|
334
334
|
check_1c(r)
|
@@ -567,16 +567,59 @@ module PgConn
|
|
567
567
|
end
|
568
568
|
end
|
569
569
|
|
570
|
-
#
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
570
|
+
# :call-seq*
|
571
|
+
# insert(table, record|records)
|
572
|
+
# insert(table, fields, record|records|tuples)
|
573
|
+
# insert(schema, table, record|records)
|
574
|
+
# insert(schema, table, fields, record|records|tuples)
|
575
|
+
#
|
576
|
+
# Insert record(s) in table and return id(s)
|
577
|
+
#
|
578
|
+
# There is no variant that takes a single tuple because it would then be
|
579
|
+
# impossible to have array or hash field values
|
580
|
+
def insert(*args)
|
581
|
+
# Add schema (=nil) if absent
|
582
|
+
args.unshift nil if args.size == 2 || (args.size == 3 && args[1].is_a?(Array))
|
583
|
+
|
584
|
+
# Add fields (=nil) if absent
|
585
|
+
args.insert(-2, nil) if !args[-2].is_a?(Array)
|
586
|
+
|
587
|
+
# Check number of arguments
|
588
|
+
args.size == 4 or raise ArgumentError, "Illegal number of arguments"
|
589
|
+
|
590
|
+
# Extract parameters
|
591
|
+
schema, table, fields, data = args
|
592
|
+
|
593
|
+
# Normalize table
|
594
|
+
table = schema ? "#{schema}.#{table}" : table
|
595
|
+
|
596
|
+
# Find method and normalize data
|
597
|
+
if data.is_a?(Array)
|
598
|
+
if data.empty?
|
599
|
+
return []
|
600
|
+
elsif data.first.is_a?(Array)
|
601
|
+
method = :values
|
602
|
+
fields or raise ArgumentError
|
603
|
+
tuples = data
|
604
|
+
elsif data.first.is_a?(Hash)
|
605
|
+
method = :values
|
606
|
+
fields ||= data.first.keys
|
607
|
+
tuples = data.map { |record| fields.map { |field| record[field] } }
|
608
|
+
else
|
609
|
+
raise ArgumentError
|
610
|
+
end
|
611
|
+
elsif data.is_a?(Hash)
|
612
|
+
method = :value
|
613
|
+
fields ||= data.keys
|
614
|
+
tuples = [fields.map { |field| data[field] }]
|
615
|
+
else
|
616
|
+
raise ArgumentError
|
617
|
+
end
|
618
|
+
|
619
|
+
# Build and execute SQL statement
|
620
|
+
columns = quote_identifier_list(fields)
|
621
|
+
values = tuples.map { |tuple| quote_literal_list(tuple) }.join(', ')
|
622
|
+
self.send method, %(insert into #{table} #{columns} values #{values} returning id)
|
580
623
|
end
|
581
624
|
|
582
625
|
# Update record(s)
|
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.18.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-05-
|
11
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|