pg_eventstore 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 578f1d0622ac152a16faddccf8d8b7a6253048a4455af9b0912a9bddb086a96f
4
- data.tar.gz: 479c28dc87c6e89e21c4a84847d837a8e9adb9f6c757d1d673d94504ba9267d6
3
+ metadata.gz: 2e22bb2356955ece89a16f5d43b803670d0304eaf27d2fedbf1daf12aa908812
4
+ data.tar.gz: 31d95e0380be2ad8dd7306a1b04a8a14e6f4f32f6bcdb8864e42205c0a1fe9bc
5
5
  SHA512:
6
- metadata.gz: 232103db9727e23cc0a387ff04544384c4509b5275b18a1231de96ceb733a74176951605b786c0f26604d956ef5a45a9ca537830683f4367712929e05b71af77
7
- data.tar.gz: f5f3bc63fe3853b492cb48127031ad0a2fb920de91368221e09d8e763259ad4b9a398b56ae901effcce18aca7ab5f127aa38f43852e14c078776ea74180108c4
6
+ metadata.gz: 8cda13e213beec47c83818301b415d1dbf5b80e0659e548c6d166a3e136172c38802b697353f13344bb0d6b15b99b54f59e950ab9fb2f07e7bf494adedb2c280
7
+ data.tar.gz: 5f0743afb46b2dcd00c9c164b51beb6f4ea6284b839a0036418d46e60e7d7b8a53d378a1eb265fc063364970ae6fb2b0091fabae51429775bec2f8c1c2e843fa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.3.0] - 2024-01-24
2
+
3
+ - Log SQL queries when `PgEvenstore.logger` is set and it is in `:debug` mode
4
+
1
5
  ## [0.2.6] - 2023-12-20
2
6
 
3
7
  - Remove `events.type` column
data/README.md CHANGED
@@ -4,8 +4,9 @@ Implements database and API to store and read events in event sourced systems.
4
4
 
5
5
  ## Requirements
6
6
 
7
- `pg_eventstore` requires a PostgreSQL database with jsonb data type support (which means you need to have v9.2+). However it is recommended to use a non [EOL](https://www.postgresql.org/support/versioning/) PostgreSQL version, because the development of this gem is targeted at current PostgreSQL versions.
8
- `pg_eventstore` requires ruby v3+. The development of this gem is targeted at [current](https://endoflife.date/ruby) ruby versions.
7
+ - `pg_eventstore` requires a PostgreSQL database with jsonb data type support (which means you need to have v9.2+). However it is recommended to use a non [EOL](https://www.postgresql.org/support/versioning/) PostgreSQL version, because the development of this gem is targeted at current PostgreSQL versions.
8
+ - It is recommend you to have the default value set for `default_transaction_isolation` PostgreSQL config setting(`"read committed"`) as the implementation relies on it. All other transaction isolation levels(`"repeatable read"` and `"serializable"`) may cause unexpected serialization errors which you will have to handle by yourself(e.g. by always wrapping your code using [`#multiple`](docs/multiple_commands.md)).
9
+ - `pg_eventstore` requires ruby v3+. The development of this gem is targeted at [current](https://endoflife.date/ruby) ruby versions.
9
10
 
10
11
  ## Installation
11
12
 
@@ -4,6 +4,7 @@ require 'pg'
4
4
  require 'pg/basic_type_map_for_results'
5
5
  require 'pg/basic_type_map_for_queries'
6
6
  require 'connection_pool'
7
+ require_relative 'pg_connection'
7
8
 
8
9
  module PgEventstore
9
10
  class Connection
@@ -73,10 +74,9 @@ module PgEventstore
73
74
  # @return [ConnectionPool]
74
75
  def init_pool
75
76
  @pool ||= ConnectionPool.new(size: pool_size, timeout: pool_timeout) do
76
- PG::Connection.new(uri).tap do |conn|
77
+ PgConnection.new(uri).tap do |conn|
77
78
  conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn, registry: pg_type_registry)
78
79
  conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(conn, registry: pg_type_registry)
79
- # conn.trace($stdout) # logs
80
80
  end
81
81
  end
82
82
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEventstore
4
+ class PgConnection < PG::Connection
5
+ def exec(sql)
6
+ log(sql, [])
7
+ super
8
+ end
9
+
10
+ def exec_params(sql, params, ...)
11
+ log(sql, params)
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+ def log(sql, params)
18
+ return unless PgEventstore.logger&.debug?
19
+
20
+ sql = sql.gsub(/\$\d+/).each do |matched|
21
+ value = params[matched[1..].to_i - 1]
22
+
23
+ value = type_map_for_queries[value.class]&.encode(value) || value
24
+ value.is_a?(String) ? "'#{value}'" : value
25
+ end unless params&.empty?
26
+ PgEventstore.logger.debug(sql)
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEventstore
4
- VERSION = "0.2.6"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Dzyzenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-20 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -83,6 +83,7 @@ files:
83
83
  - lib/pg_eventstore/event_serializer.rb
84
84
  - lib/pg_eventstore/extensions/options_extension.rb
85
85
  - lib/pg_eventstore/middleware.rb
86
+ - lib/pg_eventstore/pg_connection.rb
86
87
  - lib/pg_eventstore/pg_result_deserializer.rb
87
88
  - lib/pg_eventstore/queries.rb
88
89
  - lib/pg_eventstore/queries/event_queries.rb