evt-message_store-postgres 0.4.1.0 → 0.4.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e829f486640cb338fad6c776a2228d4d2d262424
|
4
|
+
data.tar.gz: 4cfe187dd12a3edf49ed372d2ade361cb53f2685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae5549046f2eae1f2054c08d0acc8e6e68dbc1b02f209c09164a29c0f8335e03c767461250f3eedd799a07df70c0a5030db72afd24bd47ad2bf2199b26f4674
|
7
|
+
data.tar.gz: a0d19f8e82707204f388898977ec07dd220e3efb9f8770db4ba3d5c1144da3de75c3be6880e78dd3244eb4e5372bdfde0c4871d9fc77117612dcea031b6a1f80
|
@@ -3,19 +3,19 @@ module MessageStore
|
|
3
3
|
class Get
|
4
4
|
include MessageStore::Get
|
5
5
|
|
6
|
-
initializer :batch_size
|
6
|
+
initializer :batch_size, :condition
|
7
7
|
|
8
8
|
dependency :session, Session
|
9
9
|
|
10
|
-
def self.build(batch_size: nil, session: nil)
|
11
|
-
new(batch_size).tap do |instance|
|
10
|
+
def self.build(batch_size: nil, session: nil, condition: nil)
|
11
|
+
new(batch_size, condition).tap do |instance|
|
12
12
|
instance.configure(session: session)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.configure(receiver, attr_name: nil, position: nil, batch_size: nil, session: nil)
|
16
|
+
def self.configure(receiver, attr_name: nil, position: nil, batch_size: nil, condition: nil, session: nil)
|
17
17
|
attr_name ||= :get
|
18
|
-
instance = build(batch_size: batch_size, session: session)
|
18
|
+
instance = build(batch_size: batch_size, condition: condition, session: session)
|
19
19
|
receiver.public_send "#{attr_name}=", instance
|
20
20
|
end
|
21
21
|
|
@@ -23,8 +23,8 @@ module MessageStore
|
|
23
23
|
Session.configure self, session: session
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.call(stream_name, position: nil, batch_size: nil, session: nil)
|
27
|
-
instance = build(batch_size: batch_size, session: session)
|
26
|
+
def self.call(stream_name, position: nil, batch_size: nil, condition: nil, session: nil)
|
27
|
+
instance = build(batch_size: batch_size, condition: condition, session: session)
|
28
28
|
instance.(stream_name, position: position)
|
29
29
|
end
|
30
30
|
|
@@ -42,13 +42,15 @@ module MessageStore
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def get_records(stream_name, position)
|
45
|
-
logger.trace { "Getting records (Stream: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect})" }
|
45
|
+
logger.trace { "Getting records (Stream: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition || '(none)'})" }
|
46
46
|
|
47
|
-
|
47
|
+
where_fragment = self.condition
|
48
|
+
|
49
|
+
select_statement = SelectStatement.build(stream_name, position: position, batch_size: batch_size, condition: condition)
|
48
50
|
|
49
51
|
records = session.execute(select_statement.sql)
|
50
52
|
|
51
|
-
logger.debug { "Finished getting records (Count: #{records.ntuples}, Stream: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect})" }
|
53
|
+
logger.debug { "Finished getting records (Count: #{records.ntuples}, Stream: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition || '(none)'})" }
|
52
54
|
|
53
55
|
records
|
54
56
|
end
|
@@ -4,7 +4,7 @@ module MessageStore
|
|
4
4
|
class SelectStatement
|
5
5
|
include Log::Dependency
|
6
6
|
|
7
|
-
initializer :stream_name, w(:position), w(:batch_size)
|
7
|
+
initializer :stream_name, w(:position), w(:batch_size), :condition
|
8
8
|
|
9
9
|
def position
|
10
10
|
@position ||= Defaults.position
|
@@ -22,14 +22,16 @@ module MessageStore
|
|
22
22
|
is_category_stream ||= StreamName.category?(stream_name)
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.build(stream_name, position: nil, batch_size: nil)
|
26
|
-
new(stream_name, position, batch_size)
|
25
|
+
def self.build(stream_name, position: nil, batch_size: nil, condition: nil)
|
26
|
+
new(stream_name, position, batch_size, condition)
|
27
27
|
end
|
28
28
|
|
29
29
|
def sql
|
30
|
-
logger.trace(tag: :sql) { "Composing select statement (Stream: #{stream_name}, Category: #{category_stream?}, Types: #{stream_type_list.inspect}, Position: #{position}, Batch Size: #{batch_size})" }
|
30
|
+
logger.trace(tag: :sql) { "Composing select statement (Stream: #{stream_name}, Category: #{category_stream?}, Types: #{stream_type_list.inspect}, Position: #{position}, Batch Size: #{batch_size}, Condition: #{condition || '(none)'})" }
|
31
31
|
|
32
|
-
|
32
|
+
formatted_where_clause = where_clause.each_line.to_a.join(" ")
|
33
|
+
|
34
|
+
statement = <<~SQL
|
33
35
|
SELECT
|
34
36
|
id::varchar,
|
35
37
|
stream_name::varchar,
|
@@ -42,8 +44,7 @@ module MessageStore
|
|
42
44
|
FROM
|
43
45
|
messages
|
44
46
|
WHERE
|
45
|
-
#{
|
46
|
-
#{position_field} >= #{position}
|
47
|
+
#{formatted_where_clause}
|
47
48
|
ORDER BY
|
48
49
|
#{position_field} ASC
|
49
50
|
LIMIT
|
@@ -51,13 +52,26 @@ module MessageStore
|
|
51
52
|
;
|
52
53
|
SQL
|
53
54
|
|
54
|
-
logger.debug(tag: :sql) { "Composed select statement (Stream: #{stream_name}, Category: #{category_stream?}, Types: #{stream_type_list.inspect}, Position: #{position}, Batch Size: #{batch_size})" }
|
55
|
+
logger.debug(tag: :sql) { "Composed select statement (Stream: #{stream_name}, Category: #{category_stream?}, Types: #{stream_type_list.inspect}, Position: #{position}, Batch Size: #{batch_size}, Condition: #{condition || '(none)'})" }
|
55
56
|
logger.debug(tags: [:data, :sql]) { "Statement: #{statement}" }
|
56
57
|
|
57
58
|
statement
|
58
59
|
end
|
59
60
|
|
60
|
-
def
|
61
|
+
def where_clause
|
62
|
+
clause = <<~SQL.chomp
|
63
|
+
#{discriminator_field} = '#{stream_name}' AND
|
64
|
+
#{position_field} >= #{position}
|
65
|
+
SQL
|
66
|
+
|
67
|
+
unless condition.nil?
|
68
|
+
clause << " AND\n(#{condition})"
|
69
|
+
end
|
70
|
+
|
71
|
+
clause
|
72
|
+
end
|
73
|
+
|
74
|
+
def discriminator_field
|
61
75
|
unless category_stream?
|
62
76
|
'stream_name'
|
63
77
|
else
|
@@ -3,9 +3,9 @@ module MessageStore
|
|
3
3
|
class Read
|
4
4
|
include MessageStore::Read
|
5
5
|
|
6
|
-
def configure(session: nil)
|
6
|
+
def configure(session: nil, condition: nil)
|
7
7
|
Iterator.configure(self, stream_name, position: position)
|
8
|
-
Get.configure(self.iterator, batch_size: batch_size, session: session)
|
8
|
+
Get.configure(self.iterator, batch_size: batch_size, condition: condition, session: session)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-message_store-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: scripts
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-message_store
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.6.
|
152
|
+
rubygems_version: 2.6.14
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Message store implementation for PostgreSQL
|