37 lines
862 B
Go
37 lines
862 B
Go
package driver
|
|
|
|
import (
|
|
"context"
|
|
"local/dndex/config"
|
|
"local/storage"
|
|
"strings"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
type Driver interface {
|
|
Count(context.Context, string, interface{}) (int, error)
|
|
Find(context.Context, string, interface{}) (chan bson.Raw, error)
|
|
Update(context.Context, string, interface{}, interface{}) error
|
|
Insert(context.Context, string, interface{}) error
|
|
Delete(context.Context, string, interface{}) error
|
|
}
|
|
|
|
func New(path ...string) Driver {
|
|
if len(path) == 0 {
|
|
path = config.New().Driver
|
|
}
|
|
if t := storage.TypeFromString(path[0]); t >= 0 {
|
|
return NewStorage(path...)
|
|
}
|
|
switch strings.ToLower(config.New().Driver[0]) {
|
|
case "map":
|
|
return NewMap()
|
|
case "mongo":
|
|
return NewMongo(path[0])
|
|
case "boltdb":
|
|
return NewBoltDB(path[0])
|
|
}
|
|
panic("unknown driver type " + strings.ToLower(config.New().Driver[0]))
|
|
}
|