ensql 0.6.0 → 0.6.1
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/.github/workflows/specs.yml +59 -0
- data/CHANGELOG.md +8 -2
- data/Gemfile +8 -14
- data/Gemfile.lock +8 -3
- data/README.md +18 -3
- data/ensql.gemspec +5 -0
- data/gemfiles/maintained.gemfile +22 -0
- data/gemfiles/maintained.gemfile.lock +79 -0
- data/gemfiles/minimum.gemfile +25 -0
- data/gemfiles/minimum.gemfile.lock +73 -0
- data/lib/ensql/active_record_adapter.rb +23 -9
- data/lib/ensql/adapter.rb +8 -8
- data/lib/ensql/sequel_adapter.rb +29 -13
- data/lib/ensql/sql.rb +3 -2
- data/lib/ensql/version.rb +5 -5
- metadata +64 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3bc1fdbc384c83a4d0a8ab1544f095320d63d66bc814cc30877f63bdc766be40
|
|
4
|
+
data.tar.gz: 7af7a154c0b4480278377f3dae635daf890ed69fd259f6bcffa3a14c3b4a8269
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1d085a19d85b24a3a4d038e137b54b439fafe8b30ec5f5b2e384792af87c00e3daf462ed08a8d16c252568d1f1d6bb1bf390e23c23423a8f48de4085f0f6e487
|
|
7
|
+
data.tar.gz: 7ee53cbd22ce7c5c059659b50fccd6a3e0f3b0836f0114d916d1faab3c6cdb7a598a5588102631cab3de6b2c435236939e0b43cdb550c7f068fb76c4eea579ed
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Specs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
# Service containers to run with `runner-job`
|
|
15
|
+
services:
|
|
16
|
+
# Label used to access the service container
|
|
17
|
+
postgres:
|
|
18
|
+
# Docker Hub image
|
|
19
|
+
image: postgres
|
|
20
|
+
env:
|
|
21
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
|
22
|
+
POSTGRES_USER: runner
|
|
23
|
+
# Set health checks to wait until postgres has started
|
|
24
|
+
options: >-
|
|
25
|
+
--health-cmd pg_isready
|
|
26
|
+
--health-interval 10s
|
|
27
|
+
--health-timeout 5s
|
|
28
|
+
--health-retries 5
|
|
29
|
+
ports:
|
|
30
|
+
# Maps tcp port 5432 on service container to the host
|
|
31
|
+
- 5432:5432
|
|
32
|
+
|
|
33
|
+
strategy:
|
|
34
|
+
fail-fast: false
|
|
35
|
+
matrix:
|
|
36
|
+
include:
|
|
37
|
+
- ruby-version: 3.0
|
|
38
|
+
gemfile: Gemfile
|
|
39
|
+
- ruby-version: 2.5
|
|
40
|
+
gemfile: gemfiles/maintained.gemfile
|
|
41
|
+
- ruby-version: 2.4.0
|
|
42
|
+
gemfile: gemfiles/minimum.gemfile
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
|
46
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
|
47
|
+
COVERAGE: ${{ matrix.gemfile == 'Gemfile' }}
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v2
|
|
51
|
+
- name: Set up Ruby
|
|
52
|
+
uses: ruby/setup-ruby@v1
|
|
53
|
+
with:
|
|
54
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
55
|
+
bundler-cache: true
|
|
56
|
+
- name: Install dependencies
|
|
57
|
+
run: bundle install
|
|
58
|
+
- name: Run tests
|
|
59
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# Change Log
|
|
2
2
|
|
|
3
|
-
## [0.1
|
|
3
|
+
## [0.6.1] - 2021-02-25
|
|
4
|
+
|
|
5
|
+
- Enables the use of streaming with the SequelAdapter
|
|
6
|
+
- Improves performance of #first_row and #each_row
|
|
7
|
+
- Tests against Sequel 5.9
|
|
8
|
+
|
|
9
|
+
## [0.6.0] - 2021-02-15
|
|
4
10
|
|
|
5
11
|
- Initial release
|
data/Gemfile
CHANGED
|
@@ -5,17 +5,11 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in ensql.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
gem "
|
|
11
|
-
|
|
12
|
-
gem "
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
gem "activerecord", ENV['ACTIVERECORD_VERSION'] || Ensql::ACTIVERECORD_VERSION
|
|
17
|
-
gem "sequel", ENV['SEQUEL_VERSION'] || Ensql::SEQUEL_VERSION
|
|
18
|
-
gem "sqlite3", ENV['SQLITE3_VERSION'] || "~> 1.4"
|
|
19
|
-
gem "pg", ENV['PG_VERSION'] || "~> 1.2"
|
|
20
|
-
|
|
21
|
-
gem "yard", "~> 0.9.26"
|
|
8
|
+
group :adapters do
|
|
9
|
+
require_relative 'lib/ensql/version'
|
|
10
|
+
gem "activerecord", Ensql::SUPPORTED_ACTIVERECORD_VERSIONS
|
|
11
|
+
gem "sequel", Ensql::SUPPORTED_SEQUEL_VERSIONS
|
|
12
|
+
gem "sqlite3", "~> 1.4"
|
|
13
|
+
gem "pg", "~> 1.2"
|
|
14
|
+
gem "sequel_pg"
|
|
15
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
ensql (0.6.
|
|
4
|
+
ensql (0.6.1)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -22,7 +22,7 @@ GEM
|
|
|
22
22
|
docile (1.3.5)
|
|
23
23
|
i18n (1.8.9)
|
|
24
24
|
concurrent-ruby (~> 1.0)
|
|
25
|
-
minitest (5.14.
|
|
25
|
+
minitest (5.14.4)
|
|
26
26
|
pg (1.2.3)
|
|
27
27
|
rake (13.0.3)
|
|
28
28
|
rspec (3.10.0)
|
|
@@ -39,6 +39,9 @@ GEM
|
|
|
39
39
|
rspec-support (~> 3.10.0)
|
|
40
40
|
rspec-support (3.10.2)
|
|
41
41
|
sequel (5.41.0)
|
|
42
|
+
sequel_pg (1.14.0)
|
|
43
|
+
pg (>= 0.18.0, != 1.2.0)
|
|
44
|
+
sequel (>= 4.38.0)
|
|
42
45
|
simplecov (0.21.2)
|
|
43
46
|
docile (~> 1.1)
|
|
44
47
|
simplecov-html (~> 0.11)
|
|
@@ -53,6 +56,7 @@ GEM
|
|
|
53
56
|
|
|
54
57
|
PLATFORMS
|
|
55
58
|
x86_64-darwin-18
|
|
59
|
+
x86_64-linux
|
|
56
60
|
|
|
57
61
|
DEPENDENCIES
|
|
58
62
|
activerecord (>= 5.0, < 6.2)
|
|
@@ -60,7 +64,8 @@ DEPENDENCIES
|
|
|
60
64
|
pg (~> 1.2)
|
|
61
65
|
rake (~> 13.0)
|
|
62
66
|
rspec (~> 3.0)
|
|
63
|
-
sequel (~> 5.
|
|
67
|
+
sequel (~> 5.9)
|
|
68
|
+
sequel_pg
|
|
64
69
|
simplecov (~> 0.21.2)
|
|
65
70
|
sqlite3 (~> 1.4)
|
|
66
71
|
yard (~> 0.9.26)
|
data/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Ensql
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/ensql)
|
|
4
|
+
[](https://github.com/danielfone/ensql/actions/workflows/specs.yml)
|
|
5
|
+
[](https://codeclimate.com/github/danielfone/ensql/maintainability)
|
|
6
|
+
|
|
3
7
|
Ensql lets you write SQL for your application the safe and simple way. Ditch your ORM and embrace the power and
|
|
4
8
|
simplicity of writing plain SQL again.
|
|
5
9
|
|
|
@@ -46,6 +50,11 @@ current_results = Ensql.load_sql('results/page', results: all_results, page: 2)
|
|
|
46
50
|
total = Ensql.load_sql('count', subquery: all_results)
|
|
47
51
|
result = { data: current_results.rows, total: total.first_field }
|
|
48
52
|
```
|
|
53
|
+
### Further Reading:
|
|
54
|
+
|
|
55
|
+
* [Source Code](https://github.com/danielfone/ensql)
|
|
56
|
+
* [API Documentation](https://rubydoc.info/gems/ensql/Ensql/SQL)
|
|
57
|
+
* [Rubygem](https://rubygems.org/gems/ensql)
|
|
49
58
|
|
|
50
59
|
## Installation
|
|
51
60
|
|
|
@@ -57,10 +66,16 @@ Or install it manually with:
|
|
|
57
66
|
|
|
58
67
|
$ gem install ensql
|
|
59
68
|
|
|
69
|
+
Ensql requires:
|
|
70
|
+
|
|
71
|
+
* Ruby >= 2.4.0
|
|
72
|
+
* Sequel >= 5.9 if using Sequel
|
|
73
|
+
* ActiveRecord >= 5.0 if using ActiveRecord
|
|
74
|
+
|
|
60
75
|
## Usage
|
|
61
76
|
|
|
62
77
|
Typically, you don't need to configure anything. Ensql will look for Sequel or ActiveRecord (in that order) and load the
|
|
63
|
-
appropriate adapter. You can override this if you need to, or configure your own adapter. See
|
|
78
|
+
appropriate adapter. You can override this if you need to, or configure your own adapter. See [the API docs](https://rubydoc.info/gems/ensql/Ensql/Adapter) for
|
|
64
79
|
details of the interface.
|
|
65
80
|
|
|
66
81
|
```ruby
|
|
@@ -93,7 +108,7 @@ All interpolation is marked by `%{}` placeholders in the SQL. This is the only p
|
|
|
93
108
|
allowed. Only various forms of literal interpolation are supported - identifier interpolation is not supported at this
|
|
94
109
|
stage.
|
|
95
110
|
|
|
96
|
-
There are 4 types of interpolation
|
|
111
|
+
There are 4 types of interpolation:
|
|
97
112
|
|
|
98
113
|
1. `%{param}` interpolates a Ruby object as a SQL literal.
|
|
99
114
|
2. `%{(param)}` expands an array into a list of SQL literals.
|
|
@@ -120,7 +135,7 @@ Ensql.sql('SELECT * FROM users ORDER BY %{!orderby}', orderby: Ensql.sql('name a
|
|
|
120
135
|
# SELECT * FROM users ORDER BY name asc
|
|
121
136
|
```
|
|
122
137
|
|
|
123
|
-
|
|
138
|
+
See [the API docs](https://rubydoc.info/gems/ensql/Ensql/SQL) for details.
|
|
124
139
|
|
|
125
140
|
### Results
|
|
126
141
|
|
data/ensql.gemspec
CHANGED
|
@@ -29,4 +29,9 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
30
|
spec.require_paths = ["lib"]
|
|
31
31
|
|
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
34
|
+
spec.add_development_dependency "simplecov", "~> 0.21.2"
|
|
35
|
+
spec.add_development_dependency "yard", "~> 0.9.26"
|
|
36
|
+
|
|
32
37
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# This specifies the oldest maintained versions of our dependencies
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
source "https://rubygems.org"
|
|
8
|
+
|
|
9
|
+
ruby '~> 2.5.0'
|
|
10
|
+
|
|
11
|
+
# Specify your gem's dependencies in ensql.gemspec
|
|
12
|
+
gemspec path: '../'
|
|
13
|
+
|
|
14
|
+
# Optional runtime dependencies
|
|
15
|
+
group :adapters do
|
|
16
|
+
require_relative '../lib/ensql/version'
|
|
17
|
+
gem "activerecord", "~> 5.2.0"
|
|
18
|
+
gem "sequel", "~> 5.9"
|
|
19
|
+
gem "sqlite3"
|
|
20
|
+
gem "pg"
|
|
21
|
+
gem "sequel_pg"
|
|
22
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
ensql (0.6.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
activemodel (5.2.4.5)
|
|
10
|
+
activesupport (= 5.2.4.5)
|
|
11
|
+
activerecord (5.2.4.5)
|
|
12
|
+
activemodel (= 5.2.4.5)
|
|
13
|
+
activesupport (= 5.2.4.5)
|
|
14
|
+
arel (>= 9.0)
|
|
15
|
+
activesupport (5.2.4.5)
|
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
|
+
i18n (>= 0.7, < 2)
|
|
18
|
+
minitest (~> 5.1)
|
|
19
|
+
tzinfo (~> 1.1)
|
|
20
|
+
arel (9.0.0)
|
|
21
|
+
concurrent-ruby (1.1.8)
|
|
22
|
+
diff-lcs (1.4.4)
|
|
23
|
+
docile (1.3.5)
|
|
24
|
+
i18n (1.8.9)
|
|
25
|
+
concurrent-ruby (~> 1.0)
|
|
26
|
+
minitest (5.14.4)
|
|
27
|
+
pg (1.2.3)
|
|
28
|
+
rake (13.0.3)
|
|
29
|
+
rspec (3.10.0)
|
|
30
|
+
rspec-core (~> 3.10.0)
|
|
31
|
+
rspec-expectations (~> 3.10.0)
|
|
32
|
+
rspec-mocks (~> 3.10.0)
|
|
33
|
+
rspec-core (3.10.1)
|
|
34
|
+
rspec-support (~> 3.10.0)
|
|
35
|
+
rspec-expectations (3.10.1)
|
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
|
+
rspec-support (~> 3.10.0)
|
|
38
|
+
rspec-mocks (3.10.2)
|
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
+
rspec-support (~> 3.10.0)
|
|
41
|
+
rspec-support (3.10.2)
|
|
42
|
+
sequel (5.41.0)
|
|
43
|
+
sequel_pg (1.14.0)
|
|
44
|
+
pg (>= 0.18.0, != 1.2.0)
|
|
45
|
+
sequel (>= 4.38.0)
|
|
46
|
+
simplecov (0.21.2)
|
|
47
|
+
docile (~> 1.1)
|
|
48
|
+
simplecov-html (~> 0.11)
|
|
49
|
+
simplecov_json_formatter (~> 0.1)
|
|
50
|
+
simplecov-html (0.12.3)
|
|
51
|
+
simplecov_json_formatter (0.1.2)
|
|
52
|
+
sqlite3 (1.4.2)
|
|
53
|
+
thread_safe (0.3.6)
|
|
54
|
+
tzinfo (1.2.9)
|
|
55
|
+
thread_safe (~> 0.1)
|
|
56
|
+
yard (0.9.26)
|
|
57
|
+
|
|
58
|
+
PLATFORMS
|
|
59
|
+
ruby
|
|
60
|
+
x86_64-darwin-18
|
|
61
|
+
x86_64-linux
|
|
62
|
+
|
|
63
|
+
DEPENDENCIES
|
|
64
|
+
activerecord (~> 5.2.0)
|
|
65
|
+
ensql!
|
|
66
|
+
pg
|
|
67
|
+
rake (~> 13.0)
|
|
68
|
+
rspec (~> 3.0)
|
|
69
|
+
sequel (~> 5.9)
|
|
70
|
+
sequel_pg
|
|
71
|
+
simplecov (~> 0.21.2)
|
|
72
|
+
sqlite3
|
|
73
|
+
yard (~> 0.9.26)
|
|
74
|
+
|
|
75
|
+
RUBY VERSION
|
|
76
|
+
ruby 2.5.8p224
|
|
77
|
+
|
|
78
|
+
BUNDLED WITH
|
|
79
|
+
2.2.9
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# This specifies the oldest compatible versions of our dependencies
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
source "https://rubygems.org"
|
|
8
|
+
|
|
9
|
+
ruby '2.4.0'
|
|
10
|
+
|
|
11
|
+
# Specify your gem's dependencies in ensql.gemspec
|
|
12
|
+
gemspec path: '../'
|
|
13
|
+
|
|
14
|
+
# Downgrade simplecov for ruby 2.4 compat
|
|
15
|
+
gem 'simplecov', '~> 0.18.5'
|
|
16
|
+
|
|
17
|
+
# Optional runtime dependencies
|
|
18
|
+
group :adapters do
|
|
19
|
+
require_relative '../lib/ensql/version'
|
|
20
|
+
gem "activerecord", Ensql::SUPPORTED_ACTIVERECORD_VERSIONS.to_s.scan(/\d+.\d+/).first
|
|
21
|
+
gem "sequel", Ensql::SUPPORTED_SEQUEL_VERSIONS.to_s.scan(/\d+.\d+/).first
|
|
22
|
+
gem "sqlite3", "~> 1.3.6" # AR version constraint
|
|
23
|
+
gem "pg", "~> 0.18" # AR version constraint
|
|
24
|
+
gem "sequel_pg"
|
|
25
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
ensql (0.6.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
activemodel (5.0.0)
|
|
10
|
+
activesupport (= 5.0.0)
|
|
11
|
+
activerecord (5.0.0)
|
|
12
|
+
activemodel (= 5.0.0)
|
|
13
|
+
activesupport (= 5.0.0)
|
|
14
|
+
arel (~> 7.0)
|
|
15
|
+
activesupport (5.0.0)
|
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
|
+
i18n (~> 0.7)
|
|
18
|
+
minitest (~> 5.1)
|
|
19
|
+
tzinfo (~> 1.1)
|
|
20
|
+
arel (7.1.4)
|
|
21
|
+
concurrent-ruby (1.1.8)
|
|
22
|
+
diff-lcs (1.4.4)
|
|
23
|
+
docile (1.3.5)
|
|
24
|
+
i18n (0.9.5)
|
|
25
|
+
concurrent-ruby (~> 1.0)
|
|
26
|
+
minitest (5.14.4)
|
|
27
|
+
pg (0.21.0)
|
|
28
|
+
rake (13.0.3)
|
|
29
|
+
rspec (3.10.0)
|
|
30
|
+
rspec-core (~> 3.10.0)
|
|
31
|
+
rspec-expectations (~> 3.10.0)
|
|
32
|
+
rspec-mocks (~> 3.10.0)
|
|
33
|
+
rspec-core (3.10.1)
|
|
34
|
+
rspec-support (~> 3.10.0)
|
|
35
|
+
rspec-expectations (3.10.1)
|
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
|
+
rspec-support (~> 3.10.0)
|
|
38
|
+
rspec-mocks (3.10.2)
|
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
+
rspec-support (~> 3.10.0)
|
|
41
|
+
rspec-support (3.10.2)
|
|
42
|
+
sequel (5.9.0)
|
|
43
|
+
sequel_pg (1.14.0)
|
|
44
|
+
pg (>= 0.18.0, != 1.2.0)
|
|
45
|
+
sequel (>= 4.38.0)
|
|
46
|
+
simplecov (0.18.5)
|
|
47
|
+
docile (~> 1.1)
|
|
48
|
+
simplecov-html (~> 0.11)
|
|
49
|
+
simplecov-html (0.12.3)
|
|
50
|
+
sqlite3 (1.3.13)
|
|
51
|
+
thread_safe (0.3.6)
|
|
52
|
+
tzinfo (1.2.9)
|
|
53
|
+
thread_safe (~> 0.1)
|
|
54
|
+
yard (0.9.26)
|
|
55
|
+
|
|
56
|
+
PLATFORMS
|
|
57
|
+
x86_64-darwin-18
|
|
58
|
+
x86_64-linux
|
|
59
|
+
|
|
60
|
+
DEPENDENCIES
|
|
61
|
+
activerecord (= 5.0)
|
|
62
|
+
ensql!
|
|
63
|
+
pg (~> 0.18)
|
|
64
|
+
rake (~> 13.0)
|
|
65
|
+
rspec (~> 3.0)
|
|
66
|
+
sequel (= 5.9)
|
|
67
|
+
sequel_pg
|
|
68
|
+
simplecov (~> 0.18.5)
|
|
69
|
+
sqlite3 (~> 1.3.6)
|
|
70
|
+
yard (~> 0.9.26)
|
|
71
|
+
|
|
72
|
+
BUNDLED WITH
|
|
73
|
+
2.2.9
|
|
@@ -4,7 +4,7 @@ require_relative 'version'
|
|
|
4
4
|
require_relative 'adapter'
|
|
5
5
|
|
|
6
6
|
# Ensure our optional dependency has a compatible version
|
|
7
|
-
gem 'activerecord', Ensql::
|
|
7
|
+
gem 'activerecord', Ensql::SUPPORTED_ACTIVERECORD_VERSIONS
|
|
8
8
|
require 'active_record'
|
|
9
9
|
|
|
10
10
|
module Ensql
|
|
@@ -18,20 +18,28 @@ module Ensql
|
|
|
18
18
|
# ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'mydb')
|
|
19
19
|
# Ensql.adapter = Ensql::ActiveRecordAdapter
|
|
20
20
|
#
|
|
21
|
-
# @see
|
|
22
|
-
# @see ACTIVERECORD_VERSION Required gem version
|
|
21
|
+
# @see SUPPORTED_ACTIVERECORD_VERSIONS
|
|
23
22
|
#
|
|
24
23
|
module ActiveRecordAdapter
|
|
25
24
|
extend Adapter
|
|
26
25
|
|
|
27
26
|
# @!visibility private
|
|
28
27
|
def self.fetch_rows(sql)
|
|
28
|
+
fetch_each_row(sql).to_a
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @!visibility private
|
|
32
|
+
def self.fetch_each_row(sql, &block)
|
|
33
|
+
return to_enum(:fetch_each_row, sql) unless block_given?
|
|
34
|
+
|
|
29
35
|
result = connection.exec_query(sql)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
# AR populates `column_types` with the types of any columns that haven't
|
|
37
|
+
# already been type casted by pg decoders. If present, we need to
|
|
38
|
+
# deserialize them now.
|
|
39
|
+
if result.column_types.any?
|
|
40
|
+
result.each { |row| yield deserialize_types(row, result.column_types) }
|
|
41
|
+
else
|
|
42
|
+
result.each(&block)
|
|
35
43
|
end
|
|
36
44
|
end
|
|
37
45
|
|
|
@@ -54,7 +62,13 @@ module Ensql
|
|
|
54
62
|
ActiveRecord::Base.connection
|
|
55
63
|
end
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
def self.deserialize_types(row, column_types)
|
|
66
|
+
row.each_with_object({}) { |(column, value), hash|
|
|
67
|
+
hash[column] = column_types[column]&.deserialize(value) || value
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private_class_method :connection, :deserialize_types
|
|
58
72
|
|
|
59
73
|
end
|
|
60
74
|
end
|
data/lib/ensql/adapter.rb
CHANGED
|
@@ -41,6 +41,13 @@ module Ensql
|
|
|
41
41
|
#
|
|
42
42
|
# @return [Array<Hash>] rows as hashes keyed by column name
|
|
43
43
|
|
|
44
|
+
# @!method fetch_each_row(sql)
|
|
45
|
+
#
|
|
46
|
+
# Execute the query and yield each resulting row. This should provide a more
|
|
47
|
+
# efficient method of iterating through large datasets.
|
|
48
|
+
#
|
|
49
|
+
# @yield <Hash> row
|
|
50
|
+
|
|
44
51
|
# @!method fetch_count(sql)
|
|
45
52
|
#
|
|
46
53
|
# Execute the statement and return the number of rows affected. Typically
|
|
@@ -58,18 +65,11 @@ module Ensql
|
|
|
58
65
|
|
|
59
66
|
# @!group 2. Predefined Methods
|
|
60
67
|
|
|
61
|
-
# Execute the query and yield each resulting row. This should provide a more
|
|
62
|
-
# efficient method of iterating through large datasets.
|
|
63
|
-
#
|
|
64
|
-
# @yield <Hash> row
|
|
65
|
-
def fetch_each_row(sql, &block)
|
|
66
|
-
fetch_rows(sql).each(&block)
|
|
67
|
-
end
|
|
68
68
|
|
|
69
69
|
# Execute the query and return only the first row of the result.
|
|
70
70
|
# @return <Hash>
|
|
71
71
|
def fetch_first_row(sql)
|
|
72
|
-
|
|
72
|
+
fetch_each_row(sql).first
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
# Execute the query and return only the first column of the result.
|
data/lib/ensql/sequel_adapter.rb
CHANGED
|
@@ -4,31 +4,47 @@ require_relative 'version'
|
|
|
4
4
|
require_relative 'adapter'
|
|
5
5
|
|
|
6
6
|
# Ensure our optional dependency has a compatible version
|
|
7
|
-
gem 'sequel', Ensql::
|
|
7
|
+
gem 'sequel', Ensql::SUPPORTED_SEQUEL_VERSIONS
|
|
8
8
|
require 'sequel'
|
|
9
9
|
|
|
10
10
|
module Ensql
|
|
11
11
|
#
|
|
12
|
-
# Implements the {Adapter} interface for Sequel. Requires a Sequel connection
|
|
13
|
-
# be established. Uses the first connection found in Sequel::DATABASES. You
|
|
14
|
-
# may want to utilize the relevant extensions to make the most of
|
|
15
|
-
# deserialization.
|
|
12
|
+
# Implements the {Adapter} interface for Sequel. Requires a Sequel connection
|
|
13
|
+
# to be established. Uses the first connection found in Sequel::DATABASES. You
|
|
14
|
+
# may want to utilize the relevant extensions to make the most of
|
|
15
|
+
# deserialization and other database features.
|
|
16
16
|
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
# Ensql.adapter = Ensql::SequelAdapter
|
|
17
|
+
# require 'sequel'
|
|
18
|
+
# DB = Sequel.connect('postgres://localhost/mydb')
|
|
19
|
+
# DB.extend(:pg_json)
|
|
20
|
+
# Ensql.adapter = Ensql::SequelAdapter
|
|
22
21
|
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
22
|
+
# To stream rows, configure streaming on the connection and use
|
|
23
|
+
# {SQL.each_row}
|
|
24
|
+
#
|
|
25
|
+
# DB = Sequel.connect('postgresql:/')
|
|
26
|
+
# DB.extension(:pg_streaming)
|
|
27
|
+
# DB.stream_all_queries = true
|
|
28
|
+
# Ensql.sql("select * from large_table").each_row do |row|
|
|
29
|
+
# # This now yields each row in single-row mode.
|
|
30
|
+
# # The connection cannot be used for other queries while this is streaming.
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# @see SUPPORTED_SEQUEL_VERSIONS
|
|
25
34
|
#
|
|
26
35
|
module SequelAdapter
|
|
27
36
|
extend Adapter
|
|
28
37
|
|
|
29
38
|
# @!visibility private
|
|
30
39
|
def self.fetch_rows(sql)
|
|
31
|
-
|
|
40
|
+
fetch_each_row(sql).to_a
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @!visibility private
|
|
44
|
+
def self.fetch_each_row(sql)
|
|
45
|
+
return to_enum(:fetch_each_row, sql) unless block_given?
|
|
46
|
+
|
|
47
|
+
db.fetch(sql) { |r| yield r.transform_keys(&:to_s) }
|
|
32
48
|
end
|
|
33
49
|
|
|
34
50
|
# @!visibility private
|
data/lib/ensql/sql.rb
CHANGED
|
@@ -4,8 +4,8 @@ require_relative "../ensql"
|
|
|
4
4
|
|
|
5
5
|
module Ensql
|
|
6
6
|
#
|
|
7
|
-
# Encapsulates a plain-text SQL statement and optional parameters to interpolate. Interpolation is indicated by one
|
|
8
|
-
#
|
|
7
|
+
# Encapsulates a plain-text SQL statement and optional parameters to interpolate. Interpolation is indicated by one of
|
|
8
|
+
# the four placeholder formats:
|
|
9
9
|
#
|
|
10
10
|
# 1. **Literal:** `%{param}`
|
|
11
11
|
# - Interpolates `param` as a quoted string or a numeric literal depending on the class.
|
|
@@ -31,6 +31,7 @@ module Ensql
|
|
|
31
31
|
# - Allows composition of SQL via subqueries.
|
|
32
32
|
#
|
|
33
33
|
# Any placeholders in the SQL must be present in the params hash or a KeyError will be raised during interpolation.
|
|
34
|
+
# Interpolation occurs just before the SQL is executed.
|
|
34
35
|
#
|
|
35
36
|
# @example
|
|
36
37
|
# # Interpolate a literal
|
data/lib/ensql/version.rb
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Ensql
|
|
4
4
|
# Gem version
|
|
5
|
-
VERSION = "0.6.
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
|
|
5
|
+
VERSION = "0.6.1"
|
|
6
|
+
# Versions of activerecord compatible with the {ActiveRecordAdapter}
|
|
7
|
+
SUPPORTED_ACTIVERECORD_VERSIONS = ['>= 5.0', '< 6.2'].freeze
|
|
8
|
+
# Versions of sequel compatible with the {SequelAdapter}
|
|
9
|
+
SUPPORTED_SEQUEL_VERSIONS = '~> 5.9'
|
|
10
10
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,71 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ensql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Fone
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-02-
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '13.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '13.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: simplecov
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.21.2
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.21.2
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: yard
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.9.26
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.9.26
|
|
13
69
|
description: Ditch your ORM and embrace the power and simplicity of writing plain
|
|
14
70
|
SQL again.
|
|
15
71
|
email:
|
|
@@ -18,6 +74,7 @@ executables: []
|
|
|
18
74
|
extensions: []
|
|
19
75
|
extra_rdoc_files: []
|
|
20
76
|
files:
|
|
77
|
+
- ".github/workflows/specs.yml"
|
|
21
78
|
- ".gitignore"
|
|
22
79
|
- ".rspec"
|
|
23
80
|
- ".ruby-version"
|
|
@@ -32,6 +89,10 @@ files:
|
|
|
32
89
|
- bin/rspec
|
|
33
90
|
- bin/setup
|
|
34
91
|
- ensql.gemspec
|
|
92
|
+
- gemfiles/maintained.gemfile
|
|
93
|
+
- gemfiles/maintained.gemfile.lock
|
|
94
|
+
- gemfiles/minimum.gemfile
|
|
95
|
+
- gemfiles/minimum.gemfile.lock
|
|
35
96
|
- lib/ensql.rb
|
|
36
97
|
- lib/ensql/active_record_adapter.rb
|
|
37
98
|
- lib/ensql/adapter.rb
|