rom-sql 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/rom/plugins/relation/sql/instrumentation.rb +73 -10
- data/lib/rom/sql/tasks/migration_tasks.rake +1 -1
- data/lib/rom/sql/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a673acd61e77b7b2c2a49c3dd781e06d716cec4e
|
4
|
+
data.tar.gz: e45523ac3f3c46e314fe529eb98d6ac721694e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d810deb9e4bc9d86bd35d8603644a7aa87dd7f2f7b712d681d9260482763c376f367535a22833f1b18ab36ff9d67ef26c175e4339967d52b6a7a18dfead68bf8
|
7
|
+
data.tar.gz: fc32e693d9b079c81108f495df1e42fcb8cdfa971104fead58c635f75a7fcb837933eb743265be7a866282f417a3d937fb7e166ebb319090809ef43ada8e331a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v2.2.1 2017-11-10
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* Instrumentation works with all db interactions (not just queries that materialize relations) (solnic)
|
6
|
+
* Typo in `MissingEnv` exception message (romatr)
|
7
|
+
|
8
|
+
[Compare v2.2.0...v2.2.1](https://github.com/rom-rb/rom-sql/compare/v2.2.0...v2.2.1)
|
9
|
+
|
1
10
|
## v2.2.0 2017-11-02
|
2
11
|
|
3
12
|
### Added
|
@@ -1,23 +1,86 @@
|
|
1
|
-
require 'rom/plugins/relation/instrumentation'
|
2
|
-
|
3
1
|
module ROM
|
4
2
|
module Plugins
|
5
3
|
module Relation
|
6
4
|
module SQL
|
7
|
-
#
|
5
|
+
# Instrumentation for relations and commands
|
6
|
+
#
|
7
|
+
# This plugin allows configuring a notification system, that will be used
|
8
|
+
# to instrument interactions with databases, it's based on an abstract API
|
9
|
+
# so it should work with any instrumentation object that provides
|
10
|
+
# `instrument(identifier, payload)` method.
|
11
|
+
#
|
12
|
+
# By default, instrumentation is triggered with following arguments:
|
13
|
+
# - `identifier` is set to `:sql`
|
14
|
+
# - `payload` is set to a hash with following keys:
|
15
|
+
# - `:name` database type, ie `:sqlite`, `:postgresql` etc.
|
16
|
+
# - `:query` a string with an SQL statement that was executed
|
17
|
+
#
|
18
|
+
# @example configuring notifications
|
19
|
+
# config = ROM::Configuration.new(:sqlite, 'sqlite::memory')
|
20
|
+
#
|
21
|
+
# config.plugin(:sql, relations: :instrumentation) do |c|
|
22
|
+
# c.notifications = MyNotifications.new
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @api public
|
8
26
|
module Instrumentation
|
9
|
-
|
10
|
-
|
27
|
+
extend Notifications::Listener
|
28
|
+
|
29
|
+
subscribe('configuration.relations.registry.created') do |event|
|
30
|
+
registry = event[:registry]
|
31
|
+
|
32
|
+
relations = registry.select { |_, r| r.adapter == :sql && r.respond_to?(:notifications) }.to_h
|
33
|
+
db_notifications = relations.values.map { |r| [r.dataset.db, r.notifications] }.uniq.to_h
|
34
|
+
|
35
|
+
db_notifications.each do |db, notifications|
|
36
|
+
instrumenter = Instrumenter.new(db.database_type, notifications)
|
37
|
+
db.extend(instrumenter)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# This stateful module is used to extend database connection objects
|
42
|
+
# and monkey-patches `log_connection_yield` method, which unfortunately
|
43
|
+
# is the only way to provide instrumentation on the sequel side.
|
44
|
+
#
|
45
|
+
# @api private
|
46
|
+
class Instrumenter < Module
|
47
|
+
# @!attribute [r] name
|
48
|
+
# @return [Symbol] database type
|
49
|
+
attr_reader :name
|
11
50
|
|
12
|
-
|
13
|
-
|
51
|
+
# @!attribute [r] notifications
|
52
|
+
# @return [Object] any object that responds to `instrument`
|
53
|
+
attr_reader :notifications
|
14
54
|
|
15
|
-
|
16
|
-
|
17
|
-
|
55
|
+
# @api private
|
56
|
+
def initialize(name, notifications)
|
57
|
+
@name = name
|
58
|
+
@notifications = notifications
|
59
|
+
define_log_connection_yield
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# @api private
|
65
|
+
def define_log_connection_yield
|
66
|
+
name = self.name
|
67
|
+
notifications = self.notifications
|
68
|
+
|
69
|
+
define_method(:log_connection_yield) do |*args, &block|
|
70
|
+
notifications.instrument(:sql, name: name, query: args[0]) do
|
71
|
+
super(*args, &block)
|
72
|
+
end
|
18
73
|
end
|
19
74
|
end
|
20
75
|
end
|
76
|
+
|
77
|
+
# Add `:notifications` option to a relation
|
78
|
+
#
|
79
|
+
# @api private
|
80
|
+
def self.included(klass)
|
81
|
+
super
|
82
|
+
klass.option :notifications
|
83
|
+
end
|
21
84
|
end
|
22
85
|
end
|
23
86
|
end
|
@@ -27,7 +27,7 @@ module ROM
|
|
27
27
|
def gateway
|
28
28
|
if env.nil?
|
29
29
|
Gateway.instance ||
|
30
|
-
raise(MissingEnv, "Set up a
|
30
|
+
raise(MissingEnv, "Set up a configuration with ROM::SQL::RakeSupport.env= in the db:setup task")
|
31
31
|
else
|
32
32
|
env.gateways[:default]
|
33
33
|
end
|
data/lib/rom/sql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
246
|
version: '0'
|
247
247
|
requirements: []
|
248
248
|
rubyforge_project:
|
249
|
-
rubygems_version: 2.6.
|
249
|
+
rubygems_version: 2.6.13
|
250
250
|
signing_key:
|
251
251
|
specification_version: 4
|
252
252
|
summary: SQL databases support for ROM
|