aurora-dsql-ruby-pg 1.0.0 → 1.1.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 +4 -4
- data/README.md +12 -3
- data/lib/aurora_dsql/pg/config.rb +3 -16
- data/lib/aurora_dsql/pg/pool.rb +7 -7
- data/lib/aurora_dsql/pg/version.rb +1 -1
- data/lib/aurora_dsql_pg.rb +11 -4
- metadata +2 -3
- data/lib/aurora_dsql/pg/connection.rb +0 -72
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec5cb524ab6a027a0de03dcde02ce0fbf4f78500bc95a29c125effad05919a77
|
|
4
|
+
data.tar.gz: 0a439698df60a0cbead79acbc54a6dda99ecdc60b2bcff497acef51badb6cf35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ab34f0bafb57cc66f3e987d8a94f0005f226e6f4e3cf9ddc17c152b4dc7c0b54bbac8258073b8152fdc7a60fa3b29807f718d5381c96d8819cc1712621c0f78
|
|
7
|
+
data.tar.gz: 5bc9d25804798be0c2c1d9066f0d09ca6d80e514e416fd45e762867e4bb0b329386f84484a89686d9bfa5a1597a189572f27d3e9c87a976f6b705c83a2f28c11
|
data/README.md
CHANGED
|
@@ -87,13 +87,22 @@ pool.shutdown
|
|
|
87
87
|
| `profile` | `String` | `nil` | AWS profile name |
|
|
88
88
|
| `token_duration` | `Integer` | `900` (15 min) | Token validity in seconds |
|
|
89
89
|
| `credentials_provider` | `Aws::Credentials` | `nil` | Custom credentials |
|
|
90
|
-
| `pool_size` | `Integer` | `5` | Connection pool size |
|
|
91
|
-
| `checkout_timeout` | `Integer` | `5` | Seconds to wait for a pool connection |
|
|
92
90
|
| `max_lifetime` | `Integer` | `3300` (55 min) | Max connection lifetime in seconds |
|
|
93
91
|
| `application_name` | `String` | `nil` | ORM prefix for application_name |
|
|
94
92
|
| `logger` | `Logger` | `nil` | Logger for OCC retry warnings |
|
|
95
93
|
| `occ_max_retries` | `Integer` | `nil` (disabled) | Max OCC retries on `pool.with`; enables retry when set |
|
|
96
94
|
|
|
95
|
+
### Pool Options
|
|
96
|
+
|
|
97
|
+
`create_pool` accepts a `pool:` keyword with a hash of options passed directly to [`ConnectionPool.new`](https://github.com/mperham/connection_pool). Defaults: `{size: 5, timeout: 5}`.
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
pool = AuroraDsql::Pg.create_pool(
|
|
101
|
+
host: "your-cluster.dsql.us-east-1.on.aws",
|
|
102
|
+
pool: { size: 10, timeout: 10 }
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
97
106
|
## Connection String Format
|
|
98
107
|
|
|
99
108
|
```ruby
|
|
@@ -110,7 +119,7 @@ conn.exec("SELECT 1")
|
|
|
110
119
|
conn.close
|
|
111
120
|
```
|
|
112
121
|
|
|
113
|
-
|
|
122
|
+
`connect` returns a standard `PG::Connection`.
|
|
114
123
|
|
|
115
124
|
## OCC Retry
|
|
116
125
|
|
|
@@ -12,15 +12,12 @@ module AuroraDsql
|
|
|
12
12
|
database: "postgres",
|
|
13
13
|
port: 5432,
|
|
14
14
|
max_lifetime: 55 * 60, # 55 minutes in seconds
|
|
15
|
-
token_duration: 15 * 60
|
|
16
|
-
pool_size: 5,
|
|
17
|
-
checkout_timeout: 5 # seconds to wait for a pool connection
|
|
15
|
+
token_duration: 15 * 60 # 15 minutes in seconds
|
|
18
16
|
}.freeze
|
|
19
17
|
|
|
20
18
|
attr_accessor :host, :region, :user, :database, :port,
|
|
21
19
|
:profile, :token_duration, :credentials_provider,
|
|
22
|
-
:max_lifetime, :
|
|
23
|
-
:application_name, :logger, :occ_max_retries
|
|
20
|
+
:max_lifetime, :application_name, :logger, :occ_max_retries
|
|
24
21
|
|
|
25
22
|
def initialize(**options)
|
|
26
23
|
@host = options[:host]
|
|
@@ -32,8 +29,6 @@ module AuroraDsql
|
|
|
32
29
|
@token_duration = options[:token_duration]
|
|
33
30
|
@credentials_provider = options[:credentials_provider]
|
|
34
31
|
@max_lifetime = options[:max_lifetime]
|
|
35
|
-
@pool_size = options[:pool_size]
|
|
36
|
-
@checkout_timeout = options[:checkout_timeout]
|
|
37
32
|
@application_name = options[:application_name]
|
|
38
33
|
@logger = options[:logger]
|
|
39
34
|
@occ_max_retries = options[:occ_max_retries]
|
|
@@ -100,8 +95,6 @@ module AuroraDsql
|
|
|
100
95
|
token_duration: @token_duration || DEFAULTS[:token_duration],
|
|
101
96
|
credentials_provider: @credentials_provider,
|
|
102
97
|
max_lifetime: @max_lifetime || DEFAULTS[:max_lifetime],
|
|
103
|
-
pool_size: @pool_size || DEFAULTS[:pool_size],
|
|
104
|
-
checkout_timeout: @checkout_timeout || DEFAULTS[:checkout_timeout],
|
|
105
98
|
application_name: @application_name,
|
|
106
99
|
logger: @logger,
|
|
107
100
|
occ_max_retries: @occ_max_retries
|
|
@@ -132,11 +125,6 @@ module AuroraDsql
|
|
|
132
125
|
def validate!
|
|
133
126
|
raise Error, "host is required" if @host.nil? || @host.empty?
|
|
134
127
|
|
|
135
|
-
if @port
|
|
136
|
-
raise Error, "port must be an integer, got #{@port.class}" unless @port.is_a?(Integer)
|
|
137
|
-
raise Error, "port must be between 1 and 65535, got #{@port}" if @port < 1 || @port > 65_535
|
|
138
|
-
end
|
|
139
|
-
|
|
140
128
|
if @occ_max_retries
|
|
141
129
|
unless @occ_max_retries.is_a?(Integer) && @occ_max_retries > 0
|
|
142
130
|
raise Error, "occ_max_retries must be a positive integer, got #{@occ_max_retries.inspect}"
|
|
@@ -149,8 +137,7 @@ module AuroraDsql
|
|
|
149
137
|
ResolvedConfig = Struct.new(
|
|
150
138
|
:host, :region, :user, :database, :port,
|
|
151
139
|
:profile, :token_duration, :credentials_provider,
|
|
152
|
-
:max_lifetime, :
|
|
153
|
-
:application_name, :logger, :occ_max_retries,
|
|
140
|
+
:max_lifetime, :application_name, :logger, :occ_max_retries,
|
|
154
141
|
keyword_init: true
|
|
155
142
|
) do
|
|
156
143
|
# Convert to pg connection parameters hash.
|
data/lib/aurora_dsql/pg/pool.rb
CHANGED
|
@@ -11,18 +11,18 @@ module AuroraDsql
|
|
|
11
11
|
# Wrapper to track connection creation time for max_lifetime enforcement.
|
|
12
12
|
PooledConnection = Struct.new(:conn, :created_at, keyword_init: true)
|
|
13
13
|
|
|
14
|
+
POOL_DEFAULTS = { size: 5, timeout: 5 }.freeze
|
|
15
|
+
|
|
14
16
|
# Create a new connection pool.
|
|
15
|
-
def self.create(config = nil, **options)
|
|
16
|
-
new(Config.from(config, **options).resolve)
|
|
17
|
+
def self.create(config = nil, pool: {}, **options)
|
|
18
|
+
new(Config.from(config, **options).resolve, pool)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
def initialize(resolved_config)
|
|
21
|
+
def initialize(resolved_config, pool_options = {})
|
|
20
22
|
@config = resolved_config
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
timeout: resolved_config.checkout_timeout
|
|
25
|
-
) { create_connection }
|
|
24
|
+
effective_pool = POOL_DEFAULTS.merge(pool_options)
|
|
25
|
+
@pool = ConnectionPool.new(**effective_pool) { create_connection }
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# Maximum stale connection discards before giving up.
|
data/lib/aurora_dsql_pg.rb
CHANGED
|
@@ -5,7 +5,6 @@ require_relative "aurora_dsql/pg/version"
|
|
|
5
5
|
require_relative "aurora_dsql/pg/util"
|
|
6
6
|
require_relative "aurora_dsql/pg/config"
|
|
7
7
|
require_relative "aurora_dsql/pg/token"
|
|
8
|
-
require_relative "aurora_dsql/pg/connection"
|
|
9
8
|
require_relative "aurora_dsql/pg/pool"
|
|
10
9
|
require_relative "aurora_dsql/pg/occ_retry"
|
|
11
10
|
|
|
@@ -14,13 +13,21 @@ module AuroraDsql
|
|
|
14
13
|
class Error < StandardError; end
|
|
15
14
|
|
|
16
15
|
# Create a single connection to Aurora DSQL.
|
|
16
|
+
# Returns a PG::Connection.
|
|
17
17
|
def self.connect(config = nil, **options)
|
|
18
|
-
|
|
18
|
+
resolved = Config.from(config, **options).resolve
|
|
19
|
+
token = Token.generate(
|
|
20
|
+
host: resolved.host, region: resolved.region,
|
|
21
|
+
user: resolved.user, credentials: resolved.credentials_provider,
|
|
22
|
+
profile: resolved.profile, expires_in: resolved.token_duration
|
|
23
|
+
)
|
|
24
|
+
PG.connect(resolved.to_pg_params(password: token))
|
|
19
25
|
end
|
|
20
26
|
|
|
21
27
|
# Create a connection pool for Aurora DSQL.
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
# Pass pool: { size: N, timeout: N } to configure ConnectionPool.
|
|
29
|
+
def self.create_pool(config = nil, pool: {}, **options)
|
|
30
|
+
Pool.create(config, pool: pool, **options)
|
|
24
31
|
end
|
|
25
32
|
end
|
|
26
33
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aurora-dsql-ruby-pg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Amazon Web Services
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pg
|
|
@@ -98,7 +98,6 @@ files:
|
|
|
98
98
|
- NOTICE
|
|
99
99
|
- README.md
|
|
100
100
|
- lib/aurora_dsql/pg/config.rb
|
|
101
|
-
- lib/aurora_dsql/pg/connection.rb
|
|
102
101
|
- lib/aurora_dsql/pg/occ_retry.rb
|
|
103
102
|
- lib/aurora_dsql/pg/pool.rb
|
|
104
103
|
- lib/aurora_dsql/pg/token.rb
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
require "pg"
|
|
5
|
-
|
|
6
|
-
module AuroraDsql
|
|
7
|
-
module Pg
|
|
8
|
-
# Single connection wrapper for Aurora DSQL.
|
|
9
|
-
class Connection
|
|
10
|
-
attr_reader :pg_conn, :config
|
|
11
|
-
|
|
12
|
-
# Create a new connection to Aurora DSQL.
|
|
13
|
-
def self.connect(config = nil, **options)
|
|
14
|
-
resolved = Config.from(config, **options).resolve
|
|
15
|
-
|
|
16
|
-
token = Token.generate(
|
|
17
|
-
host: resolved.host,
|
|
18
|
-
region: resolved.region,
|
|
19
|
-
user: resolved.user,
|
|
20
|
-
credentials: resolved.credentials_provider,
|
|
21
|
-
profile: resolved.profile,
|
|
22
|
-
expires_in: resolved.token_duration
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
pg_conn = ::PG.connect(resolved.to_pg_params(password: token))
|
|
26
|
-
new(pg_conn, resolved)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def initialize(pg_conn, config)
|
|
30
|
-
@pg_conn = pg_conn
|
|
31
|
-
@config = config
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Delegate common pg methods
|
|
35
|
-
|
|
36
|
-
def exec_params(...)
|
|
37
|
-
@pg_conn.exec_params(...)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def query(...)
|
|
41
|
-
@pg_conn.query(...)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def transaction(...)
|
|
45
|
-
@pg_conn.transaction(...)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def close
|
|
49
|
-
@pg_conn.close
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def finished?
|
|
53
|
-
@pg_conn.finished?
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
# Delegate remaining methods to PG::Connection.
|
|
59
|
-
def method_missing(method, ...)
|
|
60
|
-
if @pg_conn.respond_to?(method)
|
|
61
|
-
@pg_conn.send(method, ...)
|
|
62
|
-
else
|
|
63
|
-
super
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def respond_to_missing?(method, include_private = false)
|
|
68
|
-
@pg_conn.respond_to?(method, include_private) || super
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|