db-postgres 0.2.1 → 0.4.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
- data/lib/.DS_Store +0 -0
- data/lib/db/postgres/connection.rb +16 -3
- data/lib/db/postgres/native/connection.rb +19 -15
- data/lib/db/postgres/native/result.rb +7 -11
- 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: 7d9080559ec253dbc5e79e48cba81f8dec73e6bb9abd2f2cd5ae0cdeaf882b97
|
4
|
+
data.tar.gz: 8011d89fb8b19abbd805ca0068986da5763e189a7a0b046920e7d408cabdfa60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e6e16336a47e226dcc2adaa548abd522a44af09dfe0751d09806fa991fed224dd254a34a39e2f8318da843a82936d988b27c854a2382b38f18a3e2b801c943d
|
7
|
+
data.tar.gz: 183c5724efcc8025409d2e6856c3934a154aa10c59b568a9e20d8ae90769fd1595b584b9a6fe5b0c8cb72759e3068f0296327a36eb7904a01590ca186d52d07c
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -65,20 +65,33 @@ module DB
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def append_identifier(value, buffer = String.new)
|
68
|
-
|
68
|
+
case value
|
69
|
+
when Array
|
70
|
+
first = true
|
71
|
+
value.each do |part|
|
72
|
+
buffer << '.' unless first
|
73
|
+
first = false
|
74
|
+
|
75
|
+
buffer << @native.escape_identifier(part)
|
76
|
+
end
|
77
|
+
else
|
78
|
+
buffer << @native.escape_identifier(value)
|
79
|
+
end
|
69
80
|
|
70
81
|
return buffer
|
71
82
|
end
|
72
83
|
|
73
|
-
def
|
84
|
+
def key_column(name = 'id', primary: true, null: false)
|
74
85
|
buffer = String.new
|
75
86
|
|
76
87
|
append_identifier(name, buffer)
|
77
88
|
|
78
89
|
buffer << " BIGSERIAL"
|
79
90
|
|
80
|
-
if
|
91
|
+
if primary
|
81
92
|
buffer << " PRIMARY KEY"
|
93
|
+
elsif !null
|
94
|
+
buffer << " NOT NULL"
|
82
95
|
end
|
83
96
|
|
84
97
|
return buffer
|
@@ -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
|
@@ -104,15 +104,21 @@ module DB
|
|
104
104
|
|
105
105
|
class Connection < FFI::Pointer
|
106
106
|
def self.connect(wrapper: IO, types: DEFAULT_TYPES, **options)
|
107
|
-
#
|
107
|
+
# Postgres expects "dbname" as the key name:
|
108
108
|
if database = options.delete(:database)
|
109
109
|
options[:dbname] = database
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
# Postgres expects "user" as the key name:
|
113
|
+
if username = options.delete(:username)
|
114
|
+
options[:user] = username
|
115
|
+
end
|
116
|
+
|
117
|
+
keys = Strings.new(options.keys)
|
118
|
+
values = Strings.new(options.values)
|
114
119
|
|
115
|
-
pointer = Native.connect_start_params(keys, values, 0)
|
120
|
+
pointer = Native.connect_start_params(keys.array, values.array, 0)
|
121
|
+
Native.set_nonblocking(pointer, 1)
|
116
122
|
|
117
123
|
io = wrapper.new(Native.socket(pointer), "r+")
|
118
124
|
|
@@ -130,11 +136,9 @@ module DB
|
|
130
136
|
|
131
137
|
Native.finish(pointer)
|
132
138
|
|
133
|
-
raise "connect: #{error_message}"
|
139
|
+
raise Error, "Could not connect: #{error_message}"
|
134
140
|
end
|
135
141
|
|
136
|
-
Native.set_nonblocking(pointer, 1)
|
137
|
-
|
138
142
|
return self.new(pointer, io, types)
|
139
143
|
end
|
140
144
|
|
@@ -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
|
|
@@ -52,6 +54,8 @@ module DB
|
|
52
54
|
attach_function :free_memory, :PQfreemem, [:pointer], :void
|
53
55
|
|
54
56
|
class Result < FFI::Pointer
|
57
|
+
include Enumerable
|
58
|
+
|
55
59
|
def initialize(connection, types = {}, address)
|
56
60
|
super(address)
|
57
61
|
|
@@ -97,19 +101,11 @@ module DB
|
|
97
101
|
Native.clear(self)
|
98
102
|
end
|
99
103
|
|
100
|
-
def to_a
|
101
|
-
rows = []
|
102
|
-
|
103
|
-
self.each do |row|
|
104
|
-
rows << row
|
105
|
-
end
|
106
|
-
|
107
|
-
return rows
|
108
|
-
end
|
109
|
-
|
110
104
|
protected
|
111
105
|
def get_value(row, field)
|
112
|
-
Native.
|
106
|
+
if Native.get_is_null(self, row, field) == 0
|
107
|
+
Native.get_value(self, row, field)
|
108
|
+
end
|
113
109
|
end
|
114
110
|
|
115
111
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-01 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.2.3
|
147
162
|
signing_key:
|
148
163
|
specification_version: 4
|
149
164
|
summary: Ruby FFI bindings for libpq C interface.
|