本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}