rom-yesql 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,69 @@
1
- ## v0.2.0 2015-08-19
1
+ ## 1.0.0 2020-12-06
2
2
 
3
- Updated to work with ROM 0.9.0
3
+ Updated to work with rom 6.0.0 (@mrship)
4
4
 
5
- [Compare v0.1.1...v0.2.0](https://github.com/rom-rb/rom-yaml/compare/v0.1.0...v0.2.0)
6
5
 
7
- ## v0.1.1 2015-07-27
6
+ [Compare v0.5.1...v1.0.0](https://github.com/rom-rb/rom-yesql/compare/v0.5.1...v1.0.0)
7
+
8
+ ## 0.5.1 2017-03-30
9
+
10
+ Updated rom dependency (flash-gordon)
11
+
12
+
13
+ [Compare v0.5.0...v0.5.1](https://github.com/rom-rb/rom-yesql/compare/v0.5.0...v0.5.1)
14
+
15
+ ## 0.5.0 2017-03-28
16
+
17
+ Updated to work with rom 3.2.0 (flash-gordon)
18
+
19
+
20
+ [Compare v0.4.0...v0.5.0](https://github.com/rom-rb/rom-yesql/compare/v0.4.0...v0.5.0)
21
+
22
+ ## 0.4.0 2017-02-10
23
+
24
+ Updated to work with rom 3.0.0
25
+
26
+
27
+ [Compare v0.3.0...v0.4.0](https://github.com/rom-rb/rom-yesql/compare/v0.3.0...v0.4.0)
28
+
29
+ ## 0.3.0 2016-07-31
30
+
31
+ Updated to work with rom 2.0.0
32
+
33
+
34
+ [Compare v0.2.0...v0.3.0](https://github.com/rom-rb/rom-yesql/compare/v0.2.0...v0.3.0)
35
+
36
+ ## 0.2.0 2015-08-19
37
+
38
+ Updated to work with rom 0.9.0
39
+
40
+
41
+ [Compare v0.1.1...v0.2.0](https://github.com/rom-rb/rom-yesql/compare/v0.1.1...v0.2.0)
42
+
43
+ ## 0.1.1 2015-07-27
44
+
45
+ Updated to work with rom 0.8 (solnic)
8
46
 
9
47
  ### Changed
10
48
 
11
- * Updated to work with ROM 0.8 (solnic)
49
+ - Updated to work with rom 0.8 (solnic)
50
+
51
+ [Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-yesql/compare/v0.1.0...v0.1.1)
52
+
53
+ ## 0.1.0 2015-03-22
54
+
55
+ Bump rom dep to 0.6.0 final
56
+
12
57
 
13
- [Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-yaml/compare/v0.1.0...v0.1.1)
58
+ [Compare v0.0.2...v0.1.0](https://github.com/rom-rb/rom-yesql/compare/v0.0.2...v0.1.0)
14
59
 
15
- ## v0.1.0 2015-03-22
60
+ ## 0.0.2 2015-03-21
16
61
 
17
- Bump ROM dep to 0.6.0 final
62
+ Update to work with rom 0.6.0
18
63
 
19
- ## v0.0.2 2015-03-21
20
64
 
21
- Update to work with ROM 0.6.0
65
+ [Compare v0.0.1...v0.0.2](https://github.com/rom-rb/rom-yesql/compare/v0.0.1...v0.0.2)
22
66
 
23
- ## v0.0.1 2015-03-01
67
+ ## 0.0.1 2015-03-01
24
68
 
25
69
  First public release \o/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
@@ -0,0 +1,29 @@
1
+ # Issue Guidelines
2
+
3
+ ## Reporting bugs
4
+
5
+ If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
6
+
7
+ ## Reporting feature requests
8
+
9
+ Report a feature request **only after discussing it first on [discourse.rom-rb.org](https://discourse.rom-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
+
11
+ ## Reporting questions, support requests, ideas, concerns etc.
12
+
13
+ **PLEASE DON'T** - use [discourse.rom-rb.org](http://discourse.rom-rb.org) instead.
14
+
15
+ # Pull Request Guidelines
16
+
17
+ A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
18
+
19
+ Other requirements:
20
+
21
+ 1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
22
+ 2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
23
+ 3) Add API documentation if it's a new feature
24
+ 4) Update API documentation if it changes an existing feature
25
+ 5) Bonus points for sending a PR which updates user documentation in the `docsite` directory
26
+
27
+ # Asking for help
28
+
29
+ If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.rom-rb.org](https://discourse.rom-rb.org) or join [our chat](https://rom-rb.zulipchat.com).
data/Gemfile CHANGED
@@ -1,20 +1,19 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
7
+ eval_gemfile "Gemfile.devtools"
8
+
5
9
  group :test do
6
- gem 'rom', github: 'rom-rb/rom', branch: 'master'
7
- gem 'inflecto'
8
- gem 'rspec', '~> 3.1'
9
- gem 'codeclimate-test-reporter', require: false
10
- gem 'sqlite3', platforms: [:mri, :rbx]
11
- gem 'jdbc-sqlite3', platforms: :jruby
10
+ gem "codeclimate-test-reporter", require: false
11
+ gem "inflecto"
12
+ gem "jdbc-sqlite3", platforms: :jruby
13
+ gem "rspec", "~> 3.5"
14
+ gem "sqlite3", platforms: %i[mri rbx]
12
15
  end
13
16
 
14
17
  group :tools do
15
- gem 'guard'
16
- gem 'byebug', platforms: [:mri]
17
- gem 'guard-rspec'
18
- gem 'guard-rubocop'
19
- gem 'rubocop', '~> 0.28'
18
+ gem "byebug", platforms: [:mri]
20
19
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this file is managed by rom-rb/devtools project
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ group :test do
8
+ gem "simplecov", require: false, platforms: :ruby
9
+ gem "simplecov-cobertura", require: false, platforms: :ruby
10
+
11
+ gem "warning" if RUBY_VERSION >= "2.4.0"
12
+ end
13
+
14
+ group :tools do
15
+ # this is the same version that we use on codacy
16
+ gem "rubocop", "0.82.0"
17
+ end
data/Guardfile CHANGED
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  group :red_green_refactor, halt_on_fail: true do
2
4
  guard :rspec, cmd: "rspec", all_on_start: true do
3
5
  # run all specs if Gemfile.lock is modified
4
- watch('Gemfile.lock') { 'spec' }
6
+ watch("Gemfile.lock") { "spec" }
5
7
 
6
8
  # run all specs if any library code is modified
7
- watch(%r{\Alib/.+\.rb\z}) { 'spec' }
9
+ watch(%r{\Alib/.+\.rb\z}) { "spec" }
8
10
 
9
11
  # run all specs if supporting files are modified
10
- watch('spec/spec_helper.rb') { 'spec' }
11
- watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
12
+ watch("spec/spec_helper.rb") { "spec" }
13
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { "spec" }
12
14
 
13
15
  # run a spec if it is modified
14
16
  watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
15
17
 
16
- notification :tmux, display_message: true if ENV.key?('TMUX')
18
+ notification :tmux, display_message: true if ENV.key?("TMUX")
17
19
  end
18
20
 
19
21
  guard :rubocop do
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2020 rom-rb team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,52 +1,28 @@
1
1
  [gem]: https://rubygems.org/gems/rom-yesql
2
- [travis]: https://travis-ci.org/rom-rb/rom-yesql
3
- [gemnasium]: https://gemnasium.com/rom-rb/rom-yesql
4
- [codeclimate]: https://codeclimate.com/github/rom-rb/rom-yesql
2
+ [actions]: https://github.com/rom-rb/rom-yesql/actions
3
+ [codacy]: https://www.codacy.com/gh/rom-rb/rom-yesql
4
+ [chat]: https://rom-rb.zulipchat.com
5
5
  [inchpages]: http://inch-ci.org/github/rom-rb/rom-yesql
6
6
 
7
- # ROM::Yesql
7
+ # rom-yesql [![Join the chat at https://rom-rb.zulipchat.com](https://img.shields.io/badge/rom--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/rom-yesql.svg)][gem]
10
- [![Build Status](https://travis-ci.org/rom-rb/rom-yesql.svg?branch=master)][travis]
11
- [![Dependency Status](https://gemnasium.com/rom-rb/rom-yesql.png)][gemnasium]
12
- [![Code Climate](https://codeclimate.com/github/rom-rb/rom-yesql/badges/gpa.svg)][codeclimate]
13
- [![Test Coverage](https://codeclimate.com/github/rom-rb/rom-yesql/badges/coverage.svg)][codeclimate]
10
+ [![CI Status](https://github.com/rom-rb/rom-yesql/workflows/ci/badge.svg)][actions]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/88fbb464691e4666b94e0455468b68bf)][codacy]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/88fbb464691e4666b94e0455468b68bf)][codacy]
14
13
  [![Inline docs](http://inch-ci.org/github/rom-rb/rom-yesql.svg?branch=master)][inchpages]
15
14
 
15
+ ## Links
16
16
 
17
- [Yesql](https://github.com/krisajenkins/yesql)-like adapter for [Ruby Object Mapper](https://github.com/rom-rb/rom).
17
+ * [User documentation](http://rom-rb.org/learn/yesql)
18
+ * [API documentation](http://rubydoc.info/gems/rom-yesql)
18
19
 
19
- ## Installation
20
+ ## Supported Ruby versions
20
21
 
21
- Add this line to your application's Gemfile:
22
+ This library officially supports the following Ruby versions:
22
23
 
23
- ```ruby
24
- gem 'rom-yesql'
25
- ```
26
-
27
- And then execute:
28
-
29
- $ bundle
30
-
31
- Or install it yourself as:
32
-
33
- $ gem install rom-yesql
34
-
35
- ## Synopsis
36
-
37
- ``` ruby
38
- # given sql/my_queries/users.sql includes "SELECT * FROM users WHERE name = '%{name}'"
39
-
40
- ROM.setup(:yesql, ['sqlite://path/to/your/db', path: './sql'])
41
-
42
- class MyQueries < ROM::Relation[:yesql]
43
- end
44
-
45
- rom = ROM.finalize.env
46
-
47
- my_queries = rom.relations[:my_queries]
48
- my_queries.users(name: 'Jane').to_a # => gets the users
49
- ```
24
+ * MRI >= `2.4`
25
+ * jruby >= `9.2`
50
26
 
51
27
  ## License
52
28
 
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
1
4
  require "rspec/core/rake_task"
2
5
 
3
6
  RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,33 @@
1
+ ---
2
+ - version: 1.0.0
3
+ date: '2020-12-06'
4
+ summary: Updated to work with rom 6.0.0 (@mrship)
5
+ - version: 0.5.1
6
+ date: '2017-03-30'
7
+ summary: Updated rom dependency (flash-gordon)
8
+ - version: 0.5.0
9
+ date: '2017-03-28'
10
+ summary: Updated to work with rom 3.2.0 (flash-gordon)
11
+ - version: 0.4.0
12
+ date: '2017-02-10'
13
+ summary: Updated to work with rom 3.0.0
14
+ - version: 0.3.0
15
+ date: '2016-07-31'
16
+ summary: Updated to work with rom 2.0.0
17
+ - version: 0.2.0
18
+ date: '2015-08-19'
19
+ summary: Updated to work with rom 0.9.0
20
+ - version: 0.1.1
21
+ date: '2015-07-27'
22
+ changed:
23
+ - Updated to work with rom 0.8 (solnic)
24
+ summary: Updated to work with rom 0.8 (solnic)
25
+ - version: 0.1.0
26
+ date: '2015-03-22'
27
+ summary: Bump rom dep to 0.6.0 final
28
+ - version: 0.0.2
29
+ date: '2015-03-21'
30
+ summary: Update to work with rom 0.6.0
31
+ - version: 0.0.1
32
+ date: '2015-03-01'
33
+ summary: First public release \o/
@@ -1,3 +1,5 @@
1
- require 'rom' # FIXME: this should not be needed
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rom/yesql'
3
+ require "rom" # FIXME: this should not be needed
4
+
5
+ require "rom/yesql"
@@ -1,2 +1,4 @@
1
- require 'rom/yesql/version'
2
- require 'rom/yesql/gateway'
1
+ # frozen_string_literal: true
2
+
3
+ require "rom/yesql/version"
4
+ require "rom/yesql/gateway"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Yesql
3
5
  # Yesql dataset simply uses a sequel connection to fetch results of a query
@@ -1,95 +1,124 @@
1
- require 'sequel'
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rom/yesql/dataset'
4
- require 'rom/yesql/relation'
3
+ require "sequel"
4
+
5
+ require "rom/initializer"
6
+
7
+ require "rom/yesql/dataset"
8
+ require "rom/yesql/relation"
5
9
 
6
10
  module ROM
7
11
  module Yesql
8
12
  # Yesql gateway exposes access to configured SQL queries
9
13
  #
10
- # @example
11
- # # Load all queries from a specific path
12
- # ROM::Yesql::Gateway.new(uri, path: '/path/to/my_queries')
13
- #
14
- # # Provide queries explicitly using a hash
15
- # ROM::Yesql::Gateway.new(uri, queries: {
16
- # reports: {
17
- # all_users: 'SELECT * FROM users'
18
- # }
19
- # })
20
- #
21
- # # Override default query proc handler
22
- # ROM::Yesql::Gateway.new(uri, query_proc: proc { |name, query, *args|
23
- # # do something to return an sql string
24
- # })
14
+ # Relations created with datasets provided by this gateway automatically
15
+ # expose access to gateway's queries.
25
16
  #
26
17
  # @api public
27
18
  class Gateway < ROM::Gateway
28
- include Options
19
+ extend Initializer
20
+
21
+ adapter :yesql
22
+
23
+ # @!attribute [r] uri
24
+ # @return [String] connection string
25
+ param :uri
29
26
 
30
- option :path, reader: true
31
- option :queries, type: Hash, default: EMPTY_HASH
32
- option :query_proc, reader: true, default: proc { |gateway|
27
+ # @!attribute [r] path
28
+ # @return [String] a path to files with SQL queries
29
+ option :path, reader: true, optional: true
30
+
31
+ # @!attribute [r] queries
32
+ # @return [Hash] a hash with queries
33
+ option :queries, default: -> { EMPTY_HASH }
34
+
35
+ # @!attribute [r] query_proc
36
+ # This defaults to simple interpolation of the query using option hash passed to a relation
37
+ # @return [Proc] custom query proc for pre-processing a query string
38
+ option :query_proc, reader: true, default: proc { |_gateway|
33
39
  proc do |_name, query, opts|
34
40
  query % opts
35
41
  end
36
42
  }
37
43
 
38
- # Return Sequel database connection
39
- #
40
- # @return [Sequel::Database]
41
- #
42
- # @api private
44
+ # @!attribute [r] connection
45
+ # @return [Sequel::Database] Sequel database connection
43
46
  attr_reader :connection
44
47
 
45
- # Hash with loaded queries indexed using dataset names
48
+ # Initializes a yesql gateway
46
49
  #
47
- # @return [Hash]
50
+ # @example
51
+ # # Load all queries from a specific path
52
+ # ROM::Yesql::Gateway.new(uri, path: '/path/to/my_queries')
48
53
  #
49
- # @api private
50
- attr_reader :queries
51
-
52
- # @api private
53
- def initialize(uri, options = {})
54
+ # # Provide queries explicitly using a hash
55
+ # ROM::Yesql::Gateway.new(uri, queries: {
56
+ # reports: {
57
+ # all_users: 'SELECT * FROM users'
58
+ # }
59
+ # })
60
+ #
61
+ # # Override default query proc handler
62
+ # ROM::Yesql::Gateway.new(uri, query_proc: proc { |name, query, *args|
63
+ # # do something to return an sql string
64
+ # })
65
+ #
66
+ # @param uri [String]
67
+ #
68
+ # @param options [Hash]
69
+ # @option :path [String]
70
+ # @option :queries [Hash]
71
+ # @option :query_proc [Proc]
72
+ #
73
+ # @api public
74
+ def initialize(*)
54
75
  super
55
76
  @connection = Sequel.connect(uri, options)
56
- initialize_queries
57
- queries.freeze
77
+ @queries = @queries.merge(load_queries(path)).freeze
58
78
  Relation.query_proc(query_proc)
59
79
  Relation.load_queries(queries)
60
80
  end
61
81
 
62
- # Initialize a dataset
82
+ # Initializes a dataset
63
83
  #
64
84
  # Since all relations use the same dataset we simply create one instance
65
85
  #
86
+ # @return [Dataset]
87
+ #
66
88
  # @api private
67
89
  def dataset(_name)
68
90
  @dataset ||= Dataset.new(connection)
69
91
  end
70
92
 
93
+ # Returns if a dataset with the given name exists
94
+ #
95
+ # This always returns true because all relations use the same dataset
96
+ #
97
+ # @return [True]
98
+ #
71
99
  # @api private
72
100
  def dataset?(_name)
73
- ! @dataset.nil?
101
+ !@dataset.nil?
74
102
  end
75
103
 
76
104
  private
77
105
 
78
- # Load queries from filesystem if :path was provided
106
+ # Loads queries from filesystem if :path was provided
79
107
  #
80
108
  # @api private
81
- def initialize_queries
82
- @queries = options[:queries].dup
83
-
84
- return unless path
85
-
86
- Dir["#{path}/*"].each do |dir|
87
- dataset = File.basename(dir).to_sym
88
- @queries[dataset] = {}
89
- Dir["#{dir}/**/*.sql"].each do |file|
90
- name = File.basename(file, '.*').to_sym
91
- sql = File.read(file)
92
- @queries[dataset][name] = sql.strip
109
+ def load_queries(path)
110
+ if path.nil?
111
+ {}
112
+ else
113
+ Dir["#{path}/*"].each_with_object({}) do |dir, fs_queries|
114
+ dataset = File.basename(dir).to_sym
115
+
116
+ fs_queries[dataset] = Dir["#{dir}/**/*.sql"].each_with_object({}) do |file, ds_queries|
117
+ query_name = File.basename(file, ".*").to_sym
118
+ sql = File.read(file).strip
119
+
120
+ ds_queries[query_name] = sql
121
+ end
93
122
  end
94
123
  end
95
124
  end