diff options
author | 2021-09-09 16:15:25 +0200 | |
---|---|---|
committer | 2021-09-09 16:15:25 +0200 | |
commit | 555ea8edfb2c30d149b3ca6cb0fbe53f2798c7bc (patch) | |
tree | 24567c4c365a007fcd2d6603e696b363129abb77 /internal/db/bundb/basic.go | |
parent | Merge pull request #198 from NyaaaWhatsUpDoc/update/sqlite-library (diff) | |
download | gotosocial-555ea8edfb2c30d149b3ca6cb0fbe53f2798c7bc.tar.xz |
Import export (#194)
* start with export/import code
* messing about with decoding/encoding
* some more fiddling
* stuff is WORKING
* working pretty alright!
* go fmt
* fix up tests, add docs
* start backup/restore doc
* tweaks
* credits
* update advancedVisibility settings
* update bun library -> v1.0.4
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* update oauth library -> v4.3.1-SSB
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* handle oauth token scope, fix user.SigninCount + token.UserID
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* update oauth library --> v4.3.2-SSB
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* update sqlite library -> v1.13.0
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* review changes
* start with export/import code
* messing about with decoding/encoding
* some more fiddling
* stuff is WORKING
* working pretty alright!
* go fmt
* fix up tests, add docs
* start backup/restore doc
* tweaks
* credits
* update advancedVisibility settings
* review changes
Co-authored-by: kim (grufwub) <grufwub@gmail.com>
Co-authored-by: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>
Diffstat (limited to 'internal/db/bundb/basic.go')
-rw-r--r-- | internal/db/bundb/basic.go | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/internal/db/bundb/basic.go b/internal/db/bundb/basic.go index a3a8d0ae9..d4de5bb0b 100644 --- a/internal/db/bundb/basic.go +++ b/internal/db/bundb/basic.go @@ -24,6 +24,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) @@ -53,17 +54,8 @@ func (b *basicDB) GetWhere(ctx context.Context, where []db.Where, i interface{}) } q := b.conn.NewSelect().Model(i) - for _, w := range where { - if w.Value == nil { - q = q.Where("? IS NULL", bun.Ident(w.Key)) - } else { - if w.CaseInsensitive { - q = q.Where("LOWER(?) = LOWER(?)", bun.Safe(w.Key), w.Value) - } else { - q = q.Where("? = ?", bun.Safe(w.Key), w.Value) - } - } - } + + selectWhere(q, where) err := q.Scan(ctx) return b.conn.ProcessError(err) @@ -97,9 +89,7 @@ func (b *basicDB) DeleteWhere(ctx context.Context, where []db.Where, i interface NewDelete(). Model(i) - for _, w := range where { - q = q.Where("? = ?", bun.Safe(w.Key), w.Value) - } + deleteWhere(q, where) _, err := q.Exec(ctx) return b.conn.ProcessError(err) @@ -128,17 +118,7 @@ func (b *basicDB) UpdateOneByID(ctx context.Context, id string, key string, valu func (b *basicDB) UpdateWhere(ctx context.Context, where []db.Where, key string, value interface{}, i interface{}) db.Error { q := b.conn.NewUpdate().Model(i) - for _, w := range where { - if w.Value == nil { - q = q.Where("? IS NULL", bun.Ident(w.Key)) - } else { - if w.CaseInsensitive { - q = q.Where("LOWER(?) = LOWER(?)", bun.Safe(w.Key), w.Value) - } else { - q = q.Where("? = ?", bun.Safe(w.Key), w.Value) - } - } - } + updateWhere(q, where) q = q.Set("? = ?", bun.Safe(key), value) @@ -151,6 +131,40 @@ func (b *basicDB) CreateTable(ctx context.Context, i interface{}) db.Error { return err } +func (b *basicDB) CreateAllTables(ctx context.Context) db.Error { + models := []interface{}{ + >smodel.Account{}, + >smodel.Application{}, + >smodel.Block{}, + >smodel.DomainBlock{}, + >smodel.EmailDomainBlock{}, + >smodel.Follow{}, + >smodel.FollowRequest{}, + >smodel.MediaAttachment{}, + >smodel.Mention{}, + >smodel.Status{}, + >smodel.StatusToEmoji{}, + >smodel.StatusToTag{}, + >smodel.StatusFave{}, + >smodel.StatusBookmark{}, + >smodel.StatusMute{}, + >smodel.Tag{}, + >smodel.User{}, + >smodel.Emoji{}, + >smodel.Instance{}, + >smodel.Notification{}, + >smodel.RouterSession{}, + >smodel.Token{}, + >smodel.Client{}, + } + for _, i := range models { + if err := b.CreateTable(ctx, i); err != nil { + return err + } + } + return nil +} + func (b *basicDB) DropTable(ctx context.Context, i interface{}) db.Error { _, err := b.conn.NewDropTable().Model(i).IfExists().Exec(ctx) return b.conn.ProcessError(err) |