db 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -0
- data/lib/db/adapters.rb +2 -19
- data/lib/db/client.rb +4 -23
- data/lib/db/context/session.rb +48 -21
- data/lib/db/context/transaction.rb +2 -19
- data/lib/db/context/transient.rb +19 -0
- data/lib/db/query.rb +4 -26
- data/lib/db/records.rb +39 -0
- data/lib/db/version.rb +3 -20
- data/lib/db.rb +2 -19
- data/license.md +21 -0
- data/readme.md +40 -0
- data.tar.gz.sig +0 -0
- metadata +42 -63
- metadata.gz.sig +0 -0
- data/lib/db/context/generic.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00818022e4f4c8f40dae41f5f7850b89021cbcb8165f2a1e4637d07520a2c748'
|
4
|
+
data.tar.gz: 5d4ce254968d4f5187469537f2c1553970ba32e9125bea3a43de40ceb8d3bc40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb6f3c928363fbc5c9a12ebf6bc902636e93202ee3308edf28d4370f40c2c69c5b57d9c64f873e66642bba3afa025bcd1934366011a52040c9f882b931fafc40
|
7
|
+
data.tar.gz: 0d0b154d9817cbc191c9a16203e5088538fe37375af00e060be6ae4c29379c0e03d61933420b15a36ab4efcbe003e1c279b38f0242b25b6afe156a3e10103980
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
I��*�AX�E)C�4MJ
|
2
|
+
ř%��+պ4���FJ�I��5����^F�̅^��i3�hK�E� ��^�������Ф�0��d�'�h*��i`j]f���O&�'�:�]�����s3Z�ȷ9��5-�UV�L�����W �+�����9w�GR�iZ6�?�F)���nX�ݱ�c b]���5R����kR����y�s��a:C�Z�����#w���#���?��? ���sⅡ/c��:�8#v'��iB�I�Y�X����Bϴ�ЁDN��="��xG�:�I�>8K��P�=>�&�u1f� -Z�=i��9S8���b�YYobt��
|
data/lib/db/adapters.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
6
|
module DB
|
24
7
|
# A global map of registered adapters.
|
data/lib/db/client.rb
CHANGED
@@ -1,30 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
|
-
require 'async/io'
|
24
|
-
require 'async/io/stream'
|
25
6
|
require 'async/pool/controller'
|
26
7
|
|
27
|
-
require_relative 'context/
|
8
|
+
require_relative 'context/transient'
|
28
9
|
require_relative 'context/session'
|
29
10
|
require_relative 'context/transaction'
|
30
11
|
|
@@ -50,7 +31,7 @@ module DB
|
|
50
31
|
|
51
32
|
# Acquire a generic context which will acquire a connection on demand.
|
52
33
|
def context(**options)
|
53
|
-
context = Context::
|
34
|
+
context = Context::Transient.new(@pool, **options)
|
54
35
|
|
55
36
|
return context unless block_given?
|
56
37
|
|
data/lib/db/context/session.rb
CHANGED
@@ -1,31 +1,54 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
6
|
require_relative '../query'
|
7
|
+
require_relative '../records'
|
24
8
|
|
25
9
|
module DB
|
26
10
|
module Context
|
27
11
|
# A connected context for sending queries and reading results.
|
28
|
-
class Session
|
12
|
+
class Session
|
13
|
+
# Initialize the query context attached to the given connection pool.
|
14
|
+
def initialize(pool, **options)
|
15
|
+
@pool = pool
|
16
|
+
@connection = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection?
|
20
|
+
@connection != nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# Lazy initialize underlying connection.
|
24
|
+
def connection
|
25
|
+
@connection ||= @pool.acquire
|
26
|
+
end
|
27
|
+
|
28
|
+
# Flush the connection and then return it to the connection pool.
|
29
|
+
def close
|
30
|
+
if @connection
|
31
|
+
@pool.release(@connection)
|
32
|
+
@connection = nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def closed?
|
37
|
+
@connection.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def query(fragment = String.new, **parameters)
|
41
|
+
if parameters.empty?
|
42
|
+
Query.new(self, fragment)
|
43
|
+
else
|
44
|
+
Query.new(self).interpolate(fragment, **parameters)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def clause(fragment = String.new)
|
49
|
+
Query.new(self, fragment)
|
50
|
+
end
|
51
|
+
|
29
52
|
# Send a query to the server.
|
30
53
|
# @parameter statement [String] The SQL query to send.
|
31
54
|
def call(statement, **options)
|
@@ -33,7 +56,11 @@ module DB
|
|
33
56
|
|
34
57
|
connection.send_query(statement, **options)
|
35
58
|
|
36
|
-
|
59
|
+
if block_given?
|
60
|
+
yield connection
|
61
|
+
elsif result = connection.next_result
|
62
|
+
return Records.wrap(result)
|
63
|
+
end
|
37
64
|
end
|
38
65
|
end
|
39
66
|
end
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
6
|
require_relative 'session'
|
24
7
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative 'session'
|
7
|
+
|
8
|
+
module DB
|
9
|
+
module Context
|
10
|
+
# A connected context for sending queries and reading results.
|
11
|
+
class Transient < Session
|
12
|
+
def call(statement, **options, &block)
|
13
|
+
super
|
14
|
+
ensure
|
15
|
+
self.close
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/db/query.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
6
|
module DB
|
24
7
|
# Represents one or more identifiers for databases, tables or columns.
|
@@ -116,13 +99,8 @@ module DB
|
|
116
99
|
# Send the query to the remote server to be executed. See {Context::Session#call} for more details.
|
117
100
|
# @returns [Enumerable] The resulting records.
|
118
101
|
def call(&block)
|
119
|
-
|
120
|
-
|
121
|
-
else
|
122
|
-
@context.call(@buffer) do |connection|
|
123
|
-
return connection.next_result
|
124
|
-
end
|
125
|
-
end
|
102
|
+
# Console.debug(self, "Executing query...", buffer: @buffer)
|
103
|
+
@context.call(@buffer, &block)
|
126
104
|
end
|
127
105
|
|
128
106
|
def to_s
|
data/lib/db/records.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2021-2024, by Samuel Williams.
|
5
|
+
|
6
|
+
module DB
|
7
|
+
# A buffer of records.
|
8
|
+
class Records
|
9
|
+
def self.wrap(result)
|
10
|
+
# We want to avoid extra memory allocations when there are no columns:
|
11
|
+
if result.field_count == 0
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
return self.new(result.field_names, result.to_a)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(columns, rows)
|
19
|
+
@columns = columns
|
20
|
+
@rows = rows
|
21
|
+
end
|
22
|
+
|
23
|
+
def freeze
|
24
|
+
return self if frozen?
|
25
|
+
|
26
|
+
@columns.freeze
|
27
|
+
@rows.freeze
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
attr :columns
|
33
|
+
attr :rows
|
34
|
+
|
35
|
+
def to_a
|
36
|
+
@rows
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/db/version.rb
CHANGED
@@ -1,25 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
6
|
module DB
|
24
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.11.0"
|
25
8
|
end
|
data/lib/db.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
22
5
|
|
23
6
|
require_relative 'db/version'
|
24
7
|
require_relative 'db/adapters'
|
data/license.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright, 2020-2024, by Samuel Williams.
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/readme.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# DB
|
2
|
+
|
3
|
+
Provides event-driven asynchronous drivers for various database adaptors, including [Postgres](https://github.com/socketry/db-postgres) and [MariaDB/MySQL](https://github.com/socketry/db-mariadb).
|
4
|
+
|
5
|
+
[![Development Status](https://github.com/socketry/db/workflows/Test/badge.svg)](https://github.com/socketry/db/actions?workflow=Test)
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
- Event driven I/O for streaming queries and results.
|
10
|
+
- Standard interface for multiple database adapters.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Please see the [project documentation](https://socketry.github.io/db/) for more details.
|
15
|
+
|
16
|
+
- [Getting Started](https://socketry.github.io/db/guides/getting-started/index) - This guide explains how to use `db` for database queries.
|
17
|
+
|
18
|
+
- [Executing Queries](https://socketry.github.io/db/guides/executing-queries/index) - This guide explains how to escape and execute queries.
|
19
|
+
|
20
|
+
- [Example Queries](https://socketry.github.io/db/guides/example-queries/index) - This guide shows a variety of example queries using the DB gem.
|
21
|
+
|
22
|
+
- [Data Types](https://socketry.github.io/db/guides/datatypes/index) - This guide explains about SQL data types, and how they are used by the DB gem.
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
We welcome contributions to this project.
|
27
|
+
|
28
|
+
1. Fork it.
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
32
|
+
5. Create new Pull Request.
|
33
|
+
|
34
|
+
### Developer Certificate of Origin
|
35
|
+
|
36
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
37
|
+
|
38
|
+
### Community Guidelines
|
39
|
+
|
40
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,29 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.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
|
+
MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
|
14
|
+
ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
|
15
|
+
CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
|
16
|
+
MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
|
17
|
+
MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
|
18
|
+
bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
|
19
|
+
igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
|
20
|
+
9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
|
21
|
+
sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
|
22
|
+
e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
|
23
|
+
XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
|
24
|
+
RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
|
25
|
+
tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
|
26
|
+
zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
|
27
|
+
xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
28
|
+
BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
|
29
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
|
30
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
|
31
|
+
cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
|
32
|
+
xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
|
33
|
+
c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
|
34
|
+
8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
|
35
|
+
JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
|
36
|
+
eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
|
37
|
+
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
|
+
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
|
+
-----END CERTIFICATE-----
|
40
|
+
date: 2024-07-27 00:00:00.000000000 Z
|
12
41
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: async-io
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
42
|
- !ruby/object:Gem::Dependency
|
28
43
|
name: async-pool
|
29
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,48 +53,6 @@ dependencies:
|
|
38
53
|
- - ">="
|
39
54
|
- !ruby/object:Gem::Version
|
40
55
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: covered
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.0'
|
83
56
|
description:
|
84
57
|
email:
|
85
58
|
executables: []
|
@@ -89,15 +62,21 @@ files:
|
|
89
62
|
- lib/db.rb
|
90
63
|
- lib/db/adapters.rb
|
91
64
|
- lib/db/client.rb
|
92
|
-
- lib/db/context/generic.rb
|
93
65
|
- lib/db/context/session.rb
|
94
66
|
- lib/db/context/transaction.rb
|
67
|
+
- lib/db/context/transient.rb
|
95
68
|
- lib/db/query.rb
|
69
|
+
- lib/db/records.rb
|
96
70
|
- lib/db/version.rb
|
71
|
+
- license.md
|
72
|
+
- readme.md
|
97
73
|
homepage: https://github.com/socketry/db
|
98
74
|
licenses:
|
99
75
|
- MIT
|
100
|
-
metadata:
|
76
|
+
metadata:
|
77
|
+
documentation_uri: https://socketry.github.io/db/
|
78
|
+
funding_uri: https://github.com/sponsors/ioquatix
|
79
|
+
source_code_uri: https://github.com/socketry/db.git
|
101
80
|
post_install_message:
|
102
81
|
rdoc_options: []
|
103
82
|
require_paths:
|
@@ -106,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
85
|
requirements:
|
107
86
|
- - ">="
|
108
87
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
88
|
+
version: '3.1'
|
110
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
90
|
requirements:
|
112
91
|
- - ">="
|
113
92
|
- !ruby/object:Gem::Version
|
114
93
|
version: '0'
|
115
94
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.5.11
|
117
96
|
signing_key:
|
118
97
|
specification_version: 4
|
119
98
|
summary: A low level database access gem.
|
metadata.gz.sig
ADDED
Binary file
|
data/lib/db/context/generic.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2021, 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
|
-
require_relative '../query'
|
24
|
-
|
25
|
-
module DB
|
26
|
-
module Context
|
27
|
-
# A connected context for sending queries and reading results.
|
28
|
-
class Generic
|
29
|
-
# Iniitalize the query context attached to the given connection pool.
|
30
|
-
def initialize(pool, **options)
|
31
|
-
@pool = pool
|
32
|
-
@connection = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def connection?
|
36
|
-
@connection != nil
|
37
|
-
end
|
38
|
-
|
39
|
-
# Lazy initialize underlying connection.
|
40
|
-
def connection
|
41
|
-
@connection ||= @pool.acquire
|
42
|
-
end
|
43
|
-
|
44
|
-
# Flush the connection and then return it to the connection pool.
|
45
|
-
def close
|
46
|
-
if @connection
|
47
|
-
@pool.release(@connection)
|
48
|
-
@connection = nil
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def closed?
|
53
|
-
@connection.nil?
|
54
|
-
end
|
55
|
-
|
56
|
-
def query(fragment = String.new, **parameters)
|
57
|
-
if parameters.empty?
|
58
|
-
Query.new(self, fragment)
|
59
|
-
else
|
60
|
-
Query.new(self).interpolate(fragment, **parameters)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def clause(fragment = String.new)
|
65
|
-
Query.new(self, fragment)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Send a query to the server.
|
69
|
-
# @parameter statement [String] The SQL query to send.
|
70
|
-
def call(statement, **options)
|
71
|
-
connection.send_query(statement, **options)
|
72
|
-
|
73
|
-
yield connection if block_given?
|
74
|
-
ensure
|
75
|
-
self.close
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|