mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 10:12:26 -05:00
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>
This commit is contained in:
parent
53507ac2a3
commit
ed46224573
730 changed files with 2239881 additions and 3669 deletions
43
internal/db/bundb/errors.go
Normal file
43
internal/db/bundb/errors.go
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue