yesql 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e080f284342f3ef4585f3763e069a7d716deb8c5ffbb0b3e3e06a15d2dcdafa3
4
- data.tar.gz: a39131cd73c4df0e109071de38a87a284e688978ab8f8078611958677ccb7412
3
+ metadata.gz: d85f1a89f06d3fa6d3a35471d895bce7860ed93988fa91d1f08149d349782e79
4
+ data.tar.gz: 4f6a7d1486495fe6291bddcfaa7d2fadbb051a79da98ba81c2e2a9958f3046ee
5
5
  SHA512:
6
- metadata.gz: 2d4800c0d99e16ca0302deff9a9ace0b453d1503b9ae9a9937936da56cc4084c3ce4194e98974384d53f9cac3f3866b41324661db49edd6ed777fc3f379bc1a5
7
- data.tar.gz: 3c5cc66fb4fcbb8ab188f1c7057a2243e3df7d8ac84359327af44ae9d0ef812ab4c7a52b8c70f791a05bffe90efb7ebe5caaa8bae68cb038bd4b9bf1f7576044
6
+ metadata.gz: 0faf664927b4ed1c605f33a79f6e65b93b2bddd2bfea6c4f71cdeec8b9ae425c17111363ce95a74c715b468d89fb7e68b3bdf3041c3feaf76fe366556bb6592f
7
+ data.tar.gz: a1e04806de2b8b367c95f0167032a664315a8c1de57636855b430f702c84b1884432895f6393742e273c65b3dd9d54b9e35ac2e4e4c5ae59ec637caeac64509e
@@ -1,62 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yesql (0.1.3)
4
+ yesql (0.1.4)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.0.3.3)
11
- actionpack (= 6.0.3.3)
10
+ actioncable (6.0.3.4)
11
+ actionpack (= 6.0.3.4)
12
12
  nio4r (~> 2.0)
13
13
  websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.3.3)
15
- actionpack (= 6.0.3.3)
16
- activejob (= 6.0.3.3)
17
- activerecord (= 6.0.3.3)
18
- activestorage (= 6.0.3.3)
19
- activesupport (= 6.0.3.3)
14
+ actionmailbox (6.0.3.4)
15
+ actionpack (= 6.0.3.4)
16
+ activejob (= 6.0.3.4)
17
+ activerecord (= 6.0.3.4)
18
+ activestorage (= 6.0.3.4)
19
+ activesupport (= 6.0.3.4)
20
20
  mail (>= 2.7.1)
21
- actionmailer (6.0.3.3)
22
- actionpack (= 6.0.3.3)
23
- actionview (= 6.0.3.3)
24
- activejob (= 6.0.3.3)
21
+ actionmailer (6.0.3.4)
22
+ actionpack (= 6.0.3.4)
23
+ actionview (= 6.0.3.4)
24
+ activejob (= 6.0.3.4)
25
25
  mail (~> 2.5, >= 2.5.4)
26
26
  rails-dom-testing (~> 2.0)
27
- actionpack (6.0.3.3)
28
- actionview (= 6.0.3.3)
29
- activesupport (= 6.0.3.3)
27
+ actionpack (6.0.3.4)
28
+ actionview (= 6.0.3.4)
29
+ activesupport (= 6.0.3.4)
30
30
  rack (~> 2.0, >= 2.0.8)
31
31
  rack-test (>= 0.6.3)
32
32
  rails-dom-testing (~> 2.0)
33
33
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.3.3)
35
- actionpack (= 6.0.3.3)
36
- activerecord (= 6.0.3.3)
37
- activestorage (= 6.0.3.3)
38
- activesupport (= 6.0.3.3)
34
+ actiontext (6.0.3.4)
35
+ actionpack (= 6.0.3.4)
36
+ activerecord (= 6.0.3.4)
37
+ activestorage (= 6.0.3.4)
38
+ activesupport (= 6.0.3.4)
39
39
  nokogiri (>= 1.8.5)
40
- actionview (6.0.3.3)
41
- activesupport (= 6.0.3.3)
40
+ actionview (6.0.3.4)
41
+ activesupport (= 6.0.3.4)
42
42
  builder (~> 3.1)
43
43
  erubi (~> 1.4)
44
44
  rails-dom-testing (~> 2.0)
45
45
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.3.3)
47
- activesupport (= 6.0.3.3)
46
+ activejob (6.0.3.4)
47
+ activesupport (= 6.0.3.4)
48
48
  globalid (>= 0.3.6)
49
- activemodel (6.0.3.3)
50
- activesupport (= 6.0.3.3)
51
- activerecord (6.0.3.3)
52
- activemodel (= 6.0.3.3)
53
- activesupport (= 6.0.3.3)
54
- activestorage (6.0.3.3)
55
- actionpack (= 6.0.3.3)
56
- activejob (= 6.0.3.3)
57
- activerecord (= 6.0.3.3)
49
+ activemodel (6.0.3.4)
50
+ activesupport (= 6.0.3.4)
51
+ activerecord (6.0.3.4)
52
+ activemodel (= 6.0.3.4)
53
+ activesupport (= 6.0.3.4)
54
+ activestorage (6.0.3.4)
55
+ actionpack (= 6.0.3.4)
56
+ activejob (= 6.0.3.4)
57
+ activerecord (= 6.0.3.4)
58
58
  marcel (~> 0.3.1)
59
- activesupport (6.0.3.3)
59
+ activesupport (6.0.3.4)
60
60
  concurrent-ruby (~> 1.0, >= 1.0.2)
61
61
  i18n (>= 0.7, < 2)
62
62
  minitest (~> 5.1)
@@ -84,6 +84,7 @@ GEM
84
84
  mini_mime (1.0.2)
85
85
  mini_portile2 (2.4.0)
86
86
  minitest (5.14.2)
87
+ mysql2 (0.5.3)
87
88
  nio4r (2.5.4)
88
89
  nokogiri (1.10.10)
89
90
  mini_portile2 (~> 2.4.0)
@@ -94,29 +95,29 @@ GEM
94
95
  rack (2.2.3)
95
96
  rack-test (1.1.0)
96
97
  rack (>= 1.0, < 3)
97
- rails (6.0.3.3)
98
- actioncable (= 6.0.3.3)
99
- actionmailbox (= 6.0.3.3)
100
- actionmailer (= 6.0.3.3)
101
- actionpack (= 6.0.3.3)
102
- actiontext (= 6.0.3.3)
103
- actionview (= 6.0.3.3)
104
- activejob (= 6.0.3.3)
105
- activemodel (= 6.0.3.3)
106
- activerecord (= 6.0.3.3)
107
- activestorage (= 6.0.3.3)
108
- activesupport (= 6.0.3.3)
98
+ rails (6.0.3.4)
99
+ actioncable (= 6.0.3.4)
100
+ actionmailbox (= 6.0.3.4)
101
+ actionmailer (= 6.0.3.4)
102
+ actionpack (= 6.0.3.4)
103
+ actiontext (= 6.0.3.4)
104
+ actionview (= 6.0.3.4)
105
+ activejob (= 6.0.3.4)
106
+ activemodel (= 6.0.3.4)
107
+ activerecord (= 6.0.3.4)
108
+ activestorage (= 6.0.3.4)
109
+ activesupport (= 6.0.3.4)
109
110
  bundler (>= 1.3.0)
110
- railties (= 6.0.3.3)
111
+ railties (= 6.0.3.4)
111
112
  sprockets-rails (>= 2.0.0)
112
113
  rails-dom-testing (2.0.3)
113
114
  activesupport (>= 4.2.0)
114
115
  nokogiri (>= 1.6)
115
116
  rails-html-sanitizer (1.3.0)
116
117
  loofah (~> 2.3)
117
- railties (6.0.3.3)
118
- actionpack (= 6.0.3.3)
119
- activesupport (= 6.0.3.3)
118
+ railties (6.0.3.4)
119
+ actionpack (= 6.0.3.4)
120
+ activesupport (= 6.0.3.4)
120
121
  method_source
121
122
  rake (>= 0.8.7)
122
123
  thor (>= 0.20.3, < 2.0)
@@ -155,6 +156,7 @@ PLATFORMS
155
156
  ruby
156
157
 
157
158
  DEPENDENCIES
159
+ mysql2 (~> 0.5.3)
158
160
  pg (>= 0.18)
159
161
  pry (~> 0.13.1)
160
162
  rspec (~> 3.9.0)
data/README.md CHANGED
@@ -70,7 +70,6 @@ YeSQL('top_10_users_in_x_country', { country: 'Cuba', country_id: 1, limit: 6 })
70
70
  ```
71
71
 
72
72
  - If the query doesn't have bindings, but they're provided they're just omitted.
73
- TODO: update this with link to the error.
74
73
  - If the query has bindings, but nothing is provided, it raises a `NotImplementedError` exception.
75
74
 
76
75
 
@@ -145,21 +144,21 @@ YeSQL('users', cache: { expires_in: 1.hour })
145
144
 
146
145
  ## Configuration
147
146
 
148
- For default `YeSQL` looks for the _.sql_ files defined under the `app/yesql/` folder but you can update it to use any folder you need. For that you can create a Ruby file under the `config/initializers/` folder as:
147
+ For default `YeSQL` looks for the _.sql_ files defined under the `app/yesql/` folder but you can update it to use any folder you need. For that you can create a Ruby file under the `config/initializers/` with the following content:
149
148
 
150
149
  ```ruby
151
- YeSQL.config.path = 'path'
150
+ ::YeSQL.configure { |config| config.path = 'path' }
152
151
  ```
153
152
 
154
153
  After saving the file and restarting the server the files are going to be read from the given folder.
155
154
 
156
- You can check at anytime what's the configuration path by inspecting the YeSQL `config` object:
155
+ You can check at anytime what's the configuration path by inspecting the ::YeSQL `config` object:
157
156
 
158
157
  ```ruby
159
- YeSQL.config
160
- # <Dry::Configurable::Config values={:path=>"path"}>
161
- Yesql.config.path
162
- # "path"
158
+ ::YeSQL.config
159
+ # => #<YeSQL::Config::Configuration:0x00007feea1aa2ef8 @path="app/yesql">
160
+ ::YeSQL.config.path
161
+ # => "app/yesql"
163
162
  ```
164
163
 
165
164
 
@@ -167,7 +166,7 @@ Yesql.config.path
167
166
 
168
167
  - Clone the repository.
169
168
  - Install the gem dependencies.
170
- - Make sure to create the database used in the dummy Rails application in the spec/ folder.
169
+ - Make sure to create both databases used in the dummy Rails applications (mysql, pg) in the spec/ folder.
171
170
  - Run the tests.
172
171
 
173
172
  ## Contributing
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pry'
4
3
  require 'yesql/version'
5
4
  require 'yesql/config/configuration'
6
5
  require 'yesql/query/performer'
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'yesql'
4
4
 
5
- module YeSQL
5
+ module ::YeSQL
6
6
  module Bindings
7
7
  class Extract
8
+ include ::YeSQL::Common::Adapter
9
+
8
10
  def initialize(indexed_bindings, hash, index, value)
9
11
  @indexed_bindings = indexed_bindings
10
12
  @hash = hash
@@ -19,9 +21,15 @@ module YeSQL
19
21
  end
20
22
 
21
23
  def bind_vars
22
- return "$#{last_val}" unless array?
24
+ if mysql?
25
+ return '?' unless array?
26
+
27
+ Array.new(value.size, '?').join(', ')
28
+ elsif pg?
29
+ return "$#{last_val}" unless array?
23
30
 
24
- value.map.with_index(bind_index) { |_, i| "$#{i}" }.join(', ')
31
+ value.map.with_index(bind_index) { |_, i| "$#{i}" }.join(', ')
32
+ end
25
33
  end
26
34
 
27
35
  def last_val
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module ::YeSQL
6
+ module Common
7
+ module Adapter
8
+ extend Forwardable
9
+
10
+ # `adapter` might be a complex object, but
11
+ # for the sake of brevity it's just a string
12
+ def adapter
13
+ ::ActiveRecord::Base.connection.adapter_name
14
+ end
15
+
16
+ def mysql?
17
+ adapter == 'Mysql2'
18
+ end
19
+
20
+ def pg?
21
+ adapter == 'PostgreSQL'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,6 +3,7 @@
3
3
  require 'yesql'
4
4
  require 'forwardable'
5
5
  require 'yesql/bindings/utils'
6
+ require 'yesql/common/adapter'
6
7
 
7
8
  module YeSQL
8
9
  module Query
@@ -10,6 +11,7 @@ module YeSQL
10
11
  extend Forwardable
11
12
 
12
13
  include ::YeSQL::Bindings::Utils
14
+ include ::YeSQL::Common::Adapter
13
15
 
14
16
  # rubocop:disable Metrics/ParameterLists
15
17
  def initialize(bind_statement:,
@@ -74,8 +76,8 @@ module YeSQL
74
76
  # TODO: move this somewhere else.
75
77
  def binds
76
78
  statement_binds(extractor)
77
- .sort_by { |_, position| position.tr('$', '').to_i }
78
- .uniq
79
+ .sort_by { |_, position| position.to_s.tr('$', '').to_i }
80
+ .tap { |x| break(mysql? ? x : x.uniq) }
79
81
  .map(&:first)
80
82
  .flatten
81
83
  .each_slice(2)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YeSQL
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
  spec.add_dependency 'rails', '>= 5.0'
24
+ spec.add_development_dependency 'mysql2', '~> 0.5.3'
24
25
  spec.add_development_dependency 'pg', '>= 0.18'
25
26
  spec.add_development_dependency 'pry', '~> 0.13.1'
26
27
  spec.add_development_dependency 'rspec', '~> 3.9.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yesql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastián Palma
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-18 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.3
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pg
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +100,7 @@ files:
86
100
  - lib/yesql/bindings/extract.rb
87
101
  - lib/yesql/bindings/extractor.rb
88
102
  - lib/yesql/bindings/utils.rb
103
+ - lib/yesql/common/adapter.rb
89
104
  - lib/yesql/config/configuration.rb
90
105
  - lib/yesql/errors/cache_expiration_error.rb
91
106
  - lib/yesql/errors/file_path_does_not_exist_error.rb