activerecord-turbopuffer-adapter 0.1.3 → 0.1.4
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69922615a71c6eefbe25e734208f52099110685db3ad28073dd79e284ec3381b
|
|
4
|
+
data.tar.gz: 47e713a1a9336e51dcb6e446e23d3364f2bcf8f23ff944a0b52e2a7d4e49acbf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b366354338fd3d15e689340dbddf279ebf4b4d3823412ae1ef95d21eca48d1a06b492738b1aa21c9abb87e77906e2d3f07b67e71f80b61241e1f3143126946d
|
|
7
|
+
data.tar.gz: fe83fd43d546c5e07e19fcc38a14760b2810955f5e3398ce4b4895c19280fa3c77dc88874a6bb771ff5572fd90a6a9ebd13bb0563c2a69fa40de5375b6fa34fa
|
data/README.md
CHANGED
|
@@ -120,6 +120,24 @@ Document
|
|
|
120
120
|
|
|
121
121
|
> Eventual reads are cheaper but may not include writes from the last few seconds. Set a default with `turbopuffer_consistency "eventual"` in a model or `consistency: eventual` in `database.yml`. Strong is the default.
|
|
122
122
|
|
|
123
|
+
### Errors
|
|
124
|
+
|
|
125
|
+
Turbopuffer errors are raised as the ActiveRecord exceptions a Rails app already handles.
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
begin
|
|
129
|
+
Document.where(published: true).to_a
|
|
130
|
+
rescue ActiveRecord::ConnectionFailed
|
|
131
|
+
# turbopuffer is unreachable
|
|
132
|
+
rescue ActiveRecord::StatementTimeout
|
|
133
|
+
# the request timed out
|
|
134
|
+
rescue ActiveRecord::DatabaseConnectionError
|
|
135
|
+
# the API key is invalid
|
|
136
|
+
rescue ActiveRecord::StatementInvalid => e
|
|
137
|
+
e.cause # => the underlying Turbopuffer::Errors::APIError, e.g. a bad request or rate limit
|
|
138
|
+
end
|
|
139
|
+
```
|
|
140
|
+
|
|
123
141
|
### Using alongside Postgres
|
|
124
142
|
|
|
125
143
|
While something of a lark, aspirationally the idea of this gem is to make turbopuffer conveniently usable as the primary db in a Rails app. In practice, however, using turbopuffer alongside a traditional primary db (such as postgres) is a supported, potentially more practical solution.
|
|
@@ -363,6 +363,19 @@ module ActiveRecord
|
|
|
363
363
|
def reconnect
|
|
364
364
|
connect
|
|
365
365
|
end
|
|
366
|
+
|
|
367
|
+
def translate_exception(exception, message:, sql:, binds:)
|
|
368
|
+
case exception
|
|
369
|
+
when Turbopuffer::Errors::APITimeoutError
|
|
370
|
+
ActiveRecord::StatementTimeout.new(message, sql: sql, binds: binds, connection_pool: @pool)
|
|
371
|
+
when Turbopuffer::Errors::APIConnectionError
|
|
372
|
+
ActiveRecord::ConnectionFailed.new(message, sql: sql, binds: binds, connection_pool: @pool)
|
|
373
|
+
when Turbopuffer::Errors::AuthenticationError, Turbopuffer::Errors::PermissionDeniedError
|
|
374
|
+
ActiveRecord::DatabaseConnectionError.new(message)
|
|
375
|
+
else
|
|
376
|
+
super
|
|
377
|
+
end
|
|
378
|
+
end
|
|
366
379
|
end
|
|
367
380
|
end
|
|
368
381
|
end
|