db-postgres 0.5.1 → 0.7.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
- checksums.yaml.gz.sig +0 -0
- data/lib/db/postgres/connection.rb +10 -1
- data/lib/db/postgres/native/connection.rb +3 -1
- data/lib/db/postgres/native/field.rb +44 -16
- data/lib/db/postgres/native/result.rb +20 -2
- data/lib/db/postgres/native/types.rb +87 -21
- data/lib/db/postgres/native.rb +1 -1
- data/lib/db/postgres/version.rb +1 -1
- data.tar.gz.sig +2 -0
- metadata +46 -19
- metadata.gz.sig +0 -0
- data/lib/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ba17d708434471a3146cf704a5df1f64109ee8d914f73e7fbd07bcee83a04d0
|
4
|
+
data.tar.gz: 896c9c7c8850266ec0ec93a2f3ccbf35a70edd1bf88d6e9f15b67702338d6f66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18d4937f8998c303c2816a9a7fc990e0b9af87fc44a25f448a48f20f509fdf6738a697eeca81df043109ebc753585565c0d67c822b350350fa69b3db9248fb82
|
7
|
+
data.tar.gz: cd4a0d9ea49bbee151193bc512765631c47ea99d97ae495f96d0dd91d709b216fe70840038ec410f538aeaafc3029ba63bd9df0025193dcc2622658b4bcf569d
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -36,11 +36,18 @@ module DB
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def close
|
39
|
-
@native
|
39
|
+
if @native
|
40
|
+
@native&.close
|
41
|
+
@native = nil
|
42
|
+
end
|
40
43
|
|
41
44
|
super
|
42
45
|
end
|
43
46
|
|
47
|
+
def types
|
48
|
+
@native.types
|
49
|
+
end
|
50
|
+
|
44
51
|
def append_string(value, buffer = String.new)
|
45
52
|
buffer << @native.escape_literal(value)
|
46
53
|
|
@@ -49,6 +56,8 @@ module DB
|
|
49
56
|
|
50
57
|
def append_literal(value, buffer = String.new)
|
51
58
|
case value
|
59
|
+
when Time, DateTime, Date
|
60
|
+
append_string(value.iso8601, buffer)
|
52
61
|
when Numeric
|
53
62
|
buffer << value.to_s
|
54
63
|
when TrueClass
|
@@ -149,6 +149,8 @@ module DB
|
|
149
149
|
@types = types
|
150
150
|
end
|
151
151
|
|
152
|
+
attr :types
|
153
|
+
|
152
154
|
# Return the status of the connection.
|
153
155
|
def status
|
154
156
|
Native.status(self)
|
@@ -214,7 +216,7 @@ module DB
|
|
214
216
|
|
215
217
|
Native.clear(result)
|
216
218
|
|
217
|
-
raise Error,
|
219
|
+
raise Error, message
|
218
220
|
end
|
219
221
|
|
220
222
|
return Result.new(self, types, result)
|
@@ -20,32 +20,60 @@
|
|
20
20
|
|
21
21
|
require_relative 'types'
|
22
22
|
|
23
|
-
require 'json'
|
24
|
-
require 'time'
|
25
|
-
|
26
23
|
module DB
|
27
24
|
module Postgres
|
28
25
|
module Native
|
29
|
-
# These are hard coded OIDs.
|
30
26
|
DEFAULT_TYPES = {
|
31
|
-
|
27
|
+
# Pseudo types:
|
28
|
+
primary_key: Types::Integer.new('BIGSERIAL PRIMARY KEY'),
|
29
|
+
foreign_key: Types::Integer.new('BIGINT'),
|
30
|
+
text: Types::Text.new("TEXT"),
|
31
|
+
string: Types::Text.new("VARCHAR(255)"),
|
32
|
+
|
33
|
+
# Symbolic types:
|
34
|
+
decimal: Types::Decimal.new,
|
35
|
+
boolean: Types::Boolean.new,
|
36
|
+
|
37
|
+
smallint: Types::Integer.new("SMALLINT"),
|
38
|
+
integer: Types::Integer.new("INTEGER"),
|
39
|
+
bigint: Types::Integer.new("BIGINT"),
|
40
|
+
|
41
|
+
float: Types::Float.new,
|
42
|
+
double: Types::Float.new("DOUBLE"),
|
43
|
+
|
44
|
+
timestamp: Types::DateTime.new("TIMESTAMP"),
|
45
|
+
date: Types::Date.new,
|
46
|
+
datetime: Types::DateTime.new("DATETIME"),
|
47
|
+
year: Types::Integer.new("LONG"),
|
48
|
+
|
49
|
+
json: Types::JSON.new,
|
50
|
+
enum: Types::Symbol.new,
|
51
|
+
|
52
|
+
# Native types:
|
53
|
+
# This data is extracted by hand from:
|
54
|
+
# <https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat>.
|
55
|
+
# These are hard coded OIDs.
|
56
|
+
16 => Types::Boolean.new,
|
57
|
+
|
58
|
+
20 => Types::Integer.new("int8"),
|
59
|
+
21 => Types::Integer.new("int2"),
|
60
|
+
23 => Types::Integer.new("int4"),
|
32
61
|
|
33
|
-
|
34
|
-
21 => Types::Integer,
|
35
|
-
23 => Types::Integer,
|
62
|
+
114 => Types::JSON.new,
|
36
63
|
|
37
|
-
|
64
|
+
700 => Types::Float.new('float4'),
|
65
|
+
701 => Types::Float.new('float8'),
|
38
66
|
|
39
|
-
|
40
|
-
|
67
|
+
1082 => Types::Date.new,
|
68
|
+
1083 => Types::DateTime.new("TIME"),
|
41
69
|
|
42
|
-
|
43
|
-
|
44
|
-
1114 => Types::DateTime,
|
70
|
+
1114 => Types::DateTime.new("TIMESTAMP"),
|
71
|
+
1184 => Types::DateTime.new("TIMESTAMPTZ"),
|
45
72
|
|
46
|
-
1700 => Types::Decimal,
|
73
|
+
1700 => Types::Decimal.new,
|
47
74
|
|
48
|
-
|
75
|
+
# Not sure if this is ever used?
|
76
|
+
3500 => Types::Symbol.new,
|
49
77
|
}
|
50
78
|
end
|
51
79
|
end
|
@@ -54,8 +54,6 @@ module DB
|
|
54
54
|
ffi_attach_function :PQfreemem, [:pointer], :void, as: :free_memory
|
55
55
|
|
56
56
|
class Result < FFI::Pointer
|
57
|
-
include Enumerable
|
58
|
-
|
59
57
|
def initialize(connection, types = {}, address)
|
60
58
|
super(address)
|
61
59
|
|
@@ -101,6 +99,26 @@ module DB
|
|
101
99
|
Native.clear(self)
|
102
100
|
end
|
103
101
|
|
102
|
+
def map(&block)
|
103
|
+
results = []
|
104
|
+
|
105
|
+
self.each do |row|
|
106
|
+
results << yield(row)
|
107
|
+
end
|
108
|
+
|
109
|
+
return results
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_a
|
113
|
+
rows = []
|
114
|
+
|
115
|
+
self.each do |row|
|
116
|
+
rows << row
|
117
|
+
end
|
118
|
+
|
119
|
+
return rows
|
120
|
+
end
|
121
|
+
|
104
122
|
protected
|
105
123
|
|
106
124
|
def get_value(row, field)
|
@@ -18,8 +18,6 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require 'ffi'
|
22
|
-
|
23
21
|
require 'json'
|
24
22
|
require 'bigdecimal'
|
25
23
|
|
@@ -27,41 +25,109 @@ module DB
|
|
27
25
|
module Postgres
|
28
26
|
module Native
|
29
27
|
module Types
|
30
|
-
|
31
|
-
def
|
28
|
+
class Text
|
29
|
+
def initialize(name = "TEXT")
|
30
|
+
@name = name
|
31
|
+
end
|
32
|
+
|
33
|
+
attr :name
|
34
|
+
|
35
|
+
def parse(string)
|
36
|
+
string
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Integer
|
41
|
+
def initialize(name = "INTEGER")
|
42
|
+
@name = name
|
43
|
+
end
|
44
|
+
|
45
|
+
attr :name
|
46
|
+
|
47
|
+
def parse(string)
|
48
|
+
Integer(string) if string
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Boolean
|
53
|
+
def name
|
54
|
+
"BOOLEAN"
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse(string)
|
32
58
|
string == 't'
|
33
59
|
end
|
34
60
|
end
|
35
61
|
|
36
|
-
|
37
|
-
def
|
38
|
-
|
62
|
+
class Decimal
|
63
|
+
def name
|
64
|
+
"DECIMAL"
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse(string)
|
68
|
+
BigDecimal(string) if string
|
39
69
|
end
|
40
70
|
end
|
41
71
|
|
42
|
-
|
43
|
-
def
|
44
|
-
|
72
|
+
class Float
|
73
|
+
def initialize(name = "FLOAT")
|
74
|
+
@name = name
|
75
|
+
end
|
76
|
+
|
77
|
+
attr :name
|
78
|
+
|
79
|
+
def parse(string)
|
80
|
+
Float(string) if string
|
45
81
|
end
|
46
82
|
end
|
47
83
|
|
48
|
-
|
49
|
-
def
|
50
|
-
|
84
|
+
class Symbol
|
85
|
+
def name
|
86
|
+
"ENUM"
|
87
|
+
end
|
88
|
+
|
89
|
+
def parse(string)
|
90
|
+
string&.to_sym
|
51
91
|
end
|
52
92
|
end
|
53
93
|
|
54
|
-
|
55
|
-
def
|
56
|
-
|
94
|
+
class DateTime
|
95
|
+
def initialize(name = "TIMESTAMP")
|
96
|
+
@name = name
|
97
|
+
end
|
98
|
+
|
99
|
+
attr :name
|
100
|
+
|
101
|
+
def parse(string)
|
102
|
+
if string
|
103
|
+
parts = string.split(/[\-\s:]/)
|
104
|
+
|
105
|
+
return Time.utc(*parts)
|
106
|
+
end
|
57
107
|
end
|
58
108
|
end
|
59
109
|
|
60
|
-
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
110
|
+
class Date
|
111
|
+
def name
|
112
|
+
"DATE"
|
113
|
+
end
|
114
|
+
|
115
|
+
def parse(string)
|
116
|
+
if string
|
117
|
+
parts = string.split(/[\-\s:]/)
|
118
|
+
|
119
|
+
return Time.utc(*parts)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class JSON
|
125
|
+
def name
|
126
|
+
"JSON"
|
127
|
+
end
|
128
|
+
|
129
|
+
def parse(string)
|
130
|
+
::JSON.parse(string, symbolize_names: true) if string
|
65
131
|
end
|
66
132
|
end
|
67
133
|
end
|
data/lib/db/postgres/native.rb
CHANGED
data/lib/db/postgres/version.rb
CHANGED
data.tar.gz.sig
ADDED
metadata
CHANGED
@@ -1,31 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
|
14
|
+
ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
|
15
|
+
MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
|
16
|
+
aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
|
17
|
+
AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
|
18
|
+
xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
|
19
|
+
eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
|
20
|
+
L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
|
21
|
+
9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
|
22
|
+
E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
|
23
|
+
rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2XqNC6tnAj
|
24
|
+
w+XmCywiTQrFzMMAvcA7rPI4F0nU1rZId51rOvvfxaONp+wgTi4P8owZLw0/j0m4
|
25
|
+
8C20DYi6EYx4AHDXiLpElWh3AgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8E
|
26
|
+
BAMCBLAwHQYDVR0OBBYEFB6ZaeWKxQjGTI+pmz7cKRmMIywwMC4GA1UdEQQnMCWB
|
27
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWB
|
28
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEB
|
29
|
+
CwUAA4IBgQBVoM+pu3dpdUhZM1w051iw5GfiqclAr1Psypf16Tiod/ho//4oAu6T
|
30
|
+
9fj3DPX/acWV9P/FScvqo4Qgv6g4VWO5ZU7z2JmPoTXZtYMunRAmQPFL/gSUc6aK
|
31
|
+
vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
|
32
|
+
x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
|
33
|
+
bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
|
34
|
+
Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
|
35
|
+
y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
|
36
|
+
RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
|
37
|
+
HiLJ8VOFx6w=
|
38
|
+
-----END CERTIFICATE-----
|
39
|
+
date: 2021-10-04 00:00:00.000000000 Z
|
12
40
|
dependencies:
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
42
|
+
name: async-io
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
|
-
- - "
|
45
|
+
- - ">="
|
18
46
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
47
|
+
version: '0'
|
20
48
|
type: :runtime
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- - "
|
52
|
+
- - ">="
|
25
53
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: async-
|
56
|
+
name: async-pool
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - ">="
|
@@ -39,19 +67,19 @@ dependencies:
|
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
70
|
+
name: ffi-module
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- - "
|
73
|
+
- - "~>"
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
75
|
+
version: 0.3.0
|
48
76
|
type: :runtime
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - "
|
80
|
+
- - "~>"
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: 0.3.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: async-rspec
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +109,7 @@ dependencies:
|
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: bundler
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
@@ -95,7 +123,7 @@ dependencies:
|
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: covered
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - ">="
|
@@ -128,7 +156,6 @@ executables: []
|
|
128
156
|
extensions: []
|
129
157
|
extra_rdoc_files: []
|
130
158
|
files:
|
131
|
-
- lib/.DS_Store
|
132
159
|
- lib/db/postgres.rb
|
133
160
|
- lib/db/postgres/adapter.rb
|
134
161
|
- lib/db/postgres/connection.rb
|
@@ -139,7 +166,7 @@ files:
|
|
139
166
|
- lib/db/postgres/native/result.rb
|
140
167
|
- lib/db/postgres/native/types.rb
|
141
168
|
- lib/db/postgres/version.rb
|
142
|
-
homepage:
|
169
|
+
homepage: https://github.com/socketry/db-postgres
|
143
170
|
licenses:
|
144
171
|
- MIT
|
145
172
|
metadata: {}
|
@@ -158,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
185
|
- !ruby/object:Gem::Version
|
159
186
|
version: '0'
|
160
187
|
requirements: []
|
161
|
-
rubygems_version: 3.2.
|
188
|
+
rubygems_version: 3.2.22
|
162
189
|
signing_key:
|
163
190
|
specification_version: 4
|
164
191
|
summary: Ruby FFI bindings for libpq C interface.
|
metadata.gz.sig
ADDED
Binary file
|
data/lib/.DS_Store
DELETED
Binary file
|