diff options
author | 2021-08-29 15:41:41 +0100 | |
---|---|---|
committer | 2021-08-29 16:41:41 +0200 | |
commit | ed462245730bd7832019bd43e0bc1c9d1c055e8e (patch) | |
tree | 1caad78ea6aabf5ea93c93a8ade97176b4889500 /internal/db/bundb/errors.go | |
parent | Mention fixup (#167) (diff) | |
download | gotosocial-ed462245730bd7832019bd43e0bc1c9d1c055e8e.tar.xz |
Add SQLite support, fix un-thread-safe DB caches, small performance f… (#172)
* Add SQLite support, fix un-thread-safe DB caches, small performance fixes
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* add SQLite licenses to README
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* appease the linter, and fix my dumbass-ery
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* make requested changes
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* add back comment
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
Diffstat (limited to 'internal/db/bundb/errors.go')
-rw-r--r-- | internal/db/bundb/errors.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/db/bundb/errors.go b/internal/db/bundb/errors.go new file mode 100644 index 000000000..7602d5e1d --- /dev/null +++ b/internal/db/bundb/errors.go @@ -0,0 +1,43 @@ +package bundb + +import ( + "github.com/jackc/pgconn" + "github.com/superseriousbusiness/gotosocial/internal/db" + "modernc.org/sqlite" + sqlite3 "modernc.org/sqlite/lib" +) + +// processPostgresError processes an error, replacing any postgres specific errors with our own error type +func processPostgresError(err error) db.Error { + // Attempt to cast as postgres + pgErr, ok := err.(*pgconn.PgError) + if !ok { + return err + } + + // Handle supplied error code: + // (https://www.postgresql.org/docs/10/errcodes-appendix.html) + switch pgErr.Code { + case "23505" /* unique_violation */ : + return db.ErrAlreadyExists + default: + return err + } +} + +// processSQLiteError processes an error, replacing any sqlite specific errors with our own error type +func processSQLiteError(err error) db.Error { + // Attempt to cast as sqlite + sqliteErr, ok := err.(*sqlite.Error) + if !ok { + return err + } + + // Handle supplied error code: + switch sqliteErr.Code() { + case sqlite3.SQLITE_CONSTRAINT_UNIQUE: + return db.ErrAlreadyExists + default: + return err + } +} |