jade-sql 0.9.0 → 0.9.1
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/lib/jade-sql/runtime.rb +32 -33
- data/lib/jade-sql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1d437d0d6f0732ff240bc1833dd724ab0ddb17f11f048f64484971d4986c189a
|
|
4
|
+
data.tar.gz: 7570a5c8616b4281d64535e577dd9c70a504c285197ede6bda39e07b1061e397
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 88fd20a47981bd6735bee0d63fcb65d950c34da7b4deaa5f4d132f6d8342a2fe7c0f9db78628fbdfe043e001262e1751eec24528eef449234f0746076b791304
|
|
7
|
+
data.tar.gz: aab1dbb9f6a251c3b61827bd605cb89ac81ca783f13f421db0093831c294556a863e3321e75e39531cc204a25693be8434a7caf3535b978b0712e100cc6454ff
|
data/lib/jade-sql/runtime.rb
CHANGED
|
@@ -171,52 +171,51 @@ module JadeSql
|
|
|
171
171
|
raw == "NULL" ? nil : raw
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
-
#
|
|
175
|
-
#
|
|
174
|
+
# Read from Postgres rather than from ActiveRecord's classes for these,
|
|
175
|
+
# which lag it: `CheckViolation` arrived in Rails 8.
|
|
176
|
+
#
|
|
177
|
+
# https://www.postgresql.org/docs/current/errcodes-appendix.html
|
|
178
|
+
BY_SQLSTATE = {
|
|
179
|
+
'23505' => ->(e) { SqlErrors.unique_violation(constraint_name(e)) },
|
|
180
|
+
'23503' => ->(e) { SqlErrors.foreign_key_violation(constraint_name(e)) },
|
|
181
|
+
'23514' => ->(e) { SqlErrors.check_violation(constraint_name(e)) },
|
|
182
|
+
'23P01' => ->(e) { SqlErrors.exclusion_violation(constraint_name(e)) },
|
|
183
|
+
'23502' => ->(e) { SqlErrors.not_null_violation(column_name(e)) },
|
|
184
|
+
'40P01' => ->(_e) { SqlErrors.deadlock },
|
|
185
|
+
'40001' => ->(_e) { SqlErrors.serialization_failure },
|
|
186
|
+
'57014' => ->(_e) { SqlErrors.statement_timeout },
|
|
187
|
+
'55P03' => ->(_e) { SqlErrors.lock_timeout },
|
|
188
|
+
}.freeze
|
|
189
|
+
|
|
176
190
|
def self.translate(error)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
when ::ActiveRecord::ExclusionViolation
|
|
185
|
-
JadeSql::SqlErrors.exclusion_violation(constraint_name(error))
|
|
186
|
-
when ::ActiveRecord::NotNullViolation
|
|
187
|
-
JadeSql::SqlErrors.not_null_violation(column_name(error))
|
|
188
|
-
when ::ActiveRecord::Deadlocked
|
|
189
|
-
JadeSql::SqlErrors.deadlock
|
|
190
|
-
when ::ActiveRecord::SerializationFailure
|
|
191
|
-
JadeSql::SqlErrors.serialization_failure
|
|
192
|
-
when ::ActiveRecord::LockWaitTimeout
|
|
193
|
-
JadeSql::SqlErrors.lock_timeout
|
|
194
|
-
when ::ActiveRecord::QueryCanceled, ::ActiveRecord::StatementTimeout
|
|
195
|
-
JadeSql::SqlErrors.statement_timeout
|
|
196
|
-
else
|
|
197
|
-
JadeSql::SqlErrors.db_error(error.message)
|
|
198
|
-
end
|
|
191
|
+
BY_SQLSTATE[sqlstate(error)]
|
|
192
|
+
&.call(error) || SqlErrors.db_error(error.message)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Nil for anything that did not come back from Postgres.
|
|
196
|
+
def self.sqlstate(error)
|
|
197
|
+
diagnostic(error, ::PG::Result::PG_DIAG_SQLSTATE)
|
|
199
198
|
end
|
|
200
199
|
|
|
201
200
|
# The constraint/index name behind a violation, so callers can route by
|
|
202
201
|
# which one it was. PG reports it in the error's diagnostics; other
|
|
203
202
|
# adapters (or a missing name) fall back to "".
|
|
204
203
|
def self.constraint_name(error)
|
|
205
|
-
|
|
206
|
-
return "" unless defined?(::PG::Result) && cause.respond_to?(:result) && cause.result
|
|
207
|
-
|
|
208
|
-
cause.result.error_field(::PG::Result::PG_DIAG_CONSTRAINT_NAME) || ""
|
|
209
|
-
rescue StandardError
|
|
210
|
-
""
|
|
204
|
+
diagnostic(error, ::PG::Result::PG_DIAG_CONSTRAINT_NAME) || ""
|
|
211
205
|
end
|
|
212
206
|
|
|
213
207
|
def self.column_name(error)
|
|
208
|
+
diagnostic(error, ::PG::Result::PG_DIAG_COLUMN_NAME) || ""
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def self.diagnostic(error, field)
|
|
214
213
|
cause = error.cause
|
|
215
|
-
return
|
|
214
|
+
return nil unless defined?(::PG::Result) && cause.respond_to?(:result) && cause.result
|
|
216
215
|
|
|
217
|
-
cause.result.error_field(
|
|
216
|
+
cause.result.error_field(field)
|
|
218
217
|
rescue StandardError
|
|
219
|
-
|
|
218
|
+
nil
|
|
220
219
|
end
|
|
221
220
|
|
|
222
221
|
# Sql.Write.timestamped emits "$JADE_SQL_NOW$" where created_at /
|
data/lib/jade-sql/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jade-sql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- agustin
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-09-
|
|
10
|
+
date: 2026-09-18 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: jade-lang
|