Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions cdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,31 @@ func New(dbPool *sql.DB) *DB {
return &DB{DB: dbPool, DBLck: InitDbLocker(dbPool), dbPool: dbPool}
}

func (odb *DB) CreateTx(ctx context.Context, opts *sql.TxOptions) error {
if odb.hasTx {
func (oDb *DB) CreateTx(ctx context.Context, opts *sql.TxOptions) error {
if oDb.hasTx {
return fmt.Errorf("already in a transaction")
}
if tx, err := odb.dbPool.BeginTx(ctx, opts); err != nil {
if tx, err := oDb.dbPool.BeginTx(ctx, opts); err != nil {
return err
} else {
odb.DB = tx
odb.hasTx = true
oDb.DB = tx
oDb.hasTx = true
return nil
}
}

func (odb *DB) CreateSession(ev eventPublisher) {
odb.Session = &Session{
db: odb.DB,
func (oDb *DB) CreateSession(ev eventPublisher) {
oDb.Session = &Session{
db: oDb.DB,
ev: ev,
tables: make(map[string]struct{}),
}
}

func (oDb *DB) Commit() error {
if !oDb.hasTx {
return nil
}
tx, ok := oDb.DB.(DBTxer)
if !ok {
return nil
Expand All @@ -94,6 +97,10 @@ func (oDb *DB) Commit() error {
}

func (oDb *DB) Rollback() error {
if !oDb.hasTx {
return nil
}
defer func() { oDb.hasTx = false }()
tx, ok := oDb.DB.(DBTxer)
if !ok {
return nil
Expand Down
6 changes: 3 additions & 3 deletions cdb/db_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,16 @@ func (oDb *DB) AppIDFromObjectID(ctx context.Context, objectID string) (int64, b
// q &= db.apps.app == db.nodes.app
// return db(q).select(db.apps.ALL).first()
// return row
func (odb *DB) AppIDFromObjectOrNodeIDs(ctx context.Context, nodeID, objectID string) (int64, bool, error) {
func (oDb *DB) AppIDFromObjectOrNodeIDs(ctx context.Context, nodeID, objectID string) (int64, bool, error) {
if objectID != "" {
if found, ok, err := odb.AppIDFromObjectID(ctx, objectID); err == nil {
if found, ok, err := oDb.AppIDFromObjectID(ctx, objectID); err == nil {
// abort on error
return found, ok, err
} else if ok {
return found, ok, err
}
}
return odb.AppIDFromNodeID(ctx, nodeID)
return oDb.AppIDFromNodeID(ctx, nodeID)
}

func (oDb *DB) AppsWithoutResponsible(ctx context.Context) (apps []string, err error) {
Expand Down
Loading