sequelize-rails 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/Gemfile.lock +105 -103
  4. data/README.md +161 -17
  5. data/lib/sequel/rails/generators/application_record/application_record_generator.rb +26 -0
  6. data/lib/sequel/rails/generators/migration/migration_generator.rb +23 -0
  7. data/lib/sequel/rails/generators/model/model_generator.rb +11 -0
  8. data/lib/sequel/rails/minitest.rb +24 -0
  9. data/lib/sequel/rails/railtie.rb +68 -0
  10. data/lib/sequel/rails/railties/controller_runtime.rb +48 -0
  11. data/lib/sequel/rails/railties/log_subscriber.rb +155 -0
  12. data/lib/sequel/rails/translation_support.rb +15 -0
  13. data/lib/sequel/rails/version.rb +7 -0
  14. data/lib/sequel/rails.rb +38 -0
  15. data/lib/{tasks.rake → sequel/tasks.rake} +6 -6
  16. data/lib/sequelize-rails.rb +1 -1
  17. data/lib/sequelize_rails.rb +1 -29
  18. data/sequelize-rails.gemspec +2 -2
  19. data/sig/sequelize_rails.rbs +5 -3
  20. metadata +18 -15
  21. data/lib/sequelize_rails/generators/application_record/application_record_generator.rb +0 -24
  22. data/lib/sequelize_rails/generators/migration/migration_generator.rb +0 -21
  23. data/lib/sequelize_rails/generators/model/model_generator.rb +0 -9
  24. data/lib/sequelize_rails/railtie.rb +0 -66
  25. data/lib/sequelize_rails/railties/controller_runtime.rb +0 -46
  26. data/lib/sequelize_rails/railties/log_subscriber.rb +0 -153
  27. data/lib/sequelize_rails/translation_support.rb +0 -13
  28. data/lib/sequelize_rails/version.rb +0 -5
  29. /data/lib/{sequelize_rails → sequel/rails}/db_console.rb +0 -0
  30. /data/lib/{sequelize_rails → sequel/rails}/generators/application_record/templates/application_record.rb.tt +0 -0
  31. /data/lib/{sequelize_rails → sequel/rails}/generators/migration/templates/migration.rb.erb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28ba0f80f8f390c7a6e735f81466cf6de3afa6a583fa468356165dc16f6b464f
4
- data.tar.gz: aea26a334f90d64997e596fa6830f204d59bb35f58616e34795b5e0edfdf06f7
3
+ metadata.gz: 5a4f6a5f212bf94c21dde2f54845199e61451ee395cd523c2f7388c5d84f8a6a
4
+ data.tar.gz: b178476afacda06beaa3543202a5686d3563ed1eb88301282037cf9c4d1a8c10
5
5
  SHA512:
6
- metadata.gz: 10aff2b60e7c26aa6f3ae61292372689c77574e51c8aed46529b5a90989a3f013cb3661195ba83c48e98e3df4027e6afb0b18d91ba150b73f385acd05c81bbf5
7
- data.tar.gz: 3ad6415360fa05680722111e912d6c13be37204c76a8410e69ad18c19c2bde2a63fb9a2adf41728b6b286ae70847f1d34bdae8ff6daf58ea7f3d51ba90a7ae4e
6
+ metadata.gz: 83259849b58844286b69d29e9f0f94e819d4155ad3923aa9b4b5e1958353ead386980ffaefa20b67cac4522a04b16b4c64dd6396238b64749a8b849c57c538a6
7
+ data.tar.gz: 2320fcfa8b3ae4b5c3cf9c39e40abcbd624fa8189e9c2964ba5db47d78fc33cdcb5e06c5366ecbcb8bab04b6b8c44a06cb27ac171d6aa369c78ec17e71fdee73
data/.DS_Store ADDED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sequelize-rails (0.2.0)
4
+ sequelize-rails (0.3.0)
5
5
  activerecord (>= 6.0.0)
6
6
  rails (>= 6.0.0)
7
7
  sequel (>= 5.0.0)
@@ -9,67 +9,67 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (7.0.3)
13
- actionpack (= 7.0.3)
14
- activesupport (= 7.0.3)
12
+ actioncable (7.0.4.3)
13
+ actionpack (= 7.0.4.3)
14
+ activesupport (= 7.0.4.3)
15
15
  nio4r (~> 2.0)
16
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)
17
+ actionmailbox (7.0.4.3)
18
+ actionpack (= 7.0.4.3)
19
+ activejob (= 7.0.4.3)
20
+ activerecord (= 7.0.4.3)
21
+ activestorage (= 7.0.4.3)
22
+ activesupport (= 7.0.4.3)
23
23
  mail (>= 2.7.1)
24
24
  net-imap
25
25
  net-pop
26
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)
27
+ actionmailer (7.0.4.3)
28
+ actionpack (= 7.0.4.3)
29
+ actionview (= 7.0.4.3)
30
+ activejob (= 7.0.4.3)
31
+ activesupport (= 7.0.4.3)
32
32
  mail (~> 2.5, >= 2.5.4)
33
33
  net-imap
34
34
  net-pop
35
35
  net-smtp
36
36
  rails-dom-testing (~> 2.0)
37
- actionpack (7.0.3)
38
- actionview (= 7.0.3)
39
- activesupport (= 7.0.3)
37
+ actionpack (7.0.4.3)
38
+ actionview (= 7.0.4.3)
39
+ activesupport (= 7.0.4.3)
40
40
  rack (~> 2.0, >= 2.2.0)
41
41
  rack-test (>= 0.6.3)
42
42
  rails-dom-testing (~> 2.0)
43
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)
44
+ actiontext (7.0.4.3)
45
+ actionpack (= 7.0.4.3)
46
+ activerecord (= 7.0.4.3)
47
+ activestorage (= 7.0.4.3)
48
+ activesupport (= 7.0.4.3)
49
49
  globalid (>= 0.6.0)
50
50
  nokogiri (>= 1.8.5)
51
- actionview (7.0.3)
52
- activesupport (= 7.0.3)
51
+ actionview (7.0.4.3)
52
+ activesupport (= 7.0.4.3)
53
53
  builder (~> 3.1)
54
54
  erubi (~> 1.4)
55
55
  rails-dom-testing (~> 2.0)
56
56
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
- activejob (7.0.3)
58
- activesupport (= 7.0.3)
57
+ activejob (7.0.4.3)
58
+ activesupport (= 7.0.4.3)
59
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)
60
+ activemodel (7.0.4.3)
61
+ activesupport (= 7.0.4.3)
62
+ activerecord (7.0.4.3)
63
+ activemodel (= 7.0.4.3)
64
+ activesupport (= 7.0.4.3)
65
+ activestorage (7.0.4.3)
66
+ actionpack (= 7.0.4.3)
67
+ activejob (= 7.0.4.3)
68
+ activerecord (= 7.0.4.3)
69
+ activesupport (= 7.0.4.3)
70
70
  marcel (~> 1.0)
71
71
  mini_mime (>= 1.1.0)
72
- activesupport (7.0.3)
72
+ activesupport (7.0.4.3)
73
73
  concurrent-ruby (~> 1.0, >= 1.0.2)
74
74
  i18n (>= 1.6, < 2)
75
75
  minitest (>= 5.1)
@@ -82,118 +82,120 @@ GEM
82
82
  ast (2.4.2)
83
83
  builder (3.2.4)
84
84
  coderay (1.1.3)
85
- concurrent-ruby (1.1.10)
85
+ concurrent-ruby (1.2.2)
86
86
  crass (1.0.6)
87
- digest (3.1.0)
88
- erubi (1.10.0)
89
- globalid (1.0.0)
87
+ date (3.3.3)
88
+ erubi (1.12.0)
89
+ globalid (1.1.0)
90
90
  activesupport (>= 5.0)
91
- i18n (1.10.0)
91
+ i18n (1.12.0)
92
92
  concurrent-ruby (~> 1.0)
93
- loofah (2.18.0)
93
+ json (2.6.3)
94
+ language_server-protocol (3.17.0.3)
95
+ loofah (2.19.1)
94
96
  crass (~> 1.0.2)
95
97
  nokogiri (>= 1.5.9)
96
- mail (2.7.1)
98
+ mail (2.8.1)
97
99
  mini_mime (>= 0.1.1)
100
+ net-imap
101
+ net-pop
102
+ net-smtp
98
103
  marcel (1.0.2)
99
104
  method_source (1.0.0)
100
105
  mini_mime (1.1.2)
101
- mini_portile2 (2.8.0)
102
- minitest (5.16.0)
103
- minitest-reporters (1.5.0)
106
+ mini_portile2 (2.8.1)
107
+ minitest (5.18.0)
108
+ minitest-reporters (1.6.0)
104
109
  ansi
105
110
  builder
106
111
  minitest (>= 5.0)
107
112
  ruby-progressbar
108
- net-imap (0.2.3)
109
- digest
113
+ net-imap (0.3.4)
114
+ date
110
115
  net-protocol
111
- strscan
112
- net-pop (0.1.1)
113
- digest
116
+ net-pop (0.1.2)
114
117
  net-protocol
118
+ net-protocol (0.2.1)
115
119
  timeout
116
- net-protocol (0.1.3)
117
- timeout
118
- net-smtp (0.3.1)
119
- digest
120
+ net-smtp (0.3.3)
120
121
  net-protocol
121
- timeout
122
122
  nio4r (2.5.8)
123
- nokogiri (1.13.6)
123
+ nokogiri (1.14.2)
124
124
  mini_portile2 (~> 2.8.0)
125
125
  racc (~> 1.4)
126
126
  parallel (1.22.1)
127
- parser (3.1.2.0)
127
+ parser (3.2.1.1)
128
128
  ast (~> 2.4.1)
129
- pg (1.3.5)
130
- pry (0.14.1)
129
+ pg (1.4.6)
130
+ pry (0.14.2)
131
131
  coderay (~> 1.1)
132
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)
133
+ racc (1.6.2)
134
+ rack (2.2.6.4)
135
+ rack-test (2.1.0)
136
+ rack (>= 1.3)
137
+ rails (7.0.4.3)
138
+ actioncable (= 7.0.4.3)
139
+ actionmailbox (= 7.0.4.3)
140
+ actionmailer (= 7.0.4.3)
141
+ actionpack (= 7.0.4.3)
142
+ actiontext (= 7.0.4.3)
143
+ actionview (= 7.0.4.3)
144
+ activejob (= 7.0.4.3)
145
+ activemodel (= 7.0.4.3)
146
+ activerecord (= 7.0.4.3)
147
+ activestorage (= 7.0.4.3)
148
+ activesupport (= 7.0.4.3)
149
149
  bundler (>= 1.15.0)
150
- railties (= 7.0.3)
150
+ railties (= 7.0.4.3)
151
151
  rails-dom-testing (2.0.3)
152
152
  activesupport (>= 4.2.0)
153
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)
154
+ rails-html-sanitizer (1.5.0)
155
+ loofah (~> 2.19, >= 2.19.1)
156
+ railties (7.0.4.3)
157
+ actionpack (= 7.0.4.3)
158
+ activesupport (= 7.0.4.3)
159
159
  method_source
160
160
  rake (>= 12.2)
161
161
  thor (~> 1.0)
162
162
  zeitwerk (~> 2.5)
163
163
  rainbow (3.1.1)
164
164
  rake (13.0.6)
165
- regexp_parser (2.5.0)
165
+ regexp_parser (2.7.0)
166
166
  rexml (3.2.5)
167
- rubocop (1.29.1)
167
+ rubocop (1.48.1)
168
+ json (~> 2.3)
168
169
  parallel (~> 1.10)
169
- parser (>= 3.1.0.0)
170
+ parser (>= 3.2.0.0)
170
171
  rainbow (>= 2.2.2, < 4.0)
171
172
  regexp_parser (>= 1.8, < 3.0)
172
173
  rexml (>= 3.2.5, < 4.0)
173
- rubocop-ast (>= 1.17.0, < 2.0)
174
+ rubocop-ast (>= 1.26.0, < 2.0)
174
175
  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)
176
+ unicode-display_width (>= 2.4.0, < 3.0)
177
+ rubocop-ast (1.27.0)
178
+ parser (>= 3.2.1.0)
179
+ rubocop-performance (1.16.0)
179
180
  rubocop (>= 1.7.0, < 2.0)
180
181
  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)
182
+ ruby-progressbar (1.13.0)
183
+ sequel (5.66.0)
184
+ sqlite3 (1.6.1)
185
+ mini_portile2 (~> 2.8.0)
186
+ standard (1.25.3)
187
+ language_server-protocol (~> 3.17.0.2)
188
+ rubocop (~> 1.48.1)
189
+ rubocop-performance (~> 1.16.0)
188
190
  thor (1.2.1)
189
- timeout (0.3.0)
190
- tzinfo (2.0.4)
191
+ timeout (0.3.2)
192
+ tzinfo (2.0.6)
191
193
  concurrent-ruby (~> 1.0)
192
- unicode-display_width (2.1.0)
194
+ unicode-display_width (2.4.2)
193
195
  websocket-driver (0.7.5)
194
196
  websocket-extensions (>= 0.1.0)
195
197
  websocket-extensions (0.1.5)
196
- zeitwerk (2.6.0)
198
+ zeitwerk (2.6.7)
197
199
 
198
200
  PLATFORMS
199
201
  ruby
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # Sequelize::Rails
1
+ # sequelize-rails
2
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.
3
+ ![Gem Version](https://badge.fury.io/rb/sequelize-rails.svg)
4
+ ![Build Status](https://github.com/kenaniah/sequelize-rails/actions/workflows/ci.yml/badge.svg)
5
+ ![Code Climate](https://codeclimate.com/github/kenaniah/sequelize-rails.svg)
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ This gem provides support for using [Sequel](https://sequel.jeremyevans.net/) as an ORM for Rails applications by providing features that are similar to ActiveRecord's integration with Rails. It is an alternative to [sequel-rails](https://github.com/TalentBox/sequel-rails).
6
8
 
7
- ## Installation
9
+ ## Using sequelize-rails
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
@@ -16,36 +18,178 @@ And then execute:
16
18
 
17
19
  $ bundle install
18
20
 
19
- Or install it yourself as:
21
+ If you are looking to replace ActiveRecord entirely, you may need to either generate your Rails app using `--skip-active-record` or manually remove references to ActiveRecord in your `Gemfile`, `config/application.rb`, and `config/environments/*.rb` files.
20
22
 
21
- $ gem install sequelize-rails
23
+ ## Features provided by `sequelize-rails`
22
24
 
23
- ## Usage
25
+ **Database Management**
24
26
 
25
- TODO: Write usage instructions here
27
+ - [x] [Connectivity](#---database-connectivity) via `config/database.yml`
28
+ - [x] [Console](#---database-console) via `rails db`
29
+ - [x] [Migrations](#---database-migrations) via `Sequel::Migration`
30
+ - [ ] [Migration Generators](#---migration-generators) via `rails generate migration` (not supported yet)
31
+ - [x] [Rake tasks](#---database-rake-tasks) via `rails db:*`
26
32
 
27
- ## Development
33
+ **Test Suite**
34
+ - [x] [Minitest Helpers](#---minitest-helpers)
28
35
 
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.
36
+ ## - Database Connectivity
30
37
 
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).
38
+ This gem will automatically use your application's `config/database.yml` file to configure the available database connection(s).
32
39
 
33
- ## Contributing
40
+ ### Primary Connection
41
+
42
+ A connection to the "primary" database is automatically established when the application is loaded. This connection will by used by default for all model classes that do not specify a different connection.
43
+
44
+ The primary connection can be referenced directly via:
45
+
46
+ ```ruby
47
+ Sequel::DATABASES.first # instead of ActiveRecord::Base.connection
48
+ ```
49
+
50
+ A common convention within applications that use Sequel is to store the primary connection in the `DB` constant, which can be easily done within an initializer file via the following:
51
+
52
+ ```ruby
53
+ # config/initializers/sequel.rb
54
+ DB = Sequel::DATABASES.first unless defined?(DB)
55
+ ```
56
+
57
+ ### Additional Connections
58
+
59
+ Additional connections can be configured in your `config/database.yml` file by adding additional entries to the `databases` key. For example:
60
+
61
+ ```yaml
62
+ # config/database.yml
63
+
64
+ # ... snip ...
65
+
66
+ production:
67
+ <<: *default
68
+ database: <%= ENV["DATABASE_URL"] %>
69
+
70
+ my_replica:
71
+ <<: *default
72
+ database: <%= ENV["REPLICA_DATABASE_URL"] %>
73
+
74
+ ```
75
+
76
+ Additional connections can be retrieved via `Sequel::Rails.connect_to`, such as within the example below:
77
+
78
+
79
+ ```ruby
80
+ replica_connection = Sequel::Rails.connect_to :my_replica
81
+ ```
82
+
83
+ ## ✅ - Database Console
84
+
85
+ You can connect directly to your database via the `rails db` command. This command is similar to the `rails console` command, but instead of loading your application, it will connect directly to the database.
86
+
87
+ ```bash
88
+ # connects to the primary database
89
+ $ rails db
90
+
91
+ # connects to the database of the test environment
92
+ $ rails db -e test
93
+ ```
94
+
95
+ Please note that only the `-e` flag is supported at this time. Other flags such as `--database` are not supported.
96
+
97
+ ## ✅ - Database Migrations
98
+
99
+ This gem provides support for using Sequel's migration system. Migrations are stored in the `db/migrate` directory and can be executed via the `rails db:migrate` command.
100
+
101
+ More information about Sequel's migration system can be found in the [Sequel documentation](https://sequel.jeremyevans.net/rdoc/files/doc/migration_rdoc.html).
102
+
103
+ ## 🚧 - Migration Generators
104
+
105
+ Rails supports the generation of migrations via the `rails generate migration` command. This gem does not currently support this feature, but pull requests are welcome.
106
+
107
+ ## ✅ - Database Rake Tasks
108
+
109
+ This gem provides a set of rake tasks that are similar to the ActiveRecord tasks. These tasks can be used to create, drop, migrate, and seed your database.
110
+
111
+ | Task | Description |
112
+ | --- | --- |
113
+ | `rails db:create` | Creates the database from `DATABASE_URL` or `config/database.yml` for the current `RAILS_ENV` (use `db:create:all` to create all databases in the config). |
114
+ | `rails db:drop` | Drops the database from `DATABASE_URL` or `config/database.yml` for the current `RAILS_ENV` (use `db:drop:all` to drop all databases in the config). |
115
+ | `rails db:migrate` | Runs database migrations |
116
+ | `rails db:migrate:redo` | Rolls back the last migration and re-runs it |
117
+ | `rails db:migrate:status` | Displays the status of the database migrations |
118
+ | `rails db:prepare` | Runs `db:setup` if the database does not exist or `db:migrate` if it does |
119
+ | `rails db:reset` | Runs `db:drop`, `db:setup` |
120
+ | `rails db:rollback` | Rolls back the last migration |
121
+ | `rails db:setup` | Runs the `db:create`, `db:migrate`, `db:seed` tasks |
122
+
123
+ ## ✅ - Minitest Helpers
124
+ ### `assert_num_queries`
125
+
126
+ This helper can be used to assert that a specific number of database queries are executed within the given block of code.
127
+
128
+ Example:
129
+
130
+ ```ruby
131
+ # asserts that exactly 2 queries are executed
132
+ assert_num_queries(2) do
133
+ u = User[id: 1234]
134
+ u.update(name: "Random User")
135
+ end
136
+
137
+ # asserts that 0 queries are executed
138
+ assert_num_queries(0) do
139
+ some_hopefully_cached_method
140
+ end
141
+
142
+ # asserts that 1 to 3 queries are executed
143
+ assert_num_queries(1..3) do
144
+ u = User.find_or_create(name: "Random User")
145
+ end
146
+
147
+ # asserts that at least 3 queries are executed
148
+ assert_num_queries(3..) do
149
+ stuff_here
150
+ end
151
+
152
+ # asserts that no more than 2 queries are executed
153
+ assert_num_queries(..2) do
154
+ other_stuff_here
155
+ end
156
+ ```
157
+
158
+ ### `assert_no_queries`
159
+
160
+ This helper can be used to assert that no database queries are executed within the given block of code.
161
+
162
+ Example:
163
+
164
+ ```ruby
165
+ # asserts that no queries are executed
166
+ assert_no_queries do
167
+ some_hopefully_cached_method
168
+ end
169
+ ```
170
+
171
+ # Contributing
34
172
 
35
173
  Bug reports and pull requests are welcome on GitHub at https://github.com/kenaniah/sequelize-rails.
36
174
 
37
- ## License
175
+ This repository contains a handful of commands that can be used to facilitate this gem's development. These are:
176
+
177
+ | Command | Description |
178
+ | --- | --- |
179
+ | `bin/setup` | Installs the gem's development dependencies |
180
+ | `bin/test` | Runs the test suite for each supported Rails version |
181
+ | `bin/console` | Starts an interactive console within the gem's test Rails app (located in `test/dummy/`) |
182
+ | `bundle exec rake release` | Creates a new release of the gem (version number should be bumped first) |
183
+
184
+ # License
38
185
 
39
186
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
187
 
41
- ## Roadmap
188
+ # Roadmap
42
189
 
43
- - [x] Support database.yml file
44
- - [x] Support `rails db` console command
45
190
  - [ ] Support `rails console --sandbox` (auto rollback all transactions)
46
191
  - [ ] Support logging
47
192
  - [ ] Support db rake tasks
48
- - [ ] Support multiple databases
49
193
  - [ ] Support reloading (disconnect all connections)
50
194
  - [ ] Support ActiveRecord plugins / conventions (shims)
51
195
  - [ ] Support PostgreSQL custom format for dump & restore
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sequel
4
+ module Rails
5
+ module Generators
6
+ class ApplicationRecordGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ def create_application_record
10
+ template "application_record.rb", application_record_file_name
11
+ end
12
+
13
+ private
14
+
15
+ def application_record_file_name
16
+ @application_record_file_name ||=
17
+ if namespaced?
18
+ "app/models/#{namespaced_path}/application_record.rb"
19
+ else
20
+ "app/models/application_record.rb"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sequel
4
+ module Rails
5
+ module Generators
6
+ class MigrationGenerator < ::Rails::Generators::NamedBase
7
+ include ::Rails::Generators::Migration
8
+
9
+ source_root File.expand_path("templates", __dir__)
10
+
11
+ argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
12
+
13
+ def self.next_migration_number _dirname
14
+ Time.now.strftime "%Y%m%d%H%M%S"
15
+ end
16
+
17
+ def create_migration_file
18
+ migration_template "migration.rb.erb", "db/migrate/#{file_name}.rb"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sequel
4
+ module Rails
5
+ module Generators
6
+ class ModelGenerator < ::Rails::Generators::NamedBase
7
+ source_root File.expand_path("templates", __dir__)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module Minitest
2
+ module Assertions
3
+ def assert_num_queries(num, &block)
4
+ before = ::Sequel::Rails::Railties::LogSubscriber.count
5
+ res = yield
6
+ after = ::Sequel::Rails::Railties::LogSubscriber.count
7
+
8
+ case num
9
+ when Range
10
+ assert num.include?(after - before), "The number of database queries did not match expectations...\nExpected: #{num} (range)\n Actual: #{after - before}"
11
+ when Integer
12
+ assert num == after - before, "The number of database queries did not match expectations...\nExpected: #{num}\n Actual: #{after - before}"
13
+ else
14
+ raise ArgumentError, "Invalid argument passed to assert_num_queries: expected a Range or Integer value, but received #{num.inspect} instead."
15
+ end
16
+
17
+ res
18
+ end
19
+
20
+ def assert_no_queries(&block)
21
+ assert_num_queries(0, &block)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,68 @@
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 "sequel/rails/railties/log_subscriber"
11
+ require "sequel/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 "sequel/rails/db_console"
18
+
19
+ module Sequel
20
+ module Rails
21
+ class Railtie < ::Rails::Railtie
22
+ # Log subscriber
23
+ ::Sequel::Rails::Railties::LogSubscriber.attach_to :sequel
24
+ ::Sequel::Rails::Railties::LogSubscriber.backtrace_cleaner.add_filter { |line| line.gsub(::Rails.root.to_s + File::SEPARATOR, "") }
25
+
26
+ # Config initialization
27
+ config.app_generators.orm :sequelize_rails, migration: :sequel_migration
28
+ config.sequel = ActiveSupport::OrderedOptions.new
29
+
30
+ initializer "sequel.plugins" do
31
+ ::Sequel::Model.plugin :active_model
32
+ end
33
+
34
+ initializer "sequel.logger" do |app|
35
+ app.config.sequel.logger ||= ::Rails.logger
36
+ app.config.sequel.verbose_query_logs = ::Rails.env.development? if app.config.sequel.verbose_query_logs.nil?
37
+ end
38
+
39
+ # https://api.rubyonrails.org/classes/ActiveModel/Translation.html
40
+ initializer "sequel.i18n_support" do
41
+ ::Sequel::Model.send :extend, ::ActiveModel::Translation
42
+ ::Sequel::Model.send :extend, ::Sequel::Rails::TranslationSupport
43
+ end
44
+
45
+ initializer "sequel.pretty_print" do
46
+ ::Sequel::Model.plugin :pretty_print
47
+ end
48
+
49
+ initializer "sequel.configuration" do
50
+ ::Sequel::Rails.configurations = ActiveRecord::DatabaseConfigurations.new ::Rails.application.config.database_configuration
51
+ end
52
+
53
+ initializer "sequel.connection" do
54
+ ::Sequel::Rails.connect_to :primary unless ARGV.any? { |c| c.starts_with? "db:" }
55
+ end
56
+
57
+ # Expose database runtime to controller for logging.
58
+ initializer "sequel.log_runtime" do |_app|
59
+ require "sequel/rails/railties/controller_runtime"
60
+ ActionController::Base.send :include, ::Sequel::Rails::Railties::ControllerRuntime
61
+ end
62
+
63
+ rake_tasks do
64
+ load File.expand_path("../tasks.rake", __dir__)
65
+ end
66
+ end
67
+ end
68
+ end