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/util.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/util.go')
-rw-r--r-- | internal/db/bundb/util.go | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/internal/db/bundb/util.go b/internal/db/bundb/util.go index faa80221f..9e1afb87e 100644 --- a/internal/db/bundb/util.go +++ b/internal/db/bundb/util.go @@ -19,64 +19,9 @@ package bundb import ( - "context" - "strings" - - "database/sql" - - "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/uptrace/bun" ) -// processErrorResponse parses the given error and returns an appropriate DBError. -func processErrorResponse(err error) db.Error { - switch err { - case nil: - return nil - case sql.ErrNoRows: - return db.ErrNoEntries - default: - if strings.Contains(err.Error(), "duplicate key value violates unique constraint") { - return db.ErrAlreadyExists - } - return err - } -} - -func exists(ctx context.Context, q *bun.SelectQuery) (bool, db.Error) { - count, err := q.Count(ctx) - - exists := count != 0 - - err = processErrorResponse(err) - - if err != nil { - if err == db.ErrNoEntries { - return false, nil - } - return false, err - } - - return exists, nil -} - -func notExists(ctx context.Context, q *bun.SelectQuery) (bool, db.Error) { - count, err := q.Count(ctx) - - notExists := count == 0 - - err = processErrorResponse(err) - - if err != nil { - if err == db.ErrNoEntries { - return true, nil - } - return false, err - } - - return notExists, nil -} - // whereEmptyOrNull is a convenience function to return a bun WhereGroup that specifies // that the given column should be EITHER an empty string OR null. // |