db-postgres 0.6.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f6e34604ab35a726644bb1783228a2d60f01f76b0d431110ae20c5974ec3fcb
4
- data.tar.gz: e879e050b47d3975a29bc6b67e59b5837ad8b8cf067d96554eaf951a8d04198a
3
+ metadata.gz: 2ba17d708434471a3146cf704a5df1f64109ee8d914f73e7fbd07bcee83a04d0
4
+ data.tar.gz: 896c9c7c8850266ec0ec93a2f3ccbf35a70edd1bf88d6e9f15b67702338d6f66
5
5
  SHA512:
6
- metadata.gz: 7f4842d9d1c6c3e70029b9a4df1fd4e27a2a10bb4920465dddb1f25616b01ef50c67029d1666c218af68521bb9803cba5bc9b9f478e0c409c7c376e31466af92
7
- data.tar.gz: d9a04d2d4a541f44bc51493cb0509c0a2a0ad8e39a24e0803fa2e61532ab85cbbbe3c48045c01d60c76b9be88b464797626d966bfbe884dcdd2736c03ba7ee4e
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.close
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)
@@ -23,26 +23,57 @@ require_relative 'types'
23
23
  module DB
24
24
  module Postgres
25
25
  module Native
26
- # These are hard coded OIDs.
27
26
  DEFAULT_TYPES = {
28
- 16 => Types::Boolean,
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)"),
29
32
 
30
- 20 => Types::Integer,
31
- 21 => Types::Integer,
32
- 23 => Types::Integer,
33
+ # Symbolic types:
34
+ decimal: Types::Decimal.new,
35
+ boolean: Types::Boolean.new,
33
36
 
34
- 114 => Types::JSON,
37
+ smallint: Types::Integer.new("SMALLINT"),
38
+ integer: Types::Integer.new("INTEGER"),
39
+ bigint: Types::Integer.new("BIGINT"),
35
40
 
36
- 700 => Types::Float,
37
- 701 => Types::Float,
41
+ float: Types::Float.new,
42
+ double: Types::Float.new("DOUBLE"),
38
43
 
39
- 1082 => Date,
40
- 1083 => Types::DateTime,
41
- 1114 => Types::DateTime,
44
+ timestamp: Types::DateTime.new("TIMESTAMP"),
45
+ date: Types::Date.new,
46
+ datetime: Types::DateTime.new("DATETIME"),
47
+ year: Types::Integer.new("LONG"),
42
48
 
43
- 1700 => Types::Decimal,
49
+ json: Types::JSON.new,
50
+ enum: Types::Symbol.new,
44
51
 
45
- 3500 => Types::Symbol,
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"),
61
+
62
+ 114 => Types::JSON.new,
63
+
64
+ 700 => Types::Float.new('float4'),
65
+ 701 => Types::Float.new('float8'),
66
+
67
+ 1082 => Types::Date.new,
68
+ 1083 => Types::DateTime.new("TIME"),
69
+
70
+ 1114 => Types::DateTime.new("TIMESTAMP"),
71
+ 1184 => Types::DateTime.new("TIMESTAMPTZ"),
72
+
73
+ 1700 => Types::Decimal.new,
74
+
75
+ # Not sure if this is ever used?
76
+ 3500 => Types::Symbol.new,
46
77
  }
47
78
  end
48
79
  end
@@ -18,58 +18,115 @@
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
- require 'time'
26
23
 
27
24
  module DB
28
25
  module Postgres
29
26
  module Native
30
27
  module Types
31
- module Boolean
32
- def self.parse(string)
33
- string == 't'
28
+ class Text
29
+ def initialize(name = "TEXT")
30
+ @name = name
31
+ end
32
+
33
+ attr :name
34
+
35
+ def parse(string)
36
+ string
34
37
  end
35
38
  end
36
39
 
37
- module Integer
38
- def self.parse(string)
40
+ class Integer
41
+ def initialize(name = "INTEGER")
42
+ @name = name
43
+ end
44
+
45
+ attr :name
46
+
47
+ def parse(string)
39
48
  Integer(string) if string
40
49
  end
41
50
  end
42
51
 
43
- module Decimal
44
- def self.parse(string)
52
+ class Boolean
53
+ def name
54
+ "BOOLEAN"
55
+ end
56
+
57
+ def parse(string)
58
+ string == 't'
59
+ end
60
+ end
61
+
62
+ class Decimal
63
+ def name
64
+ "DECIMAL"
65
+ end
66
+
67
+ def parse(string)
45
68
  BigDecimal(string) if string
46
69
  end
47
70
  end
48
71
 
49
- module Float
50
- def self.parse(string)
72
+ class Float
73
+ def initialize(name = "FLOAT")
74
+ @name = name
75
+ end
76
+
77
+ attr :name
78
+
79
+ def parse(string)
51
80
  Float(string) if string
52
81
  end
53
82
  end
54
83
 
55
- module Symbol
56
- def self.parse(string)
84
+ class Symbol
85
+ def name
86
+ "ENUM"
87
+ end
88
+
89
+ def parse(string)
57
90
  string&.to_sym
58
91
  end
59
92
  end
60
93
 
61
- module DateTime
62
- def self.parse(string)
94
+ class DateTime
95
+ def initialize(name = "TIMESTAMP")
96
+ @name = name
97
+ end
98
+
99
+ attr :name
100
+
101
+ def parse(string)
63
102
  if string
64
- parts = string.split(/[\-\s:\.]/)
103
+ parts = string.split(/[\-\s:]/)
65
104
 
66
105
  return Time.utc(*parts)
67
106
  end
68
107
  end
69
108
  end
70
109
 
71
- module JSON
72
- def self.parse(string)
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)
73
130
  ::JSON.parse(string, symbolize_names: true) if string
74
131
  end
75
132
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module DB
22
22
  module Postgres
23
- VERSION = "0.6.0"
23
+ VERSION = "0.7.0"
24
24
  end
25
25
  end
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ _��F�b��(�zM��Zs�ƙ��.UV�"��ث*rS>���VB�ٻ��b2u0�
2
+ p��W�6�kFF���A�
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.6.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
- date: 2021-05-23 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQs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A4IBgQBVoM+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: ffi-module
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.3.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.3.0
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: async-io
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: async-pool
70
+ name: ffi-module
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - ">="
73
+ - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '0'
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: '0'
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: covered
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: bundler
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.3
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