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: cc9b47b80bd694b53052b54ca2647989e6bfd911c1a0f2e59056d61cfccf075e
4
- data.tar.gz: a306ba71a2c62db295b438c6583f61a765d425a8f2888c328b831df31bf9840b
3
+ metadata.gz: 69922615a71c6eefbe25e734208f52099110685db3ad28073dd79e284ec3381b
4
+ data.tar.gz: 47e713a1a9336e51dcb6e446e23d3364f2bcf8f23ff944a0b52e2a7d4e49acbf
5
5
  SHA512:
6
- metadata.gz: f73376471edf444dfc0f2c5dd702d2727a280c307f440da3a367d7d594074a9654e8b20fa58c19c2c6e57a4ab393dbacf17bb8044be82867e9fe7528d5b78874
7
- data.tar.gz: 8988590d661ac5c872df12f3e467f939bdb71f291d9485eab31227d3ea3afa3773f8ad8d885f2a91e3b8d3856e92835fc1a2381ceee79978185206b6f52e5479
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
@@ -1,5 +1,5 @@
1
1
  module Turbopuffer
2
2
  module ActiveRecord
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-turbopuffer-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Monette