n_1_finder 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 3e389a1727607242ce3f686e8db20fcdc33ca3ed
4
- data.tar.gz: 49a22b9adf74c1c1f329e1b2970e647659cef94b
3
+ metadata.gz: ab7427d8a228787f6c0ec69a45911a03c2db8d88
4
+ data.tar.gz: e2466e6c7fe33f5e262938fd74e465eda7e91c6d
5
5
  SHA512:
6
- metadata.gz: 1e240024894cf46304884f59d98d9396f33218f5069e6b468cc0104df9d75e5254472639ca7aa5856ce0e2a2a0f829f4852f89aafd82003aa079277cee58bd0c
7
- data.tar.gz: 17266b8396fdcb2cbe1fe0d710364efee3154963cdaa9f4dbe19cb63a3c70a6af2f3c1aa87bc9d41124e03824908ae88eefb2262ef5263621440487cc221811d
6
+ metadata.gz: c45009c7542f01b595f26450c890e85b3904b1d4635d3df4043b66388f145dc2423c1226ea045cadeed2034b922a772775a937fedc0a676237c5bee510acbae6
7
+ data.tar.gz: d3037ad0f27c81ff23bfbc9458708cc8a28d9cba4d0e54384f581135d7f83a3492c93dc1d4a7ff9d26cb745013dd476772006860efedd610b5a4814203bab3f3
data/Readme.md CHANGED
@@ -1,20 +1,22 @@
1
1
  # N+1 Finder
2
- This gem can help you to find N+1 queries.
2
+ [![Gem Version](https://badge.fury.io/rb/n_1_finder.svg)](https://badge.fury.io/rb/n_1_finder)
3
+ [![Build Status](https://api.travis-ci.org/aglushkov/n1_finder.svg?branch=master)](https://travis-ci.org/aglushkov/n1_finder)
4
+ [![Inline docs](http://inch-ci.org/github/aglushkov/n1_finder.svg?branch=master)](http://inch-ci.org/github/aglushkov/n1_finder)
5
+
6
+ This gem helps to find N+1 queries.
3
7
 
4
8
  It works with `ActiveRecord` and `Sequel`.
5
9
 
6
10
  And tested with `postgresql`, `mysql` and `sqlite`.
7
11
 
8
12
  ## Installation
9
- With Gemfile: `gem 'n1_finder', group: :development`
10
-
11
- Without Gemfile: `gem install n1_finder`
13
+ `gem 'n_1_finder', group: :development`
12
14
 
13
15
  ## Configuration
14
16
  ### Logger
15
17
  Default is `Logger.new(STDOUT)`
16
18
 
17
- `N+1 Finder` logger can be any instance of `Logger` class.
19
+ Logger can be any instance of `Logger` class.
18
20
 
19
21
  ```ruby
20
22
  N1Finder.logger = Logger.new('log/n1.log')
@@ -25,14 +27,29 @@ Default is `:active_record` if you have activerecord gem installed.
25
27
 
26
28
  Default is `:sequel` if you have sequel gem installed.
27
29
 
28
- You can set ORM explicitly
30
+ Allowed values are `:active_record` and `:sequel`
31
+
29
32
  ```ruby
30
33
  N1Finder.orm = :active_record
31
34
  ```
32
35
 
33
36
  ## Using
37
+ Include middleware to your Rack app:
38
+ ```ruby
39
+ # Rails
40
+ class Application < Rails::Application
41
+ config.middleware.use(N1Finder::Middleware)
42
+ ...
43
+ # Grape
44
+ class YourAPI < Grape::API
45
+ use N1Finder::Middleware
46
+ ...
47
+ # Padrino
48
+ class YourAPP < Padrino::Application
49
+ use N1Finder::Middleware
50
+ ```
34
51
 
35
- ### Directly
52
+ Or use it directly:
36
53
  ```ruby
37
54
  N1Finder.find do
38
55
  User.all.map { |user| user.comments.to_a }
@@ -51,24 +68,18 @@ N+1 QUERY DETECTED:
51
68
  SELECT "comments".* FROM "comments" WHERE "comments"."user_id" = $1, user_id = 947
52
69
  ```
53
70
 
54
- ### Middleware
55
- `N+1 Finder` provides middleware that you can include to any rack application to find N+1 queries in your requests:
56
-
57
- #### Rails
58
- ```ruby
59
- class Application < Rails::Application
60
- config.middleware.use(N1Finder::Middleware)
71
+ ## Running tests
72
+ - Copy `spec/.env.example` file to `spec/.env` and set database credentials.
73
+ ```bash
74
+ cp spec/.env.example spec/.env
61
75
  ```
62
76
 
63
- #### Grape
64
- ```ruby
65
- class YourAPI < Grape::API
66
- use N1Finder::Middleware
67
- ```
68
-
69
- #### Padrino
70
- ```ruby
71
- class YourAPP < Padrino::Application
72
- use N1Finder::Middleware
77
+ - Load this variables into your system.
78
+ ```bash
79
+ source spec/.env
73
80
  ```
74
81
 
82
+ - Run tests.
83
+ ```bash
84
+ rspec
85
+ ```
@@ -1,4 +1,4 @@
1
1
  class N1Finder
2
2
  # Gem version
3
- VERSION = '0.0.2'.freeze
3
+ VERSION = '0.0.3'.freeze
4
4
  end
data/spec/.env.example ADDED
@@ -0,0 +1,7 @@
1
+ export PG_USERNAME=
2
+ export PG_PASSWORD=
3
+ export PG_DATABASE=
4
+
5
+ export MYSQL_USERNAME=
6
+ export MYSQL_PASSWORD=
7
+ export MYSQL_DATABASE=
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'pry-nav'
1
+ require 'pry-nav' if RUBY_PLATFORM != 'java'
2
2
  require 'bundler/setup'
3
3
  Bundler.setup
4
4
 
@@ -1,58 +1,40 @@
1
- require 'yaml'
1
+ # rubocop:disable Metrics/LineLength
2
2
 
3
3
  module ORMHelpers
4
- SECRETS = YAML.load(File.open('spec/secrets.yml'))
5
-
6
- DB_PARAMS = {
7
- active_record: {
8
- sqlite: {
9
- adapter: 'sqlite3',
10
- database: ':memory:'
11
- },
12
- pg: {
13
- adapter: 'postgresql',
14
- host: 'localhost',
15
- username: SECRETS[:pg][:username].to_s,
16
- password: SECRETS[:pg][:password].to_s,
17
- database: SECRETS[:pg][:database].to_s
4
+ DB_PARAMS = Hash.new { |hash, _key| hash['mri'] }.update(
5
+ 'mri' => {
6
+ active_record: {
7
+ sqlite: 'sqlite3::memory:',
8
+ pg: "postgres://#{ENV['PG_USERNAME']}:#{ENV['PG_PASSWORD']}@localhost/#{ENV['PG_DATABASE']}",
9
+ mysql: "mysql2://#{ENV['MYSQL_USERNAME']}:#{ENV['MYSQL_PASSWORD']}@localhost/#{ENV['MYSQL_DATABASE']}"
18
10
  },
19
- mysql: {
20
- adapter: 'mysql',
21
- host: 'localhost',
22
- username: SECRETS[:mysql][:username].to_s,
23
- password: SECRETS[:mysql][:password].to_s,
24
- database: SECRETS[:mysql][:database].to_s
11
+ sequel: {
12
+ sqlite: 'sqlite::memory:',
13
+ pg: "postgres://#{ENV['PG_USERNAME']}:#{ENV['PG_PASSWORD']}@localhost/#{ENV['PG_DATABASE']}",
14
+ mysql: "mysql2://#{ENV['MYSQL_USERNAME']}:#{ENV['MYSQL_PASSWORD']}@localhost/#{ENV['MYSQL_DATABASE']}"
25
15
  }
26
16
  },
27
- sequel: {
28
- sqlite: {
29
- adapter: 'sqlite',
30
- database: ':memory:'
31
- },
32
- pg: {
33
- adapter: 'postgres',
34
- host: 'localhost',
35
- username: SECRETS[:pg][:username].to_s,
36
- password: SECRETS[:pg][:password].to_s,
37
- database: SECRETS[:pg][:database].to_s
17
+ 'java' => {
18
+ active_record: {
19
+ sqlite: 'sqlite3::memory:',
20
+ pg: "postgresql://#{ENV['PG_USERNAME']}:#{ENV['PG_PASSWORD']}@localhost/#{ENV['PG_DATABASE']}",
21
+ mysql: "mysql2://#{ENV['MYSQL_USERNAME']}:#{ENV['MYSQL_PASSWORD']}@localhost/#{ENV['MYSQL_DATABASE']}"
38
22
  },
39
- mysql: {
40
- adapter: 'mysql',
41
- host: 'localhost',
42
- username: SECRETS[:mysql][:username].to_s,
43
- password: SECRETS[:mysql][:password].to_s,
44
- database: SECRETS[:mysql][:database].to_s
23
+ sequel: {
24
+ sqlite: 'jdbc:sqlite::memory:',
25
+ pg: "jdbc:postgresql://localhost/#{ENV['PG_DATABASE']}?user=#{ENV['PG_USERNAME']}&password=#{ENV['PG_PASSWORD']}",
26
+ mysql: "jdbc:mysql://localhost/#{ENV['MYSQL_DATABASE']}?user=#{ENV['MYSQL_USERNAME']}&password=#{ENV['MYSQL_PASSWORD']}"
45
27
  }
46
28
  }
47
- }.freeze
29
+ )
48
30
 
49
31
  def connect_sequel(adapter)
50
- Sequel::Model.db = Sequel.connect(DB_PARAMS[:sequel][adapter])
32
+ Sequel::Model.db = Sequel.connect(DB_PARAMS[RUBY_PLATFORM][:sequel][adapter])
51
33
  TestSequelMigration.up
52
34
  end
53
35
 
54
36
  def connect_active_record(adapter)
55
- ActiveRecord::Base.establish_connection(DB_PARAMS[:active_record][adapter])
37
+ ActiveRecord::Base.establish_connection(DB_PARAMS[RUBY_PLATFORM][:active_record][adapter])
56
38
  silence_stream(STDOUT) { TestActiveRecordMigration.up }
57
39
  end
58
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: n_1_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Glushkov
@@ -28,6 +28,7 @@ files:
28
28
  - lib/n_1_finder/query.rb
29
29
  - lib/n_1_finder/storage.rb
30
30
  - lib/n_1_finder/version.rb
31
+ - spec/.env.example
31
32
  - spec/n_1_finder/adapters/active_record_adapter_spec.rb
32
33
  - spec/n_1_finder/adapters/null_adapter_spec.rb
33
34
  - spec/n_1_finder/adapters/sequel_adapter_spec.rb
@@ -43,7 +44,6 @@ files:
43
44
  - spec/n_1_finder/query_spec.rb
44
45
  - spec/n_1_finder/storage_spec.rb
45
46
  - spec/n_1_finder_spec.rb
46
- - spec/secrets.yml.example
47
47
  - spec/shared_examples/adapter.rb
48
48
  - spec/spec_helper.rb
49
49
  - spec/support/n_1_helpers.rb
@@ -1,9 +0,0 @@
1
- :pg:
2
- :username: XXX
3
- :password: XXX
4
- :database: XXX
5
-
6
- :mysql:
7
- :username: XXX
8
- :password: XXX
9
- :database: XXX