pg_conn 0.24.0 → 0.25.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 +21 -2
- 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: eb9303d38e0364b374379d8d0549d461decf393d1a20c5a97da42b1c0b0d7e17
|
4
|
+
data.tar.gz: 53512feaaff24b3b6e8b7366a0c860dac0d38f8880698570cfa16cffbb7a46b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9efb0689c559425bee8bebb5d984c72222e8bd2377803cc8c1415d5b253ada2f0913dc70b17ef12c0f9677b26e1db60accb5bdb66de41220f7001a2628c013c
|
7
|
+
data.tar.gz: fcd4f4e04157e2cdf10226f1a4545ab8fd66ce960cf14c732e0eceda9450e3c94b211277da303e8338aff7fbfbb3eb09bcd6b5946e979aa383f5f3b803ac86d7
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -630,7 +630,10 @@ module PgConn
|
|
630
630
|
#
|
631
631
|
# There is no variant that takes a single tuple because it would then be
|
632
632
|
# impossible to have array or hash field values
|
633
|
-
def insert(*args)
|
633
|
+
def insert(*args, upsert: nil, **opts)
|
634
|
+
# Add options to args except the special :upsert option
|
635
|
+
args << opts if !opts.empty?
|
636
|
+
|
634
637
|
# Add schema (=nil) if absent
|
635
638
|
args.unshift nil if args.size == 2 || (args.size == 3 && args[1].is_a?(Array))
|
636
639
|
|
@@ -665,17 +668,33 @@ module PgConn
|
|
665
668
|
fields ||= data.keys
|
666
669
|
tuples = [fields.map { |field| data[field] }]
|
667
670
|
else
|
668
|
-
raise ArgumentError
|
671
|
+
raise ArgumentError, "Illegal argument '#{data.inspect}'"
|
669
672
|
end
|
670
673
|
|
674
|
+
# On-conflict clause
|
675
|
+
upsert_sql =
|
676
|
+
case upsert
|
677
|
+
when true; "on conflict do nothing"
|
678
|
+
when String; "on conlict #{upsert}"
|
679
|
+
when false, nil; ""
|
680
|
+
else
|
681
|
+
raise ArgumentError, "Illegal value for :upsert option: #{upsert.inspect}"
|
682
|
+
end
|
683
|
+
|
671
684
|
# Execute SQL statement using either :value or :values depending on data arity
|
672
685
|
self.send method, %(
|
673
686
|
insert into #{table} (#{quote_identifiers(fields)})
|
674
687
|
values #{quote_tuples(tuples)}
|
688
|
+
#{upsert_sql}
|
675
689
|
returning id
|
676
690
|
)
|
677
691
|
end
|
678
692
|
|
693
|
+
# Use upsert. Currently on 'on conflict do nothing' is supported
|
694
|
+
def upsert(*args)
|
695
|
+
insert(*args, upsert: true)
|
696
|
+
end
|
697
|
+
|
679
698
|
# Update record(s)
|
680
699
|
def update(schema = nil, table, expr, hash)
|
681
700
|
table = [schema, table].compact.join(".")
|
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.25.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-10-
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|