pg_conn 0.5.1 → 0.6.0

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: 4831e76784a204c8466e0a58211c24f011e372eea4138b745e236b6f12806646
4
- data.tar.gz: 63a20d32f5882ff6e1961281c655b7c98ac0265910db657f7aef9f433271ddba
3
+ metadata.gz: 68ebf4013a0428bd6cefd0b14606c7de75e5ae1ba96c0207a681e0899bc3f86a
4
+ data.tar.gz: eab9bc8adfd76c5c23e0b97ffad7ee4e17109d2fd4edc41f0d95e144147acd2d
5
5
  SHA512:
6
- metadata.gz: b9791b2c5b23ee1c49cb1447309545ea091acc8ac35111f9c856594f9af210a4bf68f7d2dcf49b9e6fb3cab76c259f1d4bb2056e6655c5ac5a02eb943efebf28
7
- data.tar.gz: 173ade9118cd45141c632a4955c7a97f192d93a719ddaad4a7378408ce2dd01d531fe750896368c8399780327ade3362bff4539b08b1fd6c4a13da1a4d472528
6
+ metadata.gz: b548cfd9713d4f0bfebb5ef137669ea74bc81bcf963f0bdf4b1492b064dac30f429622d025830c42b921ebe26594d1df2210b682482ce36dec510f61e69e190f
7
+ data.tar.gz: 80baaeaac8744d89017de61106bb0efa32f0d6bcdd817a95d0dcac35454695e49b25d3ff2d7e04e44827ca08904971c2ef0e3d45b42c0c7a6b70c060c8055346
data/TODO CHANGED
@@ -1,4 +1,35 @@
1
1
  TODO
2
+ o #group method
3
+
4
+ group(query, column: nil)
5
+ group(query) { |record| group_expression }
6
+
7
+ # TODO: Move to ext/pg_conn or include in pg_conn
8
+ module PgConn
9
+ class Connection
10
+ def group(query, column: nil) # FIXME: default nil -> the first field
11
+ r = pg_exec(query)
12
+ begin
13
+ column = (column || r.fname(0)).to_s
14
+ column_index = r.fnumber(column)
15
+ one = (r.nfields == 2)
16
+ rescue ArgumentError
17
+ raise Error, "Can't find column #{column.inspect}"
18
+ end
19
+
20
+ h = {}
21
+ r.each_row { |row|
22
+ column_value = row.delete_at(column_index)
23
+ (h[column_value] ||= []) << (one ? row.first : row)
24
+ }
25
+ h
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+
32
+ o Use enumerators
2
33
  o Use SQL parameters. Optionally with a different syntax:
3
34
  $var - Value that gets single-quoted
4
35
  @var - Identifier that gets double-quoted (@ for "attribute")
@@ -30,8 +30,8 @@ module PgConn
30
30
  end
31
31
 
32
32
  # Drop a database
33
- def drop(database)
34
- conn.execute "drop database if exists \"#{database}\""
33
+ def drop(database, force: false)
34
+ conn.execute "drop database if exists \"#{database}\"#{force ? ' with force' : ''}"
35
35
  true
36
36
  end
37
37
 
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -392,7 +392,7 @@ module PgConn
392
392
 
393
393
  # Return a hash from the record id column to an OpenStruct representation
394
394
  # of the record. If the :key_column option is defined it will be used
395
- # instead of id as the key It is an error if the id field value is not
395
+ # instead of id as the key. It is an error if the id field value is not
396
396
  # unique
397
397
  def set(query, key_column: :id)
398
398
  key_column = key_column.to_sym
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.5.1
4
+ version: 0.6.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: 2022-07-20 00:00:00.000000000 Z
11
+ date: 2024-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg