···2233import (
44 "context"
55- "sync"
6576 "gorm.io/gorm"
87 "gorm.io/gorm/clause"
···1091110type DB struct {
1211 cli *gorm.DB
1313- mu sync.Mutex
1412}
15131614func NewDB(cli *gorm.DB) *DB {
1715 return &DB{
1816 cli: cli,
1919- mu: sync.Mutex{},
2017 }
2118}
22192320func (db *DB) Create(ctx context.Context, value any, clauses []clause.Expression) *gorm.DB {
2424- db.mu.Lock()
2525- defer db.mu.Unlock()
2621 return db.cli.WithContext(ctx).Clauses(clauses...).Create(value)
2722}
28232924func (db *DB) Save(ctx context.Context, value any, clauses []clause.Expression) *gorm.DB {
3030- db.mu.Lock()
3131- defer db.mu.Unlock()
3225 return db.cli.WithContext(ctx).Clauses(clauses...).Save(value)
3326}
34273528func (db *DB) Exec(ctx context.Context, sql string, clauses []clause.Expression, values ...any) *gorm.DB {
3636- db.mu.Lock()
3737- defer db.mu.Unlock()
3829 return db.cli.WithContext(ctx).Clauses(clauses...).Exec(sql, values...)
3930}
4031···4738}
48394940func (db *DB) Delete(ctx context.Context, value any, clauses []clause.Expression) *gorm.DB {
5050- db.mu.Lock()
5151- defer db.mu.Unlock()
5241 return db.cli.WithContext(ctx).Clauses(clauses...).Delete(value)
5342}
5443···5645 return db.cli.WithContext(ctx).First(dest, conds...)
5746}
58475959-// TODO: this isn't actually good. we can commit even if the db is locked here. this is probably okay for the time being, but need to figure
6060-// out a better solution. right now we only do this whenever we're importing a repo though so i'm mostly not worried, but it's still bad.
6161-// e.g. when we do apply writes we should also be using a transcation but we don't right now
6262-func (db *DB) BeginDangerously(ctx context.Context) *gorm.DB {
4848+func (db *DB) Begin(ctx context.Context) *gorm.DB {
6349 return db.cli.WithContext(ctx).Begin()
6450}
65516666-func (db *DB) Lock() {
6767- db.mu.Lock()
6868-}
6969-7070-func (db *DB) Unlock() {
7171- db.mu.Unlock()
5252+func (db *DB) Client() *gorm.DB {
5353+ return db.cli
7254}