db-postgres 0.1.3 → 0.2.4
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
- data/lib/.DS_Store +0 -0
- data/lib/db/postgres/connection.rb +0 -6
- data/lib/db/postgres/native/connection.rb +21 -16
- data/lib/db/postgres/native/result.rb +5 -1
- data/lib/db/postgres/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9914774aac9e6cf060fdba11e1ce395b7311ee55c514b3720a94b8252aaf82f6
|
4
|
+
data.tar.gz: fa42571a59bc7c9f12103359a4e396607536a6542a5ab37bd6a736b882450792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9766e98f2f42277a5ffe6df30777f8f328f8d12146cce6dddfcc0e9f50a8c1359e4b2d4766377775eb996046219e188b14e7f728609da7544d338363dacc478f
|
7
|
+
data.tar.gz: d0a9718c070dede2a6aa61e060518c8a43d0448345a0e0c79a20ff1486f89a303cd0ef120ac9137ab13575044b3811574904056c3342ce0073ab6b532ea3754f
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -27,12 +27,6 @@ require_relative 'native/connection'
|
|
27
27
|
|
28
28
|
module DB
|
29
29
|
module Postgres
|
30
|
-
module IO
|
31
|
-
def self.new(fd, mode)
|
32
|
-
Async::IO::Generic.new(::IO.new(fd, mode, autoclose: false))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
30
|
# This implements the interface between the underlying
|
37
31
|
class Connection < Async::Pool::Resource
|
38
32
|
def initialize(**options)
|
@@ -25,16 +25,16 @@ require_relative '../error'
|
|
25
25
|
module DB
|
26
26
|
module Postgres
|
27
27
|
module Native
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
class Strings
|
29
|
+
def initialize(values)
|
30
|
+
@array = FFI::MemoryPointer.new(:pointer, values.size + 1)
|
31
|
+
@pointers = values.map do |value|
|
32
|
+
FFI::MemoryPointer.from_string(value.to_s)
|
33
|
+
end
|
34
|
+
@array.write_array_of_pointer(@pointers)
|
33
35
|
end
|
34
36
|
|
35
|
-
array
|
36
|
-
|
37
|
-
return array
|
37
|
+
attr :array
|
38
38
|
end
|
39
39
|
|
40
40
|
attach_function :connect_start_params, :PQconnectStartParams, [:pointer, :pointer, :int], :pointer
|
@@ -96,19 +96,26 @@ module DB
|
|
96
96
|
attach_function :escape_literal, :PQescapeLiteral, [:pointer, :string, :size_t], :pointer
|
97
97
|
attach_function :escape_identifier, :PQescapeIdentifier, [:pointer, :string, :size_t], :pointer
|
98
98
|
|
99
|
+
module IO
|
100
|
+
def self.new(fd, mode)
|
101
|
+
Async::IO::Generic.new(::IO.new(fd, mode, autoclose: false))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
99
105
|
class Connection < FFI::Pointer
|
100
|
-
def self.connect(
|
106
|
+
def self.connect(wrapper: IO, types: DEFAULT_TYPES, **options)
|
101
107
|
# Prefer 'database' key for 'dbname' parameter:
|
102
108
|
if database = options.delete(:database)
|
103
109
|
options[:dbname] = database
|
104
110
|
end
|
105
111
|
|
106
|
-
keys =
|
107
|
-
values =
|
112
|
+
keys = Strings.new(options.keys)
|
113
|
+
values = Strings.new(options.values)
|
108
114
|
|
109
|
-
pointer = Native.connect_start_params(keys, values, 0)
|
115
|
+
pointer = Native.connect_start_params(keys.array, values.array, 0)
|
116
|
+
Native.set_nonblocking(pointer, 1)
|
110
117
|
|
111
|
-
io =
|
118
|
+
io = wrapper.new(Native.socket(pointer), "r+")
|
112
119
|
|
113
120
|
while status = Native.connect_poll(pointer)
|
114
121
|
break if status == :ok || status == :failed
|
@@ -124,11 +131,9 @@ module DB
|
|
124
131
|
|
125
132
|
Native.finish(pointer)
|
126
133
|
|
127
|
-
raise "connect: #{error_message}"
|
134
|
+
raise Error, "Could not connect: #{error_message}"
|
128
135
|
end
|
129
136
|
|
130
|
-
Native.set_nonblocking(pointer, 1)
|
131
|
-
|
132
137
|
return self.new(pointer, io, types)
|
133
138
|
end
|
134
139
|
|
@@ -43,7 +43,9 @@ module DB
|
|
43
43
|
attach_function :field_count, :PQnfields, [:pointer], :int
|
44
44
|
attach_function :field_name, :PQfname, [:pointer, :int], :string
|
45
45
|
attach_function :field_type, :PQftype, [:pointer, :int], :int
|
46
|
+
|
46
47
|
attach_function :get_value, :PQgetvalue, [:pointer, :int, :int], :string
|
48
|
+
attach_function :get_is_null, :PQgetisnull, [:pointer, :int, :int], :int
|
47
49
|
|
48
50
|
attach_function :clear, :PQclear, [:pointer], :void
|
49
51
|
|
@@ -109,7 +111,9 @@ module DB
|
|
109
111
|
|
110
112
|
protected
|
111
113
|
def get_value(row, field)
|
112
|
-
Native.
|
114
|
+
if Native.get_is_null(self, row, field) == 0
|
115
|
+
Native.get_value(self, row, field)
|
116
|
+
end
|
113
117
|
end
|
114
118
|
|
115
119
|
def get_row(row)
|
data/lib/db/postgres/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: async-pool
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: async-rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +128,7 @@ executables: []
|
|
114
128
|
extensions: []
|
115
129
|
extra_rdoc_files: []
|
116
130
|
files:
|
131
|
+
- lib/.DS_Store
|
117
132
|
- lib/db/postgres.rb
|
118
133
|
- lib/db/postgres/adapter.rb
|
119
134
|
- lib/db/postgres/connection.rb
|
@@ -143,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
158
|
- !ruby/object:Gem::Version
|
144
159
|
version: '0'
|
145
160
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
161
|
+
rubygems_version: 3.1.2
|
147
162
|
signing_key:
|
148
163
|
specification_version: 4
|
149
164
|
summary: Ruby FFI bindings for libpq C interface.
|