db 0.0.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2847cf8837c2e4e4115e6bb66e4941e5325d2206cde7cb15a4b815333a277255
4
- data.tar.gz: c04ee3789b067527bdab43fa0fc9c75ff5ed1e7e063e10ac78fb1cccdb577810
3
+ metadata.gz: 6969650d4cd9fde35de4541f64d10b67b78f0e55e42d4f4b6d6daff54022ed62
4
+ data.tar.gz: f97c19216d6ccaa88fc5fb37c71e40c614e4e843c928df37edfb1723d4afbeb5
5
5
  SHA512:
6
- metadata.gz: 518fdf481350ad615c0a76492b593762c2d4aed282b6bed052ccca86d6a75c9dd7198584c87f598b11d852a989b40d9f49a067c4b3368a91ce49e8c1c6ad8c9e
7
- data.tar.gz: 10834ed3f026f7a781afdd60e5a7611dd2d2e55578bdef48675a6f7c2aaaec5c76a5436bc91d219f53d377c8fef5c78e0343ad0360d1e64fc980b84011a3a11b
6
+ metadata.gz: 04fa032c0a0d79283fa5d51fff48ecac9d8dd5d04b1f0e7cfef9b5d279d63f7d1b947185ff8a257b1df0e031cdae7b7b548d75a4bbe6a7d85889764fb1c83e30
7
+ data.tar.gz: e695f898cf1e6b37e130f3addd3d8631a3451f62cba9b49ec52584b018a2d8900ed5ef60c5175a10e654d9b034295e244ffafddfb8ba3be1505b633dc5cd2696
@@ -4,31 +4,62 @@ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  test:
7
+ runs-on: ${{matrix.os}}-latest
8
+ continue-on-error: ${{matrix.experimental}}
9
+
7
10
  strategy:
8
11
  matrix:
9
12
  os:
10
13
  - ubuntu
11
- - macos
12
14
 
13
15
  ruby:
14
- - 2.4
15
16
  - 2.5
16
17
  - 2.6
17
18
  - 2.7
18
19
 
20
+ experimental: [false]
21
+ env: [""]
22
+
19
23
  include:
20
- - os: 'ubuntu'
21
- ruby: '2.6'
22
- env: COVERAGE=PartialSummary,Coveralls
23
-
24
- runs-on: ${{matrix.os}}-latest
24
+ - os: ubuntu
25
+ ruby: truffleruby
26
+ experimental: true
27
+ - os: ubuntu
28
+ ruby: jruby
29
+ experimental: true
30
+ env: JRUBY_OPTS="--debug -X+O"
31
+ - os: ubuntu
32
+ ruby: head
33
+ experimental: true
25
34
 
26
35
  steps:
27
- - uses: actions/checkout@v1
36
+ - uses: actions/checkout@v2
28
37
  - uses: ruby/setup-ruby@v1
29
38
  with:
30
39
  ruby-version: ${{matrix.ruby}}
40
+
31
41
  - name: Install dependencies
32
- run: bundle install
42
+ run: ${{matrix.env}} bundle install
43
+
44
+ - name: Preparing Postgres (ubuntu)
45
+ if: matrix.os == 'ubuntu'
46
+ run: |
47
+ sudo apt-get install postgresql postgresql-contrib
48
+ echo "local all all trust" | sudo tee -a /var/lib/postgresql/12/main/pg_hba.conf
49
+ sudo systemctl restart postgresql
50
+ sudo -u postgres createuser -s -d $(id -un)
51
+ sudo -u postgres createdb test
52
+
53
+ - name: Preparing MariaDB (ubuntu)
54
+ if: matrix.os == 'ubuntu'
55
+ run: |
56
+ sudo apt-get install libmariadb-dev
57
+ sudo systemctl start mysql
58
+ mysql -uroot -proot -e "STATUS"
59
+ mysql -uroot -proot -e "CREATE USER '$(id -un)'@'localhost'; GRANT ALL ON *.* TO '$(id -un)'@'localhost'; FLUSH PRIVILEGES; CREATE DATABASE test;"
60
+
33
61
  - name: Run tests
34
- run: ${{matrix.env}} bundle exec rspec
62
+ timeout-minutes: 5
63
+ run: |
64
+ export MYSQL_UNIX_PORT=/var/run/mysqld/mysqld.sock
65
+ ${{matrix.env}} bundle exec rspec
data/db.gemspec CHANGED
@@ -17,10 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
+ spec.add_dependency "async-io"
21
+ spec.add_dependency "async-pool"
22
+
20
23
  spec.add_development_dependency "bake"
21
24
  spec.add_development_dependency "bake-bundler"
22
25
 
26
+ spec.add_development_dependency "covered"
23
27
  spec.add_development_dependency "bundler", "~> 2.0"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
28
  spec.add_development_dependency "rspec", "~> 3.0"
26
29
  end
data/gems.rb CHANGED
@@ -2,3 +2,14 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in db.gemspec
4
4
  gemspec
5
+
6
+ group :adapters do
7
+ gem "db-postgres"#, path: "../db-postgres"
8
+ gem "db-mariadb"#, path: "../db-mariadb"
9
+ end
10
+
11
+ group :benchmark do
12
+ gem "benchmark-ips"
13
+ gem "mysql2"
14
+ gem "pg"
15
+ end
data/lib/db.rb CHANGED
@@ -20,4 +20,5 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require "db/version"
23
+ require_relative 'db/version'
24
+ require_relative 'db/adapters'
@@ -0,0 +1,14 @@
1
+
2
+ module DB
3
+ module Adapters
4
+ @adapters = {}
5
+
6
+ def self.register(name, adapter)
7
+ @adapters[name] = adapter
8
+ end
9
+
10
+ def self.each(&block)
11
+ @adapters.each(&block)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,101 @@
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
+ require 'async/io'
24
+ require 'async/io/stream'
25
+ require 'async/pool/controller'
26
+
27
+ require_relative 'context/query'
28
+ require_relative 'context/transaction'
29
+
30
+ module DB
31
+ class Client
32
+ def initialize(adapter, **options)
33
+ @adapter = adapter
34
+
35
+ @pool = connect(**options)
36
+ end
37
+
38
+ attr :endpoint
39
+ attr :protocol
40
+
41
+ # @return [client] if no block provided.
42
+ # @yield [client, task] yield the client in an async task.
43
+ def self.open(*arguments, &block)
44
+ client = self.new(*arguments)
45
+
46
+ return client unless block_given?
47
+
48
+ Async do |task|
49
+ begin
50
+ yield client, task
51
+ ensure
52
+ client.close
53
+ end
54
+ end.wait
55
+ end
56
+
57
+ def close
58
+ @pool.close
59
+ end
60
+
61
+ def call(statement = nil, **options)
62
+ query = Context::Query.new(@pool, **options)
63
+
64
+ if statement
65
+ query.send_query(statement)
66
+ end
67
+
68
+ return query unless block_given?
69
+
70
+ begin
71
+ yield query
72
+ ensure
73
+ query.close
74
+ end
75
+ end
76
+
77
+ def transaction(statement = "BEGIN", **options)
78
+ transaction = Context::Transaction.new(@pool, **options)
79
+
80
+ if statement
81
+ transaction.call("BEGIN")
82
+ end
83
+
84
+ return transaction unless block_given?
85
+
86
+ begin
87
+ yield transaction
88
+
89
+ transaction.commit
90
+ ensure
91
+ transaction.abort if $!
92
+ end
93
+ end
94
+
95
+ protected
96
+
97
+ def connect(**options)
98
+ Async::Pool::Controller.new(@adapter, **options)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ # Copyright, 2018, by Huba Nagy.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ module DB
25
+ module Context
26
+ class Query
27
+ def initialize(pool, **options)
28
+ @pool = pool
29
+ @connection = pool.acquire
30
+ end
31
+
32
+ attr :connection
33
+
34
+ def close
35
+ if @connection
36
+ self.flush
37
+
38
+ @pool.release(@connection)
39
+
40
+ @connection = nil
41
+ end
42
+ end
43
+
44
+ def send_query(statement, **options)
45
+ @connection.send_query(statement, **options)
46
+ end
47
+
48
+ def next_result
49
+ @connection.next_result
50
+ end
51
+
52
+ def call(statement, **options)
53
+ @connection.send_query(statement, **options)
54
+
55
+ return @connection.next_result
56
+ end
57
+
58
+ def results
59
+ while result = self.next_result
60
+ yield result
61
+ end
62
+
63
+ return nil
64
+ end
65
+
66
+ def flush
67
+ until @connection.next_result.nil?
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ # Copyright, 2018, by Huba Nagy.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ require_relative 'query'
25
+
26
+ module DB
27
+ module Context
28
+ class Transaction < Query
29
+ def commit
30
+ self.call("COMMIT")
31
+ self.close
32
+ end
33
+
34
+ def abort
35
+ self.call("ROLLBACK")
36
+ self.close
37
+ end
38
+
39
+ def savepoint(name)
40
+ self.call("SAVEPOINT #{name}")
41
+ end
42
+
43
+ def rollback(name)
44
+ self.call("ROLLBACK #{name}")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module DB
24
- VERSION = "0.0.0"
24
+ VERSION = "0.5.0"
25
25
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-25 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  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
+ - !ruby/object:Gem::Dependency
28
+ name: async-pool
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bake
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -39,33 +67,33 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: bundler
70
+ name: covered
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - "~>"
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
- version: '2.0'
75
+ version: '0'
48
76
  type: :development
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: '2.0'
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: rake
84
+ name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '10.0'
89
+ version: '2.0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '10.0'
96
+ version: '2.0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rspec
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +108,7 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: '3.0'
83
- description:
111
+ description:
84
112
  email:
85
113
  - samuel.williams@oriontransfer.co.nz
86
114
  executables: []
@@ -94,11 +122,15 @@ files:
94
122
  - db.gemspec
95
123
  - gems.rb
96
124
  - lib/db.rb
125
+ - lib/db/adapters.rb
126
+ - lib/db/client.rb
127
+ - lib/db/context/query.rb
128
+ - lib/db/context/transaction.rb
97
129
  - lib/db/version.rb
98
130
  homepage: https://github.com/socketry/db
99
131
  licenses: []
100
132
  metadata: {}
101
- post_install_message:
133
+ post_install_message:
102
134
  rdoc_options: []
103
135
  require_paths:
104
136
  - lib
@@ -113,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
145
  - !ruby/object:Gem::Version
114
146
  version: '0'
115
147
  requirements: []
116
- rubygems_version: 3.0.6
117
- signing_key:
148
+ rubygems_version: 3.1.2
149
+ signing_key:
118
150
  specification_version: 4
119
151
  summary: A low level database access gem.
120
152
  test_files: []