当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.Delete方法代码示例

本文整理汇总了Golang中github.com/jinzhu/gorm.DB.Delete方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Delete方法的具体用法?Golang DB.Delete怎么用?Golang DB.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jinzhu/gorm.DB的用法示例。


在下文中一共展示了DB.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: deleteAccountHandler

//Deletes a certain account from the db
func deleteAccountHandler(db *gorm.DB, acc account, rendr render.Render) {
	if err := db.Delete(&acc).Error; err != nil {
		rendr.Text(http.StatusInternalServerError, err.Error())
	} else {
		rendr.Text(http.StatusOK, "Account deleted")
	}
}
开发者ID:danihodovic,项目名称:lendico,代码行数:8,代码来源:routes.go

示例2: MediaDelete

func MediaDelete(db gorm.DB, r render.Render, params martini.Params) {
	var media models.Media
	if err := db.First(&media, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Media not found"})
		return
	}
	db.Delete(media)
	r.JSON(http.StatusNoContent, nil)
}
开发者ID:RadioTerminal,项目名称:podcaster,代码行数:9,代码来源:media.go

示例3: ProjectDelete

func ProjectDelete(db gorm.DB, r render.Render, params martini.Params) {
	var project models.Project
	if err := db.First(&project, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Project not found"})
		return
	}
	db.Delete(project)
	r.JSON(http.StatusNoContent, nil)
}
开发者ID:jerryclinesmith,项目名称:notabbble,代码行数:9,代码来源:project_controller.go

示例4: GroupDelete

func GroupDelete(db gorm.DB, r render.Render, params martini.Params) {
	var group models.Group
	if err := db.First(&group, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Group not found"})
		return
	}
	db.Delete(group)
	r.JSON(http.StatusNoContent, nil)
}
开发者ID:RadioTerminal,项目名称:podcaster,代码行数:9,代码来源:group.go

示例5: DelRole

func (p *AuthDao) DelRole(db *gorm.DB, user uint, name string, resource_type string, resource_id uint) {
	role := p.getRole(db, name, resource_type, resource_id)
	for _, pe := range role.Permissions {
		if pe.UserID == user {
			db.Delete(&pe)
			return
		}
	}

}
开发者ID:itpkg,项目名称:base,代码行数:10,代码来源:dao.go

示例6: deleteUserHandler

//Deletes a user based on a given path `id` param
func deleteUserHandler(db *gorm.DB, params martini.Params, ren render.Render) {
	u, err := findUserFromIDParam(db, params["id"])
	if err != nil {
		ren.Text(err.toMartiniRender())
		return
	}
	if db.Delete(&u).Error != nil {
		ren.Text(http.StatusInternalServerError, err.Error())
		return
	}
	ren.Text(http.StatusOK, fmt.Sprintf("User with id: %d was deleted", u.ID))
}
开发者ID:danihodovic,项目名称:backend-test,代码行数:13,代码来源:routes.go

示例7: deleteTodoHandler

func deleteTodoHandler(params martini.Params, rendr render.Render, db *gorm.DB) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		panic(err)
	}

	t, err := findTodo(db, &todo{ID: id})
	if err != nil {
		rendr.Text(http.StatusBadRequest, err.Error())
		return
	}

	db.Delete(&t)
	rendr.JSON(http.StatusOK, t)
}
开发者ID:danihodovic,项目名称:go-martini-gorm-angular-todo,代码行数:15,代码来源:server.go

示例8: GetDeleteTaskHandler

// GetDeleteTaskHandler creates HTTP handler for Delete Task operation
func GetDeleteTaskHandler(db *gorm.DB) echo.HandlerFunc {
	return func(c *echo.Context) error {
		id, err := strconv.ParseInt(c.Param("id"), 10, 64)
		if err != nil {
			return c.JSON(http.StatusBadRequest, NewApiError(err.Error()))
		}

		task := model.Task{Id: id}
		if err := db.Delete(&task).Error; err != nil {
			return c.JSON(http.StatusInternalServerError, NewApiError(err.Error()))
		}

		return c.JSON(http.StatusOK, task)
	}
}
开发者ID:seesawlabs,项目名称:ivan-kirichenko-exercise,代码行数:16,代码来源:task.go

示例9: BeforeDelete

// BeforeDelete invokes required actions before deletion.
func (u *Repo) BeforeDelete(tx *gorm.DB) error {
	tags := Tags{}

	tx.Model(
		u,
	).Related(
		&tags,
	)

	for _, tag := range tags {
		if err := tx.Delete(tag).Error; err != nil {
			return err
		}
	}

	return nil
}
开发者ID:umschlag,项目名称:umschlag-api,代码行数:18,代码来源:repo.go

示例10: upgrade_v3

func upgrade_v3(db gorm.DB) {
	// Hash the passwords
	logging.Info("Migrating 2 => 3")

	var unhashed []user.AuthenticationMethod
	db.Where("method_type = ?", user.AUTH_PASSWD).Find(&unhashed)

	for i := 0; i < len(unhashed); i++ {
		hashed, err := user.HashedPasswordAuth(unhashed[i].Value)
		if err != nil {
			logging.Error("data", "Could not transform password. ID ", unhashed[i].ID)
		} else {
			hashed.UserID = unhashed[i].UserID

			db.Create(&hashed)
			db.Delete(&unhashed[i])
		}
	}
}
开发者ID:twitchyliquid64,项目名称:CNC,代码行数:19,代码来源:transform.go

示例11: DeleteSpaceSetting

func DeleteSpaceSetting(db gorm.DB, router *gin.Engine) {

	router.DELETE("/space_setting/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			space_setting := &model.SpaceSetting{
				SpaceSettingId: model.SpaceSettingId{Id: id},
			}
			if err := db.First(space_setting).Error; err == nil {
				db.Delete(space_setting)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:20,代码来源:space_setting.go

示例12: DeleteWallEntry

func DeleteWallEntry(db gorm.DB, router *gin.Engine) {

	router.DELETE("/wall_entry/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			wall_entry := &model.WallEntry{
				WallEntryId: model.WallEntryId{Id: id},
			}
			if err := db.First(wall_entry).Error; err == nil {
				db.Delete(wall_entry)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:20,代码来源:wall_entry.go

示例13: DeleteGroupAdmin

func DeleteGroupAdmin(db gorm.DB, router *gin.Engine) {

	router.DELETE("/group_admin/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			group_admin := &model.GroupAdmin{
				GroupAdminId: model.GroupAdminId{Id: id},
			}
			if err := db.First(group_admin).Error; err == nil {
				db.Delete(group_admin)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:20,代码来源:group_admin.go

示例14: DeleteModuleEnabled

func DeleteModuleEnabled(db gorm.DB, router *gin.Engine) {

	router.DELETE("/module_enabled/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			module_enabled := &model.ModuleEnabled{
				ModuleEnabledId: model.ModuleEnabledId{Id: id},
			}
			if err := db.First(module_enabled).Error; err == nil {
				db.Delete(module_enabled)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:20,代码来源:module_enabled.go

示例15: DeleteUserHttpSession

func DeleteUserHttpSession(db gorm.DB, router *gin.Engine) {

	router.DELETE("/user_http_session/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			user_http_session := &model.UserHttpSession{
				UserHttpSessionId: model.UserHttpSessionId{Id: id},
			}
			if err := db.First(user_http_session).Error; err == nil {
				db.Delete(user_http_session)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:20,代码来源:user_http_session.go


注:本文中的github.com/jinzhu/gorm.DB.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。