當前位置: 首頁>>代碼示例>>Golang>>正文


Golang internalerrors.NewViolatedConstraint函數代碼示例

本文整理匯總了Golang中github.com/solher/zest/internalerrors.NewViolatedConstraint函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewViolatedConstraint函數的具體用法?Golang NewViolatedConstraint怎麽用?Golang NewViolatedConstraint使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewViolatedConstraint函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UpdateByID

func (r *RoleMappingRepo) UpdateByID(id int, roleMapping *domain.RoleMapping,
	context usecases.QueryContext) (*domain.RoleMapping, error) {

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	dbName := utils.ToDBName("roleMappings")
	oldRoleMapping := &domain.RoleMapping{}

	err = query.Where(dbName+".id = ?", id).First(oldRoleMapping).Error
	if err != nil {
		if strings.Contains(err.Error(), "record not found") {
			return nil, internalerrors.NotFound
		}

		return nil, internalerrors.DatabaseError
	}

	roleMapping.ID = oldRoleMapping.ID
	roleMapping.CreatedAt = oldRoleMapping.CreatedAt

	err = r.store.GetDB().Save(&roleMapping).Error
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return roleMapping, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:34,代碼來源:role_mapping_repository.go

示例2: UpdateByID

func (r *AccountRepo) UpdateByID(id int, account *domain.Account,
	context usecases.QueryContext) (*domain.Account, error) {

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	dbName := utils.ToDBName("accounts")
	oldAccount := &domain.Account{}

	err = query.Where(dbName+".id = ?", id).First(oldAccount).Error
	if err != nil {
		if strings.Contains(err.Error(), "record not found") {
			return nil, internalerrors.NotFound
		}

		return nil, internalerrors.DatabaseError
	}

	account.ID = oldAccount.ID
	account.CreatedAt = oldAccount.CreatedAt

	err = r.store.GetDB().Save(&account).Error
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return account, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:34,代碼來源:account_repository.go

示例3: UpdateAttributesByID

func (r *UserRepo) UpdateAttributesByID(id int, attributes map[string]interface{},
	context usecases.QueryContext) (*domain.User, error) {

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	dbName := utils.ToDBName("users")
	user := &domain.User{}

	err = query.Where(dbName+".id = ?", id).First(user).Error
	if err != nil {
		if strings.Contains(err.Error(), "record not found") {
			return nil, internalerrors.NotFound
		}

		return nil, internalerrors.DatabaseError
	}

	err = r.store.GetDB().Model(&user).Updates(attributes).Error
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return user, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:31,代碼來源:user_repository.go

示例4: UpdateByID

func (r *SessionRepo) UpdateByID(id int, session *domain.Session,
	context usecases.QueryContext) (*domain.Session, error) {

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	dbName := utils.ToDBName("sessions")

	err = query.Where(dbName+".id = ?", id).First(&domain.Session{}).Error
	if err != nil {
		if strings.Contains(err.Error(), "record not found") {
			return nil, internalerrors.NotFound
		}

		return nil, internalerrors.DatabaseError
	}

	err = r.store.GetDB().Where(dbName+".id = ?", id).Model(&domain.Session{}).Updates(&session).Error
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return session, nil
}
開發者ID:optimuse,項目名稱:zest,代碼行數:30,代碼來源:session_repository.go

示例5: Raw

func (r *AccountRepo) Raw(query string, values ...interface{}) (*sql.Rows, error) {
	db := r.store.GetDB()

	rows, err := db.Raw(query, values...).Rows()
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return rows, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:14,代碼來源:account_repository.go

示例6: Update

func (r *AccountRepo) Update(accounts []domain.Account, context usecases.QueryContext) ([]domain.Account, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	for _, account := range accounts {
		queryCopy := *query

		dbName := utils.ToDBName("accounts")
		oldAccount := &domain.Account{}

		err = queryCopy.Where(dbName+".id = ?", account.ID).First(oldAccount).Error
		if err != nil {
			if strings.Contains(err.Error(), "record not found") {
				return nil, internalerrors.NotFound
			}

			return nil, internalerrors.DatabaseError
		}

		account.ID = oldAccount.ID
		account.CreatedAt = oldAccount.CreatedAt

		err = r.store.GetDB().Save(&account).Error
		if err != nil {
			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}
	}

	transaction.Commit()
	return accounts, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:40,代碼來源:account_repository.go

示例7: Update

func (r *RoleMappingRepo) Update(roleMappings []domain.RoleMapping, context usecases.QueryContext) ([]domain.RoleMapping, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	for _, roleMapping := range roleMappings {
		queryCopy := *query

		dbName := utils.ToDBName("roleMappings")
		oldRoleMapping := &domain.RoleMapping{}

		err = queryCopy.Where(dbName+".id = ?", roleMapping.ID).First(oldRoleMapping).Error
		if err != nil {
			if strings.Contains(err.Error(), "record not found") {
				return nil, internalerrors.NotFound
			}

			return nil, internalerrors.DatabaseError
		}

		roleMapping.ID = oldRoleMapping.ID
		roleMapping.CreatedAt = oldRoleMapping.CreatedAt

		err = r.store.GetDB().Save(&roleMapping).Error
		if err != nil {
			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}
	}

	transaction.Commit()
	return roleMappings, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:40,代碼來源:role_mapping_repository.go

示例8: Create

func (r *AccountRepo) Create(accounts []domain.Account) ([]domain.Account, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	for i, account := range accounts {
		err := db.Create(&account).Error
		if err != nil {
			transaction.Rollback()

			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}

		accounts[i] = account
	}

	transaction.Commit()
	return accounts, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:22,代碼來源:account_repository.go

示例9: Create

func (r *UserRepo) Create(users []domain.User) ([]domain.User, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	for i, user := range users {
		err := db.Create(&user).Error
		if err != nil {
			transaction.Rollback()

			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}

		users[i] = user
	}

	transaction.Commit()
	return users, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:22,代碼來源:user_repository.go

示例10: Create

func (r *RoleRepo) Create(roles []domain.Role) ([]domain.Role, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	for i, role := range roles {
		err := db.Create(&role).Error
		if err != nil {
			transaction.Rollback()

			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}

		roles[i] = role
	}

	transaction.Commit()
	return roles, nil
}
開發者ID:wid-la,項目名稱:wus,代碼行數:22,代碼來源:role_repository.go

示例11: Create

func (r *SessionRepo) Create(sessions []domain.Session) ([]domain.Session, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	for i, session := range sessions {
		err := db.Create(&session).Error
		if err != nil {
			transaction.Rollback()

			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}

		sessions[i] = session
	}

	transaction.Commit()
	return sessions, nil
}
開發者ID:optimuse,項目名稱:zest,代碼行數:22,代碼來源:session_repository.go

示例12: Update

func (r *SessionRepo) Update(sessions []domain.Session, context usecases.QueryContext) ([]domain.Session, error) {
	db := r.store.GetDB()
	transaction := db.Begin()

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	for _, session := range sessions {
		queryCopy := *query

		dbName := utils.ToDBName("sessions")

		err = queryCopy.Where(dbName+".id = ?", session.ID).First(&domain.Session{}).Error
		if err != nil {
			if strings.Contains(err.Error(), "record not found") {
				return nil, internalerrors.NotFound
			}

			return nil, internalerrors.DatabaseError
		}

		err = r.store.GetDB().Where(dbName+".id = ?", session.ID).Model(&domain.Session{}).Updates(&session).Error
		if err != nil {
			if strings.Contains(err.Error(), "constraint") {
				return nil, internalerrors.NewViolatedConstraint(err.Error())
			}

			return nil, internalerrors.DatabaseError
		}
	}

	transaction.Commit()
	return sessions, nil
}
開發者ID:optimuse,項目名稱:zest,代碼行數:36,代碼來源:session_repository.go


注:本文中的github.com/solher/zest/internalerrors.NewViolatedConstraint函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。