diff --git a/capten/common-pkg/capten-store/app_config_store.go b/capten/common-pkg/capten-store/app_config_store.go index f3684d1d..59a5cf4b 100644 --- a/capten/common-pkg/capten-store/app_config_store.go +++ b/capten/common-pkg/capten-store/app_config_store.go @@ -17,7 +17,7 @@ func (a *Store) UpsertAppConfig(appData *agentpb.SyncAppData) error { appConfig := &ClusterAppConfig{} recordFound := true - err := a.dbClient.Find(appConfig, ClusterAppConfig{ReleaseName: appData.Config.ReleaseName}) + err := a.dbClient.FindFirst(appConfig, ClusterAppConfig{ReleaseName: appData.Config.ReleaseName}) if err != nil { if gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { return prepareError(err, appData.Config.ReleaseName, "Fetch") @@ -59,9 +59,8 @@ func (a *Store) UpsertAppConfig(appData *agentpb.SyncAppData) error { func (a *Store) GetAppConfig(appReleaseName string) (*agentpb.SyncAppData, error) { appConfig := &ClusterAppConfig{} - err := a.dbClient.Find(appConfig, ClusterAppConfig{ReleaseName: appReleaseName}) + err := a.dbClient.FindFirst(appConfig, ClusterAppConfig{ReleaseName: appReleaseName}) if err != nil { - err = prepareError(err, appReleaseName, "Fetch") return nil, err } @@ -109,8 +108,8 @@ func (a *Store) GetAppConfig(appReleaseName string) (*agentpb.SyncAppData, error func (a *Store) GetAllApps() ([]*agentpb.SyncAppData, error) { var appConfigs []ClusterAppConfig err := a.dbClient.Find(&appConfigs, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { - return nil, fmt.Errorf("Unable to fetch apps: %v", err.Error()) + if err != nil { + return nil, fmt.Errorf("failed to fetch apps: %v", err.Error()) } var appData []*agentpb.SyncAppData diff --git a/capten/common-pkg/capten-store/cloud_provider.go b/capten/common-pkg/capten-store/cloud_provider.go index ffef42e3..97ec8577 100644 --- a/capten/common-pkg/capten-store/cloud_provider.go +++ b/capten/common-pkg/capten-store/cloud_provider.go @@ -5,10 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/kube-tarian/kad/capten/common-pkg/gerrors" "github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb" - postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" - "gorm.io/gorm" ) func (a *Store) UpsertCloudProvider(config *captenpluginspb.CloudProvider) error { @@ -33,7 +30,7 @@ func (a *Store) UpsertCloudProvider(config *captenpluginspb.CloudProvider) error func (a *Store) GetCloudProviderForID(id string) (*captenpluginspb.CloudProvider, error) { provider := CloudProvider{} - err := a.dbClient.Find(&provider, CloudProvider{ID: uuid.MustParse(id)}) + err := a.dbClient.FindFirst(&provider, CloudProvider{ID: uuid.MustParse(id)}) if err != nil { return nil, err } @@ -51,7 +48,7 @@ func (a *Store) GetCloudProviderForID(id string) (*captenpluginspb.CloudProvider func (a *Store) GetCloudProviders() ([]*captenpluginspb.CloudProvider, error) { providers := []CloudProvider{} err := a.dbClient.Find(&providers, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch providers: %v", err.Error()) } @@ -70,11 +67,8 @@ func (a *Store) GetCloudProviders() ([]*captenpluginspb.CloudProvider, error) { func (a *Store) GetCloudProvidersByLabelsAndCloudType(searchLabels []string, cloudType string) ([]*captenpluginspb.CloudProvider, error) { providers := []CloudProvider{} err := a.dbClient.Session().Where("cloud_type = ?", cloudType).Where("labels @> ?", fmt.Sprintf("{%s}", searchLabels[0])).Find(&providers).Error - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { - if gorm.ErrRecordNotFound != err { - return nil, fmt.Errorf("failed to fetch providers: %v", err.Error()) - } - err = nil + if err != nil { + return nil, fmt.Errorf("failed to fetch providers: %v", err.Error()) } cloudProviders := make([]*captenpluginspb.CloudProvider, 0) @@ -92,7 +86,7 @@ func (a *Store) GetCloudProvidersByLabelsAndCloudType(searchLabels []string, clo func (a *Store) GetCloudProvidersByLabels(searchLabels []string) ([]*captenpluginspb.CloudProvider, error) { providers := []CloudProvider{} err := a.dbClient.Find(&providers, "labels @> ?", fmt.Sprintf("{%s}", searchLabels[0])) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch providers: %v", err.Error()) } diff --git a/capten/common-pkg/capten-store/cluster_plugin_config_store.go b/capten/common-pkg/capten-store/cluster_plugin_config_store.go index 720e3a3e..a1591d96 100644 --- a/capten/common-pkg/capten-store/cluster_plugin_config_store.go +++ b/capten/common-pkg/capten-store/cluster_plugin_config_store.go @@ -8,8 +8,6 @@ import ( "github.com/kube-tarian/kad/capten/common-pkg/gerrors" "github.com/kube-tarian/kad/capten/common-pkg/pb/clusterpluginspb" postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" - "github.com/pkg/errors" - "gorm.io/gorm" ) func (a *Store) UpsertClusterPluginConfig(pluginConfig *clusterpluginspb.Plugin) error { @@ -67,11 +65,8 @@ func (a *Store) DeleteClusterPluginConfig(pluginName string) error { func (a *Store) GetClusterPluginConfig(pluginName string) (*clusterpluginspb.Plugin, error) { var pluginConfig ClusterPluginConfig - err := a.dbClient.Find(&pluginConfig, "plugin_name = ?", pluginName) + err := a.dbClient.FindFirst(&pluginConfig, ClusterPluginConfig{PluginName: pluginName}) if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return nil, nil - } return nil, err } @@ -103,7 +98,7 @@ func (a *Store) GetClusterPluginConfig(pluginName string) (*clusterpluginspb.Plu func (a *Store) GetAllClusterPluginConfigs() ([]*clusterpluginspb.Plugin, error) { var plugins []ClusterPluginConfig err := a.dbClient.Find(&plugins, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch plugins: %v", err.Error()) } diff --git a/capten/common-pkg/capten-store/container_registry.go b/capten/common-pkg/capten-store/container_registry.go index 3bcc7ad0..954eebce 100644 --- a/capten/common-pkg/capten-store/container_registry.go +++ b/capten/common-pkg/capten-store/container_registry.go @@ -5,9 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/kube-tarian/kad/capten/common-pkg/gerrors" "github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb" - postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" ) func (a *Store) UpsertContainerRegistry(config *captenpluginspb.ContainerRegistry) error { @@ -32,7 +30,7 @@ func (a *Store) UpsertContainerRegistry(config *captenpluginspb.ContainerRegistr func (a *Store) GetContainerRegistryForID(id string) (*captenpluginspb.ContainerRegistry, error) { registry := ContainerRegistry{} - err := a.dbClient.Find(®istry, ContainerRegistry{ID: uuid.MustParse(id)}) + err := a.dbClient.FindFirst(®istry, ContainerRegistry{ID: uuid.MustParse(id)}) if err != nil { return nil, err } @@ -50,7 +48,7 @@ func (a *Store) GetContainerRegistryForID(id string) (*captenpluginspb.Container func (a *Store) GetContainerRegistries() ([]*captenpluginspb.ContainerRegistry, error) { registries := []ContainerRegistry{} err := a.dbClient.Find(®istries, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch registries: %v", err.Error()) } @@ -70,7 +68,7 @@ func (a *Store) GetContainerRegistries() ([]*captenpluginspb.ContainerRegistry, func (a *Store) GetContainerRegistriesByLabels(searchLabels []string) ([]*captenpluginspb.ContainerRegistry, error) { registries := []ContainerRegistry{} err := a.dbClient.Find(®istries, "labels @> ?", fmt.Sprintf("{%s}", searchLabels[0])) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch registries: %v", err.Error()) } diff --git a/capten/common-pkg/capten-store/crossplane_project.go b/capten/common-pkg/capten-store/crossplane_project.go index 49aaa840..06484c29 100644 --- a/capten/common-pkg/capten-store/crossplane_project.go +++ b/capten/common-pkg/capten-store/crossplane_project.go @@ -8,8 +8,6 @@ import ( "github.com/kube-tarian/kad/capten/common-pkg/gerrors" postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" "github.com/kube-tarian/kad/capten/model" - "github.com/pkg/errors" - "gorm.io/gorm" ) func (a *Store) UpsertCrossplaneProject(crossplaneProject *model.CrossplaneProject) error { @@ -47,11 +45,9 @@ func (a *Store) DeleteCrossplaneProject(id string) error { func (a *Store) GetCrossplaneProjectForID(id string) (*model.CrossplaneProject, error) { project := CrossplaneProject{} - err := a.dbClient.Find(&project, CrossplaneProject{ID: 1}) + err := a.dbClient.FindFirst(&project, CrossplaneProject{ID: 1}) if err != nil { return nil, err - } else if project.ID == 0 { - return nil, gorm.ErrRecordNotFound } crossplaneProject := &model.CrossplaneProject{ @@ -70,7 +66,7 @@ func (a *Store) GetCrossplaneProject() (*model.CrossplaneProject, error) { func (a *Store) updateCrossplaneProject() (*model.CrossplaneProject, error) { allCrossplaneGitProjects, err := a.GetGitProjectsByLabels([]string{"crossplane"}) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch projects: %v", err.Error()) } @@ -85,7 +81,7 @@ func (a *Store) updateCrossplaneProject() (*model.CrossplaneProject, error) { crossplaneProject, err := a.GetCrossplaneProjectForID("0") if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { + if gerrors.GetErrorType(err) == postgresdb.ObjectNotExist { project := CrossplaneProject{ ID: 1, GitProjectID: gitProjectUUID, diff --git a/capten/common-pkg/capten-store/crossplane_provider.go b/capten/common-pkg/capten-store/crossplane_provider.go index 88fa3b90..bdd690e6 100644 --- a/capten/common-pkg/capten-store/crossplane_provider.go +++ b/capten/common-pkg/capten-store/crossplane_provider.go @@ -40,7 +40,7 @@ func (a *Store) DeleteCrossplaneProviderById(id string) error { func (a *Store) GetCrossplaneProviders() ([]*captenpluginspb.CrossplaneProvider, error) { providers := []CrossplaneProvider{} err := a.dbClient.Find(&providers, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch providers: %v", err.Error()) } @@ -68,7 +68,7 @@ func (a *Store) UpdateCrossplaneProvider(provider *model.CrossplaneProvider) err func (a *Store) GetCrossplanProviderByCloudType(cloudType string) (*captenpluginspb.CrossplaneProvider, error) { providers := []CrossplaneProvider{} err := a.dbClient.Find(&providers, "cloud_type = ?", cloudType) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch providers: %v", err.Error()) } @@ -88,7 +88,7 @@ func (a *Store) GetCrossplanProviderByCloudType(cloudType string) (*captenplugin func (a *Store) GetCrossplanProviderById(id string) (*captenpluginspb.CrossplaneProvider, error) { provider := CrossplaneProvider{} - err := a.dbClient.Find(&provider, CrossplaneProvider{ID: uuid.MustParse(id)}) + err := a.dbClient.FindFirst(&provider, CrossplaneProvider{ID: uuid.MustParse(id)}) if err != nil { return nil, err } diff --git a/capten/common-pkg/capten-store/git_projects.go b/capten/common-pkg/capten-store/git_projects.go index 92a1e015..3caa8070 100644 --- a/capten/common-pkg/capten-store/git_projects.go +++ b/capten/common-pkg/capten-store/git_projects.go @@ -5,9 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/kube-tarian/kad/capten/common-pkg/gerrors" "github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb" - postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" ) func (a *Store) UpsertGitProject(config *captenpluginspb.GitProject) error { @@ -38,7 +36,7 @@ func (a *Store) DeleteGitProjectById(id string) error { func (a *Store) GetGitProjectForID(id string) (*captenpluginspb.GitProject, error) { project := GitProject{} - err := a.dbClient.Find(&project, GitProject{ID: uuid.MustParse(id)}) + err := a.dbClient.FindFirst(&project, GitProject{ID: uuid.MustParse(id)}) if err != nil { return nil, err } @@ -55,7 +53,7 @@ func (a *Store) GetGitProjectForID(id string) (*captenpluginspb.GitProject, erro func (a *Store) GetGitProjects() ([]*captenpluginspb.GitProject, error) { projects := []GitProject{} err := a.dbClient.Find(&projects, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch projects: %v", err.Error()) } @@ -74,7 +72,7 @@ func (a *Store) GetGitProjects() ([]*captenpluginspb.GitProject, error) { func (a *Store) GetGitProjectsByLabels(searchLabels []string) ([]*captenpluginspb.GitProject, error) { projects := []GitProject{} err := a.dbClient.Find(&projects, "labels @> ?", fmt.Sprintf("{%s}", searchLabels[0])) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch projects: %v", err.Error()) } diff --git a/capten/common-pkg/capten-store/integration_store_test.go b/capten/common-pkg/capten-store/integration_store_test.go index b649e6a7..9fa35ff3 100644 --- a/capten/common-pkg/capten-store/integration_store_test.go +++ b/capten/common-pkg/capten-store/integration_store_test.go @@ -815,12 +815,8 @@ func TestPluginStoreConfig(t *testing.T) { return } - config, err = store.GetPluginStoreConfig(pluginstorepb.StoreType_CENTRAL_STORE) - if !assert.Nil(t, err) { - t.Logf("get plugin store config error, %v", err) - return - } - assert.Equal(t, config.GitProjectURL, "") + _, err = store.GetPluginStoreConfig(pluginstorepb.StoreType_CENTRAL_STORE) + assert.Error(t, err) } func TestPluginStoreData(t *testing.T) { diff --git a/capten/common-pkg/capten-store/managed_cluster.go b/capten/common-pkg/capten-store/managed_cluster.go index 47a395a1..47b158e4 100644 --- a/capten/common-pkg/capten-store/managed_cluster.go +++ b/capten/common-pkg/capten-store/managed_cluster.go @@ -5,10 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/kube-tarian/kad/capten/common-pkg/gerrors" "github.com/kube-tarian/kad/capten/common-pkg/pb/captenpluginspb" - postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" - "gorm.io/gorm" ) func (a *Store) UpsertManagedCluster(managedCluster *captenpluginspb.ManagedCluster) error { @@ -42,11 +39,9 @@ func (a *Store) DeleteManagedClusterById(id string) error { func (a *Store) GetManagedClusterForID(id string) (*captenpluginspb.ManagedCluster, error) { cluster := ManagedCluster{} - err := a.dbClient.Find(&cluster, ManagedCluster{ID: uuid.MustParse(id)}) + err := a.dbClient.FindFirst(&cluster, ManagedCluster{ID: uuid.MustParse(id)}) if err != nil { return nil, err - } else if cluster.ID == uuid.Nil { - return nil, gorm.ErrRecordNotFound } result := &captenpluginspb.ManagedCluster{ @@ -63,7 +58,7 @@ func (a *Store) GetManagedClusterForID(id string) (*captenpluginspb.ManagedClust func (a *Store) GetManagedClusters() ([]*captenpluginspb.ManagedCluster, error) { clusters := []ManagedCluster{} err := a.dbClient.Find(&clusters, nil) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch clusters: %v", err.Error()) } diff --git a/capten/common-pkg/capten-store/plugin_store_config_store.go b/capten/common-pkg/capten-store/plugin_store_config_store.go index 5aa715db..95b656e0 100644 --- a/capten/common-pkg/capten-store/plugin_store_config_store.go +++ b/capten/common-pkg/capten-store/plugin_store_config_store.go @@ -13,15 +13,13 @@ import ( func (a *Store) UpsertPluginStoreConfig(config *pluginstorepb.PluginStoreConfig) error { pluginStoreConfig := &PluginStoreConfig{} recordFound := true - err := a.dbClient.Find(pluginStoreConfig, PluginStoreConfig{StoreType: int(config.StoreType)}) + err := a.dbClient.FindFirst(pluginStoreConfig, PluginStoreConfig{StoreType: int(config.StoreType)}) if err != nil { if gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { return prepareError(err, fmt.Sprintf("%d", config.StoreType), "Fetch") } err = nil recordFound = false - } else if pluginStoreConfig.StoreType == 0 { - recordFound = false } pluginStoreConfig.StoreType = int(config.StoreType) @@ -39,9 +37,9 @@ func (a *Store) UpsertPluginStoreConfig(config *pluginstorepb.PluginStoreConfig) func (a *Store) GetPluginStoreConfig(storeType pluginstorepb.StoreType) (*pluginstorepb.PluginStoreConfig, error) { pluginStoreConfig := &PluginStoreConfig{} - err := a.dbClient.Find(pluginStoreConfig, PluginStoreConfig{StoreType: int(storeType)}) + err := a.dbClient.FindFirst(pluginStoreConfig, PluginStoreConfig{StoreType: int(storeType)}) if err != nil { - return nil, prepareError(err, fmt.Sprintf("%d", storeType), "Fetch") + return nil, err } return &pluginstorepb.PluginStoreConfig{ diff --git a/capten/common-pkg/capten-store/plugin_store_date_store.go b/capten/common-pkg/capten-store/plugin_store_date_store.go index 293ff323..0c75cda9 100644 --- a/capten/common-pkg/capten-store/plugin_store_date_store.go +++ b/capten/common-pkg/capten-store/plugin_store_date_store.go @@ -8,13 +8,12 @@ import ( "github.com/kube-tarian/kad/capten/common-pkg/gerrors" "github.com/kube-tarian/kad/capten/common-pkg/pb/pluginstorepb" postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" - "gorm.io/gorm" ) func (a *Store) UpsertPluginStoreData(gitProjectID string, pluginData *pluginstorepb.PluginData) error { pluginStoreData := &PluginStoreData{} recordFound := true - err := a.dbClient.Find(pluginStoreData, PluginStoreData{ + err := a.dbClient.FindFirst(pluginStoreData, PluginStoreData{ StoreType: int(pluginData.StoreType), GitProjectID: uuid.MustParse(gitProjectID), PluginName: pluginData.PluginName}) @@ -25,8 +24,6 @@ func (a *Store) UpsertPluginStoreData(gitProjectID string, pluginData *pluginsto } err = nil recordFound = false - } else if pluginStoreData.StoreType == 0 { - recordFound = false } pluginStoreData.StoreType = int(pluginData.StoreType) @@ -51,15 +48,13 @@ func (a *Store) UpsertPluginStoreData(gitProjectID string, pluginData *pluginsto func (a *Store) GetPluginStoreData(storeType pluginstorepb.StoreType, gitProjectId, pluginName string) (*pluginstorepb.PluginData, error) { pluginStoreData := &PluginStoreData{} - err := a.dbClient.Find(pluginStoreData, PluginStoreData{ + err := a.dbClient.FindFirst(pluginStoreData, PluginStoreData{ StoreType: int(storeType), GitProjectID: uuid.MustParse(gitProjectId), PluginName: pluginName, }) if err != nil { - return nil, prepareError(err, fmt.Sprintf("%s/%s/%s", gitProjectId, gitProjectId, pluginName), "Fetch") - } else if pluginStoreData.StoreType == 0 { - return nil, gorm.ErrRecordNotFound + return nil, err } pluginData := &pluginstorepb.PluginData{ diff --git a/capten/common-pkg/capten-store/tekton_projects.go b/capten/common-pkg/capten-store/tekton_projects.go index 14a2ed26..2fcbfec3 100644 --- a/capten/common-pkg/capten-store/tekton_projects.go +++ b/capten/common-pkg/capten-store/tekton_projects.go @@ -8,8 +8,6 @@ import ( "github.com/kube-tarian/kad/capten/common-pkg/gerrors" postgresdb "github.com/kube-tarian/kad/capten/common-pkg/postgres" "github.com/kube-tarian/kad/capten/model" - "github.com/pkg/errors" - "gorm.io/gorm" ) func (a *Store) UpsertTektonProject(tektonProject *model.TektonProject) error { @@ -46,11 +44,9 @@ func (a *Store) DeleteTektonProject(id string) error { func (a *Store) GetTektonProjectForID(id string) (*model.TektonProject, error) { project := TektonProject{} - err := a.dbClient.Find(&project, TektonProject{ID: 1}) + err := a.dbClient.FindFirst(&project, TektonProject{ID: 1}) if err != nil { return nil, err - } else if project.ID == 0 { - return nil, gorm.ErrRecordNotFound } tektonProject := &model.TektonProject{ @@ -69,7 +65,7 @@ func (a *Store) GetTektonProject() (*model.TektonProject, error) { func (a *Store) updateTektonProject() (*model.TektonProject, error) { allTektonGitProjects, err := a.GetGitProjectsByLabels([]string{"tekton"}) - if err != nil && gerrors.GetErrorType(err) != postgresdb.ObjectNotExist { + if err != nil { return nil, fmt.Errorf("failed to fetch projects: %v", err.Error()) } @@ -84,7 +80,7 @@ func (a *Store) updateTektonProject() (*model.TektonProject, error) { tektonProject, err := a.GetTektonProjectForID("1") if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { + if gerrors.GetErrorType(err) == postgresdb.ObjectNotExist { project := TektonProject{ ID: 1, GitProjectID: gitProjectUUID, diff --git a/capten/common-pkg/postgres/db_client.go b/capten/common-pkg/postgres/db_client.go index fa81c0c1..0380e18a 100644 --- a/capten/common-pkg/postgres/db_client.go +++ b/capten/common-pkg/postgres/db_client.go @@ -134,6 +134,23 @@ func (db *DBClient) Delete(value interface{}, where interface{}) (err error) { return } +func (db *DBClient) FindFirst(value interface{}, where interface{}, args ...interface{}) (err error) { + err = db.session.Where(where, args).First(value).Error + if err == nil { + return + } + + if gorm.ErrRecordNotFound == err { + err = gerrors.New(ObjectNotExist, "") + } + + if err != nil { + err = db.checkError(err) + return + } + return +} + // Find find records that match given conditions func (db *DBClient) Find(value interface{}, where interface{}, args ...interface{}) (err error) { if where != nil {