本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
788B

  1. package store
  2. import (
  3. "fmt"
  4. "os"
  5. "path"
  6. "github.com/lunny/nodb/config"
  7. "github.com/lunny/nodb/store/driver"
  8. _ "github.com/lunny/nodb/store/goleveldb"
  9. )
  10. func getStorePath(cfg *config.Config) string {
  11. return path.Join(cfg.DataDir, fmt.Sprintf("%s_data", cfg.DBName))
  12. }
  13. func Open(cfg *config.Config) (*DB, error) {
  14. s, err := driver.GetStore(cfg)
  15. if err != nil {
  16. return nil, err
  17. }
  18. path := getStorePath(cfg)
  19. if err := os.MkdirAll(path, os.ModePerm); err != nil {
  20. return nil, err
  21. }
  22. idb, err := s.Open(path, cfg)
  23. if err != nil {
  24. return nil, err
  25. }
  26. db := &DB{idb}
  27. return db, nil
  28. }
  29. func Repair(cfg *config.Config) error {
  30. s, err := driver.GetStore(cfg)
  31. if err != nil {
  32. return err
  33. }
  34. path := getStorePath(cfg)
  35. return s.Repair(path, cfg)
  36. }
  37. func init() {
  38. }
上海开阖软件有限公司 沪ICP备12045867号-1