mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-04-23 19:45:18 +08:00
优化KV相关错误提示/可以从路径直接加载数据库
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user