inquery 1.0.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: inquery 1.0.0 ruby lib
2
+ # stub: inquery 1.0.5 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "inquery".freeze
6
- s.version = "1.0.0"
6
+ s.version = "1.0.5"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2017-05-16"
12
- s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "doc/Inquery.html".freeze, "doc/Inquery/Exceptions.html".freeze, "doc/Inquery/Exceptions/Base.html".freeze, "doc/Inquery/Exceptions/InvalidRelation.html".freeze, "doc/Inquery/Exceptions/UnknownCallSignature.html".freeze, "doc/Inquery/Mixins.html".freeze, "doc/Inquery/Mixins/RelationValidation.html".freeze, "doc/Inquery/Mixins/RelationValidation/ClassMethods.html".freeze, "doc/Inquery/Mixins/SchemaValidation.html".freeze, "doc/Inquery/Mixins/SchemaValidation/ClassMethods.html".freeze, "doc/Inquery/Query.html".freeze, "doc/Inquery/Query/Chainable.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "inquery.gemspec".freeze, "lib/inquery.rb".freeze, "lib/inquery/exceptions.rb".freeze, "lib/inquery/mixins/relation_validation.rb".freeze, "lib/inquery/mixins/schema_validation.rb".freeze, "lib/inquery/query.rb".freeze, "lib/inquery/query/chainable.rb".freeze, "test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/inquery/query/chainable_test.rb".freeze, "test/inquery/query_test.rb".freeze, "test/queries/group/fetch_as_json.rb".freeze, "test/queries/group/fetch_green.rb".freeze, "test/queries/group/fetch_red.rb".freeze, "test/queries/group/filter_with_color.rb".freeze, "test/queries/user/fetch_all.rb".freeze, "test/queries/user/fetch_in_group.rb".freeze, "test/queries/user/fetch_in_group_rel.rb".freeze, "test/test_helper.rb".freeze]
13
- s.rubygems_version = "2.6.6".freeze
11
+ s.date = "2020-11-25"
12
+ s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "doc/Inquery.html".freeze, "doc/Inquery/Exceptions.html".freeze, "doc/Inquery/Exceptions/Base.html".freeze, "doc/Inquery/Exceptions/InvalidRelation.html".freeze, "doc/Inquery/Exceptions/UnknownCallSignature.html".freeze, "doc/Inquery/Mixins.html".freeze, "doc/Inquery/Mixins/RawSqlUtils.html".freeze, "doc/Inquery/Mixins/RelationValidation.html".freeze, "doc/Inquery/Mixins/RelationValidation/ClassMethods.html".freeze, "doc/Inquery/Mixins/SchemaValidation.html".freeze, "doc/Inquery/Mixins/SchemaValidation/ClassMethods.html".freeze, "doc/Inquery/Query.html".freeze, "doc/Inquery/Query/Chainable.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "inquery.gemspec".freeze, "lib/inquery.rb".freeze, "lib/inquery/exceptions.rb".freeze, "lib/inquery/mixins/raw_sql_utils.rb".freeze, "lib/inquery/mixins/relation_validation.rb".freeze, "lib/inquery/mixins/schema_validation.rb".freeze, "lib/inquery/query.rb".freeze, "lib/inquery/query/chainable.rb".freeze, "test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/inquery/query/chainable_test.rb".freeze, "test/inquery/query_test.rb".freeze, "test/queries/group/fetch_as_json.rb".freeze, "test/queries/group/fetch_green.rb".freeze, "test/queries/group/fetch_red.rb".freeze, "test/queries/group/filter_with_color.rb".freeze, "test/queries/user/fetch_all.rb".freeze, "test/queries/user/fetch_in_group.rb".freeze, "test/queries/user/fetch_in_group_rel.rb".freeze, "test/test_helper.rb".freeze]
13
+ s.rubygems_version = "3.0.3".freeze
14
14
  s.summary = "A skeleton that allows extracting queries into atomic, reusable classes.".freeze
15
15
  s.test_files = ["test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/inquery/query/chainable_test.rb".freeze, "test/inquery/query_test.rb".freeze, "test/queries/group/fetch_as_json.rb".freeze, "test/queries/group/fetch_green.rb".freeze, "test/queries/group/fetch_red.rb".freeze, "test/queries/group/filter_with_color.rb".freeze, "test/queries/user/fetch_all.rb".freeze, "test/queries/user/fetch_in_group.rb".freeze, "test/queries/user/fetch_in_group_rel.rb".freeze, "test/test_helper.rb".freeze]
16
16
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.specification_version = 4
19
19
 
20
20
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
21
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.3"])
21
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
22
22
  s.add_development_dependency(%q<rake>.freeze, [">= 0"])
23
23
  s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
24
24
  s.add_development_dependency(%q<haml>.freeze, [">= 0"])
@@ -28,9 +28,9 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency(%q<minitest>.freeze, [">= 0"])
29
29
  s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
30
30
  s.add_runtime_dependency(%q<activerecord>.freeze, [">= 0"])
31
- s.add_runtime_dependency(%q<schemacop>.freeze, ["~> 2"])
31
+ s.add_runtime_dependency(%q<schemacop>.freeze, [">= 2.0"])
32
32
  else
33
- s.add_dependency(%q<bundler>.freeze, ["~> 1.3"])
33
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
34
34
  s.add_dependency(%q<rake>.freeze, [">= 0"])
35
35
  s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
36
36
  s.add_dependency(%q<haml>.freeze, [">= 0"])
@@ -40,10 +40,10 @@ Gem::Specification.new do |s|
40
40
  s.add_dependency(%q<minitest>.freeze, [">= 0"])
41
41
  s.add_dependency(%q<activesupport>.freeze, [">= 0"])
42
42
  s.add_dependency(%q<activerecord>.freeze, [">= 0"])
43
- s.add_dependency(%q<schemacop>.freeze, ["~> 2"])
43
+ s.add_dependency(%q<schemacop>.freeze, [">= 2.0"])
44
44
  end
45
45
  else
46
- s.add_dependency(%q<bundler>.freeze, ["~> 1.3"])
46
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
47
47
  s.add_dependency(%q<rake>.freeze, [">= 0"])
48
48
  s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
49
49
  s.add_dependency(%q<haml>.freeze, [">= 0"])
@@ -53,6 +53,6 @@ Gem::Specification.new do |s|
53
53
  s.add_dependency(%q<minitest>.freeze, [">= 0"])
54
54
  s.add_dependency(%q<activesupport>.freeze, [">= 0"])
55
55
  s.add_dependency(%q<activerecord>.freeze, [">= 0"])
56
- s.add_dependency(%q<schemacop>.freeze, ["~> 2"])
56
+ s.add_dependency(%q<schemacop>.freeze, [">= 2.0"])
57
57
  end
58
58
  end
@@ -6,5 +6,6 @@ require 'schemacop'
6
6
  require 'inquery/exceptions'
7
7
  require 'inquery/mixins/schema_validation'
8
8
  require 'inquery/mixins/relation_validation'
9
+ require 'inquery/mixins/raw_sql_utils'
9
10
  require 'inquery/query'
10
11
  require 'inquery/query/chainable'
@@ -0,0 +1,23 @@
1
+ module Inquery
2
+ module Mixins
3
+ module RawSqlUtils
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ # Sanitizes the SQL and substitutes in the supplied variables. Relies on
8
+ # `sanitize_sql_array` from ActiveRecord.
9
+ def san(sql, *variables)
10
+ ActiveRecord::Base.send(:sanitize_sql_array, [sql, *variables])
11
+ end
12
+
13
+ # Executes the sql on the connection provided by calling `connection`,
14
+ # which means that the method needs to be defined where this mixin is
15
+ # included. The sql passed in should be sanitized.
16
+ # Returns an instance of `ActiveRecord::Result`.
17
+ def exec_query(sql)
18
+ connection.exec_query(sql, self.class.to_s)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,11 +3,20 @@ module Inquery
3
3
  module RelationValidation
4
4
  extend ActiveSupport::Concern
5
5
 
6
- OPTIONS_SCHEMA = Schemacop::Schema.new do
7
- opt :class, :string
8
- opt :fields, :integer
9
- opt :default_select, :symbol
10
- opt :default, :object, classes: [Proc, FalseClass]
6
+ if defined?(Schemacop::V2)
7
+ OPTIONS_SCHEMA = Schemacop::Schema.new(:hash) do
8
+ str? :class
9
+ int? :fields
10
+ sym? :default_select
11
+ rby? :default, [Proc, FalseClass]
12
+ end
13
+ else
14
+ OPTIONS_SCHEMA = Schemacop::Schema.new do
15
+ opt :class, :string
16
+ opt :fields, :integer
17
+ opt :default_select, :symbol
18
+ opt :default, :object, classes: [Proc, FalseClass]
19
+ end
11
20
  end
12
21
 
13
22
  DEFAULT_OPTIONS = {
@@ -9,10 +9,21 @@ module Inquery
9
9
  end
10
10
 
11
11
  module ClassMethods
12
- def schema(*args, &block)
13
- schema = Schemacop::Schema.new(*args, &block)
12
+ def schema2(*args, &block)
13
+ self._schema = Schemacop::Schema.new(*args, &block)
14
+ end
14
15
 
15
- self._schema = schema
16
+ def schema3(reference = nil, **options, &block)
17
+ if reference
18
+ self._schema = Schemacop::Schema3.new(:reference, options.merge(path: reference))
19
+ else
20
+ self._schema = Schemacop::Schema3.new(:hash, **options, &block)
21
+ end
22
+ end
23
+
24
+ # @see schema2
25
+ def schema(*args, &block)
26
+ schema2(*args, &block)
16
27
  end
17
28
  end
18
29
  end
@@ -1,6 +1,7 @@
1
1
  module Inquery
2
2
  class Query
3
3
  include Mixins::SchemaValidation
4
+ include Mixins::RawSqlUtils
4
5
 
5
6
  attr_reader :params
6
7
 
@@ -21,8 +22,8 @@ module Inquery
21
22
  def initialize(params = {})
22
23
  @params = params
23
24
 
24
- if self.class._schema
25
- self.class._schema.validate!(@params)
25
+ if _schema
26
+ @params = _schema.validate!(@params)
26
27
  end
27
28
  end
28
29
 
@@ -46,5 +47,11 @@ module Inquery
46
47
  def osparams
47
48
  @osparams ||= OpenStruct.new(params)
48
49
  end
50
+
51
+ # Provides a connection to the database. May be overridden if a different
52
+ # connection is desired. Defaults to `ActiveRecord::Base.connection`.
53
+ def connection
54
+ ActiveRecord::Base.connection
55
+ end
49
56
  end
50
57
  end
@@ -19,6 +19,11 @@ module Inquery
19
19
  super(params)
20
20
  end
21
21
 
22
+ # Override the connection method to (re-)use the connection of the relation
23
+ def connection
24
+ @relation.connection
25
+ end
26
+
22
27
  private
23
28
 
24
29
  def parse_init_args(*args)
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -154,18 +154,18 @@ dependencies:
154
154
  name: schemacop
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '2'
159
+ version: '2.0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '2'
167
- description:
168
- email:
166
+ version: '2.0'
167
+ description:
168
+ email:
169
169
  executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
@@ -175,6 +175,7 @@ files:
175
175
  - ".rubocop.yml"
176
176
  - ".travis.yml"
177
177
  - ".yardopts"
178
+ - CHANGELOG.md
178
179
  - Gemfile
179
180
  - LICENSE
180
181
  - README.md
@@ -187,6 +188,7 @@ files:
187
188
  - doc/Inquery/Exceptions/InvalidRelation.html
188
189
  - doc/Inquery/Exceptions/UnknownCallSignature.html
189
190
  - doc/Inquery/Mixins.html
191
+ - doc/Inquery/Mixins/RawSqlUtils.html
190
192
  - doc/Inquery/Mixins/RelationValidation.html
191
193
  - doc/Inquery/Mixins/RelationValidation/ClassMethods.html
192
194
  - doc/Inquery/Mixins/SchemaValidation.html
@@ -210,6 +212,7 @@ files:
210
212
  - inquery.gemspec
211
213
  - lib/inquery.rb
212
214
  - lib/inquery/exceptions.rb
215
+ - lib/inquery/mixins/raw_sql_utils.rb
213
216
  - lib/inquery/mixins/relation_validation.rb
214
217
  - lib/inquery/mixins/schema_validation.rb
215
218
  - lib/inquery/query.rb
@@ -226,10 +229,10 @@ files:
226
229
  - test/queries/user/fetch_in_group.rb
227
230
  - test/queries/user/fetch_in_group_rel.rb
228
231
  - test/test_helper.rb
229
- homepage:
232
+ homepage:
230
233
  licenses: []
231
234
  metadata: {}
232
- post_install_message:
235
+ post_install_message:
233
236
  rdoc_options: []
234
237
  require_paths:
235
238
  - lib
@@ -244,9 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
247
  - !ruby/object:Gem::Version
245
248
  version: '0'
246
249
  requirements: []
247
- rubyforge_project:
248
- rubygems_version: 2.6.8
249
- signing_key:
250
+ rubygems_version: 3.1.4
251
+ signing_key:
250
252
  specification_version: 4
251
253
  summary: A skeleton that allows extracting queries into atomic, reusable classes.
252
254
  test_files: