gomog/internal/database/adapter.go

38 lines
1.0 KiB
Go

package database
import (
"context"
"git.kingecg.top/kingecg/gomog/pkg/types"
)
// DatabaseAdapter 数据库适配器接口
type DatabaseAdapter interface {
// 连接管理
Connect(ctx context.Context, dsn string) error
Close() error
Ping(ctx context.Context) error
// 表/集合管理
CreateCollection(ctx context.Context, name string) error
DropCollection(ctx context.Context, name string) error
CollectionExists(ctx context.Context, name string) (bool, error)
// 数据操作(批量)
InsertMany(ctx context.Context, collection string, docs []types.Document) error
UpdateMany(ctx context.Context, collection string, ids []string, doc types.Update) error
DeleteMany(ctx context.Context, collection string, ids []string) error
// 全量查询(用于加载到内存)
FindAll(ctx context.Context, collection string) ([]types.Document, error)
// 事务支持
BeginTx(ctx context.Context) (Transaction, error)
}
// Transaction 事务接口
type Transaction interface {
Commit() error
Rollback() error
}