statement_timeout 0.0.1 → 1.0.0.pre.rc.1

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
  SHA256:
3
- metadata.gz: 9081c6f29f5048ca847ab9f4f91496337353e389e0a69c0482e8ff6b9abe8976
4
- data.tar.gz: e34da8b5a04b2d181475664c0819af816d556fc758f4ff4d1ea719edf40cb49e
3
+ metadata.gz: b42943a4a7aaa58ea1d0111e663391f30e8781dee8d220ad8db2ad011b1efda3
4
+ data.tar.gz: c585bf0781f46e562b3947c0813c478ba6d14e038d9c0f876ba27dd0ee0fe4be
5
5
  SHA512:
6
- metadata.gz: 814f0feefa1b7ded86a7f2664f10a37a257970d8987fc58f9fe330e547b59d859f0755d12ac59790a9be74d9b20572646d956ddc7fc2dab0010482d1879a1dfd
7
- data.tar.gz: '09618d143f07dedcd39a8a4a1cf0577e610258ad6cb14432748b43a6f0d6286592b352e2d2ab9bebbe8457054c21742c46f8da17a3f0f0cc6088d78a2e70aeae'
6
+ metadata.gz: 66a2345bbb4088bdebd6fe59327c5550b4d114e6edac342d4778641a081184cd5a7e5d0bfec6db4d5e07be71acf9f9abbd727a0b665725b916f41f6798742641
7
+ data.tar.gz: 566f9e844756d16d3d85da9a31a35a5c52b52969cf8acf95879dbf04c915e1eb974b7bc1c5d8c4e3fa0902be25885cf24ce67375ac10bb3dd0b373674d45606c
data/README.md CHANGED
@@ -1,31 +1,84 @@
1
- # StatementTimeout
1
+ # statement_timeout
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![CI](https://github.com/keygen-sh/statement_timeout/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/statement_timeout/actions)
4
+ [![Gem Version](https://badge.fury.io/rb/statement_timeout.svg)](https://badge.fury.io/rb/statement_timeout)
4
5
 
5
- 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/statement_timeout`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ Use `statement_timeout` to wrap an Active Record transaction or query in a
7
+ local statement timeout.
8
+
9
+ This gem was extracted from [Keygen](https://keygen.sh).
10
+
11
+ Sponsored by:
12
+
13
+ <a href="https://keygen.sh?ref=statement_timeout">
14
+ <div>
15
+ <img src="https://keygen.sh/images/logo-pill.png" width="200" alt="Keygen">
16
+ </div>
17
+ </a>
18
+
19
+ _A fair source software licensing and distribution API._
6
20
 
7
21
  ## Installation
8
22
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
23
+ Add this line to your application's `Gemfile`:
10
24
 
11
- Install the gem and add to the application's Gemfile by executing:
25
+ ```ruby
26
+ gem 'statement_timeout'
27
+ ```
12
28
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
29
+ And then execute:
14
30
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
31
+ ```bash
32
+ $ bundle
33
+ ```
16
34
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
35
+ Or install it yourself as:
36
+
37
+ ```bash
38
+ $ gem install statement_timeout
39
+ ```
18
40
 
19
41
  ## Usage
20
42
 
21
- TODO: Write usage instructions here
43
+ ```ruby
44
+ User.statement_timeout 42.minutes do
45
+ some_expensive_operation
46
+ end
47
+
48
+ User.posts.statement_timeout 10.seconds do
49
+ some_cheap_operation
50
+ end
51
+
52
+ Tag.statement_timeout 6.hours do |conn|
53
+ conn.execute 'VACUUM ANALYZE tags'
54
+ end
55
+ ```
22
56
 
23
- ## Development
57
+ ## Future
24
58
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+ Right now, the gem only supports RSpec, but we're open to pull requests that
60
+ extend the functionality to other testing frameworks.
26
61
 
27
- 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).
62
+ ## Supported databases
63
+
64
+ We currently support PostgreSQL. We'd love contributions that add MySQL,
65
+ MariaDB, and SQLite support, but we probably won't add it ourselves.
66
+
67
+ ## Supported Rubies
68
+
69
+ **`statement_timeout` supports Ruby 3.1 and above.** We encourage you to upgrade
70
+ if you're on an older version. Ruby 3 provides a lot of great features, like
71
+ better pattern matching and a new shorthand hash syntax.
72
+
73
+ ## Is it any good?
74
+
75
+ Yes.
28
76
 
29
77
  ## Contributing
30
78
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/statement_timeout.
79
+ If you have an idea, or have discovered a bug, please open an issue or create a
80
+ pull request.
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record/connection_adapters/postgresql_adapter'
4
+ require 'active_record/relation'
5
+
6
+ module StatementTimeout
7
+ ActiveSupport.on_load :active_record do
8
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(AbstractAdapterExtension)
9
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapterExtension)
10
+ ActiveRecord::QueryMethods.prepend(QueryMethodsExtension)
11
+ ActiveRecord::Querying.prepend(QueryingExtension)
12
+ end
13
+ end
14
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StatementTimeout
4
- VERSION = '0.0.1'
4
+ VERSION = '1.0.0-rc.1'
5
5
  end
@@ -1,6 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support'
4
+ require 'active_record'
5
+
3
6
  require_relative 'statement_timeout/version'
7
+ require_relative 'statement_timeout/railtie'
4
8
 
5
9
  module StatementTimeout
10
+ module AbstractAdapterExtension
11
+ def supports_statement_timeout? = false
12
+ def statement_timeout = raise NotImplementedError
13
+ def statement_timeout=(timeout)
14
+ raise NotImplementedError
15
+ end
16
+ end
17
+
18
+ module PostgreSQLAdapterExtension
19
+ def supports_statement_timeout? = true
20
+ def statement_timeout = @statement_timeout ||= query_value("SHOW statement_timeout")
21
+ def statement_timeout=(timeout)
22
+ @statement_timeout = nil
23
+
24
+ internal_exec_query("SET statement_timeout = #{quote(timeout)}")
25
+ end
26
+ end
27
+
28
+ module QueryMethodsExtension
29
+ def statement_timeout(timeout)
30
+ timeout = if timeout in ActiveSupport::Duration
31
+ timeout.in_milliseconds
32
+ else
33
+ timeout
34
+ end
35
+
36
+ connection_pool.with_connection do |connection|
37
+ raise ActiveRecord::AdapterError, "statement_timeout is not supported for the #{connection.class.inspect} adapter" unless
38
+ connection.supports_statement_timeout?
39
+
40
+ statement_timeout_was, connection.statement_timeout = connection.statement_timeout, timeout
41
+
42
+ yield connection
43
+ ensure
44
+ connection.statement_timeout = statement_timeout_was
45
+ end
46
+ end
47
+ end
48
+
49
+ module QueryingExtension
50
+ delegate :statement_timeout, to: :all
51
+ end
6
52
  end
53
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statement_timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-29 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,76 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: temporary_tables
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sql_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pg
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
41
111
  description: Wrap an Active Record transaction or query in a local statement timeout.
42
112
  email:
43
113
  - oss@keygen.sh
@@ -51,6 +121,7 @@ files:
51
121
  - README.md
52
122
  - SECURITY.md
53
123
  - lib/statement_timeout.rb
124
+ - lib/statement_timeout/railtie.rb
54
125
  - lib/statement_timeout/version.rb
55
126
  homepage: https://github.com/keygen-sh/statement_timeout
56
127
  licenses:
@@ -67,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
138
  version: '3.1'
68
139
  required_rubygems_version: !ruby/object:Gem::Requirement
69
140
  requirements:
70
- - - ">="
141
+ - - ">"
71
142
  - !ruby/object:Gem::Version
72
- version: '0'
143
+ version: 1.3.1
73
144
  requirements: []
74
145
  rubygems_version: 3.4.13
75
146
  signing_key: