sequelize-rails 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a6436860299eb2c361e5301b17ed80ecb416ec1b2a4b0c775b83abb4425a7aa
4
+ data.tar.gz: '095e1782c0742e4682e1de70d49018a80661222cb5db591ddc613294ed1c3e68'
5
+ SHA512:
6
+ metadata.gz: 698afc25ec353669f34a355519f6cac981ec590de4c94bb94ca423693856601fb184a7e226183bc61deb23847f27d8145c76d17eaac698bcef47e2a9d8273394
7
+ data.tar.gz: 97294ea426455e6983b38d552146abcaa8568753ea7013da12f1781cfb8c1c6cd78671f77ab9276bd3e401549a339caf174753879f7de6211808c3b0f714efe2
data/.standard.yml ADDED
@@ -0,0 +1,4 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ignore:
4
+ - 'gemfiles/**/*'
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ gem "sqlite3"
2
+ gem "pg"
3
+
4
+ appraise "rails-6" do
5
+ gem "activerecord", "~> 6"
6
+ gem "rails", "~> 6"
7
+ gem "sequel", "~> 5"
8
+ end
9
+
10
+ appraise "rails-7" do
11
+ gem "activerecord", "~> 7"
12
+ gem "rails", "~> 7"
13
+ gem "sequel", "~> 5"
14
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-26
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sequelize-rails.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,213 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sequelize-rails (0.2.0)
5
+ activerecord (>= 6.0.0)
6
+ rails (>= 6.0.0)
7
+ sequel (>= 5.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (7.0.3)
13
+ actionpack (= 7.0.3)
14
+ activesupport (= 7.0.3)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (>= 0.6.1)
17
+ actionmailbox (7.0.3)
18
+ actionpack (= 7.0.3)
19
+ activejob (= 7.0.3)
20
+ activerecord (= 7.0.3)
21
+ activestorage (= 7.0.3)
22
+ activesupport (= 7.0.3)
23
+ mail (>= 2.7.1)
24
+ net-imap
25
+ net-pop
26
+ net-smtp
27
+ actionmailer (7.0.3)
28
+ actionpack (= 7.0.3)
29
+ actionview (= 7.0.3)
30
+ activejob (= 7.0.3)
31
+ activesupport (= 7.0.3)
32
+ mail (~> 2.5, >= 2.5.4)
33
+ net-imap
34
+ net-pop
35
+ net-smtp
36
+ rails-dom-testing (~> 2.0)
37
+ actionpack (7.0.3)
38
+ actionview (= 7.0.3)
39
+ activesupport (= 7.0.3)
40
+ rack (~> 2.0, >= 2.2.0)
41
+ rack-test (>= 0.6.3)
42
+ rails-dom-testing (~> 2.0)
43
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
+ actiontext (7.0.3)
45
+ actionpack (= 7.0.3)
46
+ activerecord (= 7.0.3)
47
+ activestorage (= 7.0.3)
48
+ activesupport (= 7.0.3)
49
+ globalid (>= 0.6.0)
50
+ nokogiri (>= 1.8.5)
51
+ actionview (7.0.3)
52
+ activesupport (= 7.0.3)
53
+ builder (~> 3.1)
54
+ erubi (~> 1.4)
55
+ rails-dom-testing (~> 2.0)
56
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
+ activejob (7.0.3)
58
+ activesupport (= 7.0.3)
59
+ globalid (>= 0.3.6)
60
+ activemodel (7.0.3)
61
+ activesupport (= 7.0.3)
62
+ activerecord (7.0.3)
63
+ activemodel (= 7.0.3)
64
+ activesupport (= 7.0.3)
65
+ activestorage (7.0.3)
66
+ actionpack (= 7.0.3)
67
+ activejob (= 7.0.3)
68
+ activerecord (= 7.0.3)
69
+ activesupport (= 7.0.3)
70
+ marcel (~> 1.0)
71
+ mini_mime (>= 1.1.0)
72
+ activesupport (7.0.3)
73
+ concurrent-ruby (~> 1.0, >= 1.0.2)
74
+ i18n (>= 1.6, < 2)
75
+ minitest (>= 5.1)
76
+ tzinfo (~> 2.0)
77
+ ansi (1.5.0)
78
+ appraisal (2.4.1)
79
+ bundler
80
+ rake
81
+ thor (>= 0.14.0)
82
+ ast (2.4.2)
83
+ builder (3.2.4)
84
+ coderay (1.1.3)
85
+ concurrent-ruby (1.1.10)
86
+ crass (1.0.6)
87
+ digest (3.1.0)
88
+ erubi (1.10.0)
89
+ globalid (1.0.0)
90
+ activesupport (>= 5.0)
91
+ i18n (1.10.0)
92
+ concurrent-ruby (~> 1.0)
93
+ loofah (2.18.0)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.5.9)
96
+ mail (2.7.1)
97
+ mini_mime (>= 0.1.1)
98
+ marcel (1.0.2)
99
+ method_source (1.0.0)
100
+ mini_mime (1.1.2)
101
+ mini_portile2 (2.8.0)
102
+ minitest (5.16.0)
103
+ minitest-reporters (1.5.0)
104
+ ansi
105
+ builder
106
+ minitest (>= 5.0)
107
+ ruby-progressbar
108
+ net-imap (0.2.3)
109
+ digest
110
+ net-protocol
111
+ strscan
112
+ net-pop (0.1.1)
113
+ digest
114
+ net-protocol
115
+ timeout
116
+ net-protocol (0.1.3)
117
+ timeout
118
+ net-smtp (0.3.1)
119
+ digest
120
+ net-protocol
121
+ timeout
122
+ nio4r (2.5.8)
123
+ nokogiri (1.13.6)
124
+ mini_portile2 (~> 2.8.0)
125
+ racc (~> 1.4)
126
+ parallel (1.22.1)
127
+ parser (3.1.2.0)
128
+ ast (~> 2.4.1)
129
+ pg (1.3.5)
130
+ pry (0.14.1)
131
+ coderay (~> 1.1)
132
+ method_source (~> 1.0)
133
+ racc (1.6.0)
134
+ rack (2.2.3.1)
135
+ rack-test (1.1.0)
136
+ rack (>= 1.0, < 3)
137
+ rails (7.0.3)
138
+ actioncable (= 7.0.3)
139
+ actionmailbox (= 7.0.3)
140
+ actionmailer (= 7.0.3)
141
+ actionpack (= 7.0.3)
142
+ actiontext (= 7.0.3)
143
+ actionview (= 7.0.3)
144
+ activejob (= 7.0.3)
145
+ activemodel (= 7.0.3)
146
+ activerecord (= 7.0.3)
147
+ activestorage (= 7.0.3)
148
+ activesupport (= 7.0.3)
149
+ bundler (>= 1.15.0)
150
+ railties (= 7.0.3)
151
+ rails-dom-testing (2.0.3)
152
+ activesupport (>= 4.2.0)
153
+ nokogiri (>= 1.6)
154
+ rails-html-sanitizer (1.4.3)
155
+ loofah (~> 2.3)
156
+ railties (7.0.3)
157
+ actionpack (= 7.0.3)
158
+ activesupport (= 7.0.3)
159
+ method_source
160
+ rake (>= 12.2)
161
+ thor (~> 1.0)
162
+ zeitwerk (~> 2.5)
163
+ rainbow (3.1.1)
164
+ rake (13.0.6)
165
+ regexp_parser (2.5.0)
166
+ rexml (3.2.5)
167
+ rubocop (1.29.1)
168
+ parallel (~> 1.10)
169
+ parser (>= 3.1.0.0)
170
+ rainbow (>= 2.2.2, < 4.0)
171
+ regexp_parser (>= 1.8, < 3.0)
172
+ rexml (>= 3.2.5, < 4.0)
173
+ rubocop-ast (>= 1.17.0, < 2.0)
174
+ ruby-progressbar (~> 1.7)
175
+ unicode-display_width (>= 1.4.0, < 3.0)
176
+ rubocop-ast (1.18.0)
177
+ parser (>= 3.1.1.0)
178
+ rubocop-performance (1.13.3)
179
+ rubocop (>= 1.7.0, < 2.0)
180
+ rubocop-ast (>= 0.4.0)
181
+ ruby-progressbar (1.11.0)
182
+ sequel (5.57.0)
183
+ sqlite3 (1.4.4)
184
+ standard (1.12.1)
185
+ rubocop (= 1.29.1)
186
+ rubocop-performance (= 1.13.3)
187
+ strscan (3.0.3)
188
+ thor (1.2.1)
189
+ timeout (0.3.0)
190
+ tzinfo (2.0.4)
191
+ concurrent-ruby (~> 1.0)
192
+ unicode-display_width (2.1.0)
193
+ websocket-driver (0.7.5)
194
+ websocket-extensions (>= 0.1.0)
195
+ websocket-extensions (0.1.5)
196
+ zeitwerk (2.6.0)
197
+
198
+ PLATFORMS
199
+ ruby
200
+
201
+ DEPENDENCIES
202
+ appraisal
203
+ minitest (~> 5.0)
204
+ minitest-reporters
205
+ pg
206
+ pry
207
+ rake (~> 13.0)
208
+ sequelize-rails!
209
+ sqlite3
210
+ standard (~> 1.3)
211
+
212
+ BUNDLED WITH
213
+ 2.3.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Kenaniah Cerny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Sequelize::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sequelize_rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sequelize-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sequelize-rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kenaniah/sequelize-rails.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Roadmap
42
+
43
+ - [x] Support database.yml file
44
+ - [x] Support `rails db` console command
45
+ - [ ] Support `rails console --sandbox` (auto rollback all transactions)
46
+ - [ ] Support logging
47
+ - [ ] Support db rake tasks
48
+ - [ ] Support multiple databases
49
+ - [ ] Support reloading (disconnect all connections)
50
+ - [ ] Support ActiveRecord plugins / conventions (shims)
51
+ - [ ] Support PostgreSQL custom format for dump & restore
52
+ - [ ] Support generators (including orm)
53
+ - [ ] Support migration generator (and parsed attributes)
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/*_test.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
data/bin/console ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "sequelize-rails"
6
+
7
+ # Load the rails application
8
+ require_relative "../test/dummy/config/environment"
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require "pry"
15
+ # Pry.start
16
+
17
+ require "irb"
18
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
9
+ bundle exec appraisal generate
10
+ bundle exec appraisal install
data/bin/test ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Runs the test suite locally
4
+ bundle exec appraisal rake test
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "standard", "~> 1.3"
8
+ gem "activerecord", "~> 6"
9
+ gem "rails", "~> 6"
10
+ gem "sequel", "~> 5"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "standard", "~> 1.3"
8
+ gem "activerecord", "~> 7"
9
+ gem "rails", "~> 7"
10
+ gem "sequel", "~> 5"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ module Sequel
2
+ module Extensions
3
+ module SequelInstrumentation
4
+ def log_connection_yield(sql, conn, args = nil)
5
+ ActiveSupport::Notifications.instrument "sql.sequel", sql: sql, conn: conn, binds: args do
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
11
+ Database.register_extension(:sequel_instrumentation, Extensions::SequelInstrumentation)
12
+ Database.extension(:sequel_instrumentation)
13
+ end
@@ -0,0 +1,24 @@
1
+ module Sequel::Plugins::PrettyPrint
2
+ module InstanceMethods
3
+ # Modeled after the implementation within ActiveRecord
4
+ def pretty_print(pp)
5
+ return super if method(:inspect).owner != Sequel::Model.instance_method(:inspect).owner
6
+
7
+ pp.object_address_group(self) do
8
+ keys = self.class.columns.select { |name| @values.key?(name) || new? }
9
+ keys = (keys + @values.keys).uniq
10
+
11
+ pp.seplist(keys, proc { pp.text(",") }) do |key|
12
+ pp.breakable " "
13
+
14
+ pp.group(1) do
15
+ pp.text key.to_s
16
+ pp.text ":"
17
+ pp.breakable
18
+ pp.pp self[key]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ require "sequelize_rails"
@@ -0,0 +1,10 @@
1
+ # Monkey patch to allow Rails DB Console to load properly by loading active_record first
2
+ if defined? Rails::DBConsole
3
+ module DBConsoleMonkeyPatch
4
+ def initialize options = {}
5
+ require "active_record"
6
+ super
7
+ end
8
+ end
9
+ Rails::DBConsole.prepend DBConsoleMonkeyPatch
10
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SequelizeRails
4
+ module Generators
5
+ class ApplicationRecordGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def create_application_record
9
+ template "application_record.rb", application_record_file_name
10
+ end
11
+
12
+ private
13
+
14
+ def application_record_file_name
15
+ @application_record_file_name ||=
16
+ if namespaced?
17
+ "app/models/#{namespaced_path}/application_record.rb"
18
+ else
19
+ "app/models/application_record.rb"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ class ApplicationRecord < Sequel::Model
3
+ # Makes this an abstract model
4
+ dataset = nil
5
+ end
6
+
7
+ # Allows subclassed models to be initialzed with a customized dataset
8
+ def ApplicationRecord *args
9
+ ApplicationRecord.Model *args
10
+ end
11
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SequelizeRails
4
+ module Generators
5
+ class MigrationGenerator < ::Rails::Generators::NamedBase
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
11
+
12
+ def self.next_migration_number _dirname
13
+ Time.now.strftime "%Y%m%d%H%M%S"
14
+ end
15
+
16
+ def create_migration_file
17
+ migration_template "migration.rb.erb", "db/migrate/#{file_name}.rb"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ Sequel.migration do
2
+ up do
3
+ # Add forward migration code here
4
+ end
5
+
6
+ down do
7
+ # Add rollback migration code here
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SequelizeRails
4
+ module Generators
5
+ class ModelGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("templates", __dir__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,62 @@
1
+ require "sequel"
2
+ require "rails"
3
+
4
+ # Database configuration
5
+ require "active_record/connection_handling"
6
+ require "active_record/database_configurations"
7
+
8
+ # Railties
9
+ require "action_controller/railtie"
10
+ require "sequelize_rails/railties/log_subscriber"
11
+ require "sequelize_rails/railties/controller_runtime"
12
+
13
+ # Load instrumentation before any database connections are established
14
+ Sequel.extension :sequel_instrumentation
15
+
16
+ # Monkey patches
17
+ require "sequelize_rails/db_console"
18
+
19
+ module SequelizeRails
20
+ class Railtie < Rails::Railtie
21
+ ::SequelizeRails::Railties::LogSubscriber.attach_to :sequel
22
+ config.app_generators.orm :sequelize_rails, migration: :sequel_migration
23
+ config.sequel = ActiveSupport::OrderedOptions.new
24
+
25
+ initializer "sequel.plugins" do
26
+ ::Sequel::Model.plugin :active_model
27
+ end
28
+
29
+ initializer "sequel.logger" do |app|
30
+ app.config.sequel.logger ||= ::Rails.logger
31
+ app.config.sequel.verbose_query_logs = ::Rails.env.development? if app.config.sequel.verbose_query_logs.nil?
32
+ end
33
+
34
+ # https://api.rubyonrails.org/classes/ActiveModel/Translation.html
35
+ initializer "sequel.i18n_support" do
36
+ ::Sequel::Model.send :extend, ::ActiveModel::Translation
37
+ ::Sequel::Model.send :extend, ::SequelizeRails::TranslationSupport
38
+ end
39
+
40
+ initializer "sequel.pretty_print" do
41
+ ::Sequel::Model.plugin :pretty_print
42
+ end
43
+
44
+ initializer "sequel.configuration" do
45
+ SequelizeRails.configurations = ActiveRecord::DatabaseConfigurations.new Rails.application.config.database_configuration
46
+ end
47
+
48
+ initializer "sequel.connection" do
49
+ SequelizeRails.connect_to :primary unless ARGV.any? { |c| c.starts_with? "db:" }
50
+ end
51
+
52
+ # Expose database runtime to controller for logging.
53
+ initializer "sequel.log_runtime" do |_app|
54
+ require "sequelize_rails/railties/controller_runtime"
55
+ ActionController::Base.send :include, SequelizeRails::Railties::ControllerRuntime
56
+ end
57
+
58
+ rake_tasks do
59
+ load File.expand_path("../tasks.rake", __dir__)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,46 @@
1
+ require "active_support/core_ext/module/attr_internal"
2
+
3
+ module SequelizeRails
4
+ module Railties
5
+ module ControllerRuntime
6
+ extend ActiveSupport::Concern
7
+
8
+ protected
9
+
10
+ attr_internal :db_runtime
11
+
12
+ def process_action(action, *)
13
+ # We also need to reset the runtime before each action
14
+ # because of queries in middleware or in cases we are streaming
15
+ # and it won't be cleaned up by the method below.
16
+ ::SequelizeRails::Railties::LogSubscriber.reset_runtime
17
+ ::SequelizeRails::Railties::LogSubscriber.reset_count
18
+ super
19
+ end
20
+
21
+ def cleanup_view_runtime
22
+ db_rt_before_render = ::SequelizeRails::Railties::LogSubscriber.reset_runtime
23
+ self.db_runtime = (db_runtime || 0) + db_rt_before_render
24
+ runtime = super
25
+ db_rt_after_render = ::SequelizeRails::Railties::LogSubscriber.reset_runtime
26
+ self.db_runtime += db_rt_after_render
27
+ runtime - db_rt_after_render
28
+ end
29
+
30
+ def append_info_to_payload(payload)
31
+ super
32
+ payload[:db_runtime] = (db_runtime || 0) + ::SequelizeRails::Railties::LogSubscriber.reset_runtime
33
+ payload[:db_query_count] = ::SequelizeRails::Railties::LogSubscriber.count
34
+ end
35
+
36
+ module ClassMethods
37
+ def log_process_action(payload)
38
+ messages = super
39
+ messages << format("Database: %.1fms", payload[:db_runtime].to_f) if payload[:db_runtime]
40
+ messages << format("Queries: %d", payload[:db_query_count].to_f) if payload[:db_query_count]
41
+ messages
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end