db-postgres 0.1.1 → 0.1.2

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: 61a45c4212bcf4b8c3fdf1a244292581da1a1df513450d51fcd322ea625ccd94
4
- data.tar.gz: 18310b502a0cae91906948fa5ce8c5c07c07e81590612e902588abba7fdd37e1
3
+ metadata.gz: c30d669b19ff5cf7b41eb45ff896363060472f2de9231c0c3a25236f23560c82
4
+ data.tar.gz: a3026d300addc7817bf9dbae7124f1c04140a77d8d9a6bd8854ed3741ae7af53
5
5
  SHA512:
6
- metadata.gz: '039afaa56fac564fbb12e66d164ab0d0700eeb6c22d6bcbb7a56ecbd209da1b065ab16c28c5b14cac513ff0af15d7ece1f549cf4fe055db62e8f742fac4406a2'
7
- data.tar.gz: 94e9caed1d36af0a15b9efb71f96a1c151c171fe062bdd789e23c0eab023a2aadd759dbbda996809d93de7fa32323e4fdc67fa52592b7a4e6a1eb784033234bb
6
+ metadata.gz: 7b0314e22e03bb2579ead32274df8015064d9799f751e02f38e5b9aee1160c92eb20ba490f502a0e39672934d7099a2445584f19cda5c42f08524648c1bda799
7
+ data.tar.gz: b951e9c36caed76f39f98342cae5eda8383c658eba45d2cab17cfe8aa0a0b6a73a7bbb7d3475746514b09229e68696d4690b475b89e7035d6eb662045a6e7613
@@ -76,31 +76,33 @@ module DB
76
76
  return buffer
77
77
  end
78
78
 
79
+ def id_column(name = 'id', primary_key: true)
80
+ buffer = String.new
81
+
82
+ append_identifier(name, buffer)
83
+
84
+ buffer << " BIGSERIAL"
85
+
86
+ if primary_key
87
+ buffer << " PRIMARY KEY"
88
+ end
89
+
90
+ return buffer
91
+ end
92
+
79
93
  def status
80
94
  @native.status
81
95
  end
82
96
 
83
97
  def send_query(statement)
98
+ @native.discard_results
99
+
84
100
  @native.send_query(statement)
85
101
  end
86
102
 
87
103
  def next_result
88
104
  @native.next_result
89
105
  end
90
-
91
- def call(statement, streaming: false)
92
- @native.send_query(statement)
93
-
94
- @native.single_row_mode! if streaming
95
-
96
- last_result = nil
97
-
98
- while result = @native.next_result
99
- last_result = result
100
- end
101
-
102
- return last_result
103
- end
104
106
  end
105
107
  end
106
108
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module DB
24
+ module Postgres
25
+ class Error < StandardError
26
+ end
27
+ end
28
+ end
@@ -20,6 +20,7 @@
20
20
 
21
21
  require_relative 'result'
22
22
  require_relative 'field'
23
+ require_relative '../error'
23
24
 
24
25
  module DB
25
26
  module Postgres
@@ -196,6 +197,16 @@ module DB
196
197
 
197
198
  def next_result(types: @types)
198
199
  if result = self.get_result
200
+ status = Native.result_status(result)
201
+
202
+ if status == :fatal_error
203
+ message = Native.result_error_message(result)
204
+
205
+ Native.clear(result)
206
+
207
+ raise Error, "Could not get next result: #{message}"
208
+ end
209
+
199
210
  return Result.new(self, types, result)
200
211
  end
201
212
  end
@@ -208,7 +219,7 @@ module DB
208
219
 
209
220
  case status
210
221
  when :copy_in
211
- self.put_copy_end("discard results")
222
+ self.put_copy_end("Discard results")
212
223
  when :copy_out
213
224
  self.flush_copy_out
214
225
  end
@@ -244,7 +255,7 @@ module DB
244
255
 
245
256
  if status == -1
246
257
  message = Native.error_message(self)
247
- raise Error.new(message)
258
+ raise Error, message
248
259
  elsif status == 0
249
260
  @io.wait_writable
250
261
  else
@@ -261,7 +272,7 @@ module DB
261
272
 
262
273
  if status == -2
263
274
  message = Native.error_message(self)
264
- raise Error.new(message)
275
+ raise Error, message
265
276
  elsif status == -1
266
277
  break
267
278
  elsif status == 0
@@ -289,7 +300,7 @@ module DB
289
300
  def check!(result)
290
301
  if result == 0
291
302
  message = Native.error_message(self)
292
- raise Error.new(message)
303
+ raise Error, message
293
304
  end
294
305
  end
295
306
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module DB
22
22
  module Postgres
23
- VERSION = "0.1.1"
23
+ VERSION = "0.1.2"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -117,6 +117,7 @@ files:
117
117
  - lib/db/postgres.rb
118
118
  - lib/db/postgres/adapter.rb
119
119
  - lib/db/postgres/connection.rb
120
+ - lib/db/postgres/error.rb
120
121
  - lib/db/postgres/native.rb
121
122
  - lib/db/postgres/native/connection.rb
122
123
  - lib/db/postgres/native/field.rb