You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When node:sqlite throws an exception from deno, we get an Error with a message about unique constraints. When used in node v23, it throws an Error with a code, errcode, and errstr that all make detecting a unique constraint issue much easier. This is important when building applications have database constraints, since a lot of these kinds of unique constraints need to be bubbled up to the user. This is especially problematic when a unique constraint error happens from a prepared statement in deno. In that case, we dont actually have any error string information we can use to tell if the exception was a unique constraint
deno error output:
Deno 2.2.1
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import * as sqlite from 'node:sqlite'
undefined
> let db = new sqlite.DatabaseSync(':memory:')
undefined
> db.exec('CREATE TABLE person ( name TEXT NOT NULL UNIQUE );')
null
> db.exec(`INSERT INTO person (name) VALUES ('johnny')`)
null
> db.exec(`INSERT INTO person (name) VALUES ('johnny')`)
Uncaught Error: UNIQUE constraint failed: person.name
at <anonymous>:1:25
> db.prepare(`INSERT INTO person (name) VALUES ('johnny')`).run()
Uncaught Error: Failed to step statement
at <anonymous>:1:80
>
node error output:
Welcome to Node.js v23.8.0.
Type ".help" for more information.
> const sqlite = require('node:sqlite')
undefined
> (node:44980) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
> db = new sqlite.DatabaseSync(':memory:')
DatabaseSync {}
> db.exec('CREATE TABLE person ( name TEXT NOT NULL UNIQUE );')
undefined
> db.exec(`INSERT INTO person (name) VALUES ('johnny')`)
undefined
> db.exec(`INSERT INTO person (name) VALUES ('johnny')`)
Uncaught [Error: UNIQUE constraint failed: person.name] {
code: 'ERR_SQLITE_ERROR',
errcode: 2067,
errstr: 'constraint failed'
}
> db.prepare(`INSERT INTO person (name) VALUES ('johnny')`).run()
Uncaught [Error: UNIQUE constraint failed: person.name] {
code: 'ERR_SQLITE_ERROR',
errcode: 2067,
errstr: 'constraint failed'
}
The text was updated successfully, but these errors were encountered:
Version: Deno 2.2.1
When node:sqlite throws an exception from deno, we get an
Error
with a message about unique constraints. When used in node v23, it throws anError
with acode
,errcode
, anderrstr
that all make detecting a unique constraint issue much easier. This is important when building applications have database constraints, since a lot of these kinds of unique constraints need to be bubbled up to the user. This is especially problematic when a unique constraint error happens from a prepared statement in deno. In that case, we dont actually have any error string information we can use to tell if the exception was a unique constraintdeno error output:
node error output:
The text was updated successfully, but these errors were encountered: