dboperations.go 930 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dboperations
  2. import (
  3. "git.sxidc.com/go-tools/dboperations/operations"
  4. "strings"
  5. )
  6. var dbOperationsInstance operations.DBOperations
  7. func GetInstance() operations.DBOperations {
  8. return dbOperationsInstance
  9. }
  10. func InitInstance(dbConfig *operations.DBConfig) error {
  11. if dbOperationsInstance != nil {
  12. return nil
  13. }
  14. dbOperations, err := operations.NewOperations(dbConfig)
  15. if err != nil {
  16. return err
  17. }
  18. dbOperationsInstance = dbOperations
  19. return nil
  20. }
  21. func DestroyInstance() error {
  22. if dbOperationsInstance == nil {
  23. return nil
  24. }
  25. err := operations.DestroyOperation(dbOperationsInstance.(*operations.Operations))
  26. if err != nil {
  27. return err
  28. }
  29. dbOperationsInstance = nil
  30. return nil
  31. }
  32. func IsErrorDBRecordHasExist(err error) bool {
  33. return strings.Contains(err.Error(), "记录已存在")
  34. }
  35. func IsErrorDBRecordNotExist(err error) bool {
  36. return strings.Contains(err.Error(), "记录不存在")
  37. }