pg-ephemeral 0.2.2-aarch64-linux → 0.2.3-aarch64-linux
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 +146 -0
- data/bin/pg-ephemeral +0 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30827d60bff661ffab35406253c1154ab6d2a9cc3a8b845e2fbde4aabaad33e3
|
|
4
|
+
data.tar.gz: 413fc8d945038b6848d8d80d0536e8a272cdf3a101dc2436b3f6fa8738e51e0c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f36ca8fbad77763cf4ff64990a19cae7e0445bddcdbb43e59fd592916cd6be4284e814421714d2ab780e14bf233c08b5d366ca905562dfe8f2ff9768e7a346b0
|
|
7
|
+
data.tar.gz: 730edec285df9579c9865567c6d87fb7ee1ae1e475717d8cefae771bf793f60a61b622a096d69daecfba11fb720c9ac23069dea5e5f0a6b6a4f27045df27a620
|
data/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# pg-ephemeral Ruby Gem
|
|
2
|
+
|
|
3
|
+
Ruby wrapper for [pg-ephemeral](https://github.com/mbj/mrs/tree/main/pg-ephemeral). Bundles the platform-specific binary
|
|
4
|
+
and provides a native API for ephemeral PostgreSQL instances.
|
|
5
|
+
|
|
6
|
+
Published on RubyGems: [pg-ephemeral](https://rubygems.org/gems/pg-ephemeral)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'pg-ephemeral'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The gem ships with prebuilt binaries for `x86_64-linux`, `aarch64-linux`, and `arm64-darwin`.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Direct connection
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
PgEphemeral.with_connection do |conn|
|
|
22
|
+
conn.exec("SELECT 1 AS value")
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`with_connection` yields a `PG::Connection` and closes it after the block.
|
|
27
|
+
|
|
28
|
+
### Server handle
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
PgEphemeral.with_server do |server|
|
|
32
|
+
puts server.url # => "postgres://postgres:...@127.0.0.1:54321/postgres"
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`with_server` yields a `Server` with a `.url` accessor. The container shuts down
|
|
37
|
+
after the block.
|
|
38
|
+
|
|
39
|
+
### Options
|
|
40
|
+
|
|
41
|
+
Both `with_connection` and `with_server` accept:
|
|
42
|
+
|
|
43
|
+
| Option | Description | Default |
|
|
44
|
+
|-----------------|--------------------------------------------------|------------|
|
|
45
|
+
| `instance_name` | Target instance from `database.toml` | `"main"` |
|
|
46
|
+
| `config` | Path to a `database.toml` config file | auto-detect |
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
PgEphemeral.with_connection(instance_name: "analytics", config: "path/to/database.toml") do |conn|
|
|
50
|
+
conn.exec("SELECT 1")
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Manual lifecycle
|
|
55
|
+
|
|
56
|
+
For cases where the block form doesn't fit:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
server = PgEphemeral.start
|
|
60
|
+
connection = PG.connect(server.url)
|
|
61
|
+
# ...
|
|
62
|
+
connection.close
|
|
63
|
+
server.shutdown
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Utilities
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
PgEphemeral.version # => "0.2.0"
|
|
70
|
+
PgEphemeral.platform_supported? # => true
|
|
71
|
+
PgEphemeral.binary_path # => "/path/to/pg-ephemeral"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Test Framework Integration
|
|
75
|
+
|
|
76
|
+
### RSpec
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
RSpec.describe UserRepository do
|
|
80
|
+
before(:all) do
|
|
81
|
+
@server = PgEphemeral.start
|
|
82
|
+
@connection = PG.connect(@server.url)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
after(:all) do
|
|
86
|
+
@connection.close
|
|
87
|
+
@server.shutdown
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'inserts a user' do
|
|
91
|
+
@connection.exec("INSERT INTO users (name) VALUES ('alice')")
|
|
92
|
+
result = @connection.exec("SELECT name FROM users")
|
|
93
|
+
expect(result.first['name']).to eq('alice')
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Rails
|
|
99
|
+
|
|
100
|
+
Configure pg-ephemeral in `spec/support/pg_ephemeral.rb` so ActiveRecord
|
|
101
|
+
connects to the ephemeral instance:
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
RSpec.configure do |config|
|
|
105
|
+
config.before(:suite) do
|
|
106
|
+
@server = PgEphemeral.start
|
|
107
|
+
ENV['DATABASE_URL'] = @server.url
|
|
108
|
+
ActiveRecord::Base.establish_connection
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
config.after(:suite) do
|
|
112
|
+
@server.shutdown
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Schema and seed data are applied via `database.toml` seeds, so the database
|
|
118
|
+
is ready before the suite starts.
|
|
119
|
+
|
|
120
|
+
### Minitest
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
# test/test_helper.rb
|
|
124
|
+
SERVER = PgEphemeral.start
|
|
125
|
+
CONNECTION = PG.connect(SERVER.url)
|
|
126
|
+
|
|
127
|
+
Minitest.after_run do
|
|
128
|
+
CONNECTION.close
|
|
129
|
+
SERVER.shutdown
|
|
130
|
+
end
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
class UserRepositoryTest < Minitest::Test
|
|
135
|
+
def test_inserts_a_user
|
|
136
|
+
CONNECTION.exec("INSERT INTO users (name) VALUES ('alice')")
|
|
137
|
+
result = CONNECTION.exec("SELECT name FROM users")
|
|
138
|
+
assert_equal 'alice', result.first['name']
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Requirements
|
|
144
|
+
|
|
145
|
+
- Ruby >= 3.3
|
|
146
|
+
- Docker Engine 20.10+ / Docker Desktop 4.34+, or Podman 5.3+
|
data/bin/pg-ephemeral
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pg-ephemeral
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Markus Schirp
|
|
@@ -32,6 +32,7 @@ extensions: []
|
|
|
32
32
|
extra_rdoc_files: []
|
|
33
33
|
files:
|
|
34
34
|
- LICENSE.txt
|
|
35
|
+
- README.md
|
|
35
36
|
- bin/pg-ephemeral
|
|
36
37
|
- lib/pg_ephemeral.rb
|
|
37
38
|
homepage: https://github.com/mbj/mrs/tree/main/pg-ephemeral
|