sourcegraph/internal/codeintel/shared/db.go
Noah S-C 9333f8f283
codeintel: consolidate enterprise & oss codeintel packages (#54431)
Movin enterprise codeintel stuff (and ~two others that had to be dragged
along) out of `enterprise/internal` and into `internal` as part of the
shift towards enterprise-only

## Test plan

Successfully built frontend with bazel, CI will check the rest
😎 no logic changed, just shufflin things around
2023-07-05 14:58:41 +01:00

53 lines
1.4 KiB
Go

package stores
import (
"context"
"database/sql"
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
"github.com/sourcegraph/sourcegraph/internal/database/dbutil"
)
type CodeIntelDB interface {
dbutil.DB
basestore.ShareableStore
Transact(context.Context) (CodeIntelDB, error)
Done(error) error
}
func NewCodeIntelDB(logger log.Logger, inner *sql.DB) CodeIntelDB {
return &codeIntelDB{basestore.NewWithHandle(basestore.NewHandleWithDB(logger, inner, sql.TxOptions{}))}
}
func NewCodeIntelDBWith(other basestore.ShareableStore) CodeIntelDB {
return &codeIntelDB{basestore.NewWithHandle(other.Handle())}
}
type codeIntelDB struct {
*basestore.Store
}
func (d *codeIntelDB) Transact(ctx context.Context) (CodeIntelDB, error) {
tx, err := d.Store.Transact(ctx)
return &codeIntelDB{tx}, err
}
func (db *codeIntelDB) Done(err error) error {
return db.Store.Done(err)
}
func (db *codeIntelDB) QueryContext(ctx context.Context, q string, args ...any) (*sql.Rows, error) {
return db.Handle().QueryContext(ctx, q, args...)
}
func (db *codeIntelDB) ExecContext(ctx context.Context, q string, args ...any) (sql.Result, error) {
return db.Handle().ExecContext(ctx, q, args...)
}
func (db *codeIntelDB) QueryRowContext(ctx context.Context, q string, args ...any) *sql.Row {
return db.Handle().QueryRowContext(ctx, q, args...)
}