优化KV相关错误提示/可以从路径直接加载数据库

This commit is contained in:
GoEdgeLab
2024-04-23 11:56:00 +08:00
parent 1f9f3d64e5
commit e18bd2a6e1
3 changed files with 57 additions and 8 deletions

View File

@@ -15,12 +15,22 @@ type Tx[T any] struct {
batch *pebble.Batch
}
func NewTx[T any](table *Table[T], readOnly bool) *Tx[T] {
func NewTx[T any](table *Table[T], readOnly bool) (*Tx[T], error) {
if table.db == nil {
return nil, errors.New("the table has not been added to a db")
}
if table.db.store == nil {
return nil, errors.New("the db has not been added to a store")
}
if table.db.store.rawDB == nil {
return nil, errors.New("the store has not been opened")
}
return &Tx[T]{
table: table,
readOnly: readOnly,
batch: table.db.store.rawDB.NewIndexedBatch(),
}
}, nil
}
func (this *Tx[T]) Set(key string, value T) error {