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


Golang DB.First方法代码示例

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


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

示例1: PutProfileFieldCategory

func PutProfileFieldCategory(db gorm.DB, router *gin.Engine) {
	// PUT /profile_field_category
	// Update profile_field_category data by id
	router.PUT("/profile_field_category/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var profile_field_categoryData model.ProfileFieldCategoryData
			if err := c.BindJSON(&profile_field_categoryData); err == nil {
				profile_field_category := &model.ProfileFieldCategory{
					ProfileFieldCategoryData: profile_field_categoryData,
					ProfileFieldCategoryId:   model.ProfileFieldCategoryId{Id: id},
				}
				if err := checkDataProfileFieldCategory(profile_field_category.ProfileFieldCategoryData); err {
					checkProfileFieldCategory := &model.ProfileFieldCategory{
						ProfileFieldCategoryData: profile_field_categoryData,
						ProfileFieldCategoryId:   model.ProfileFieldCategoryId{Id: id},
					}
					if err := db.First(checkProfileFieldCategory).Error; err == nil {
						db.Save(&profile_field_category)
						c.JSON(http.StatusOK, profile_field_category)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:profile_field_category.go

示例2: PutNotification

func PutNotification(db gorm.DB, router *gin.Engine) {
	// PUT /notification
	// Update notification data by id
	router.PUT("/notification/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var notificationData model.NotificationData
			if err := c.BindJSON(&notificationData); err == nil {
				notification := &model.Notification{
					NotificationData: notificationData,
					NotificationId:   model.NotificationId{Id: id},
				}
				if err := checkDataNotification(notification.NotificationData); err {
					checkNotification := &model.Notification{
						NotificationData: notificationData,
						NotificationId:   model.NotificationId{Id: id},
					}
					if err := db.First(checkNotification).Error; err == nil {
						db.Save(&notification)
						c.JSON(http.StatusOK, notification)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:notification.go

示例3: PutUserHttpSession

func PutUserHttpSession(db gorm.DB, router *gin.Engine) {
	// PUT /user_http_session
	// Update user_http_session data by id
	router.PUT("/user_http_session/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var user_http_sessionData model.UserHttpSessionData
			if err := c.BindJSON(&user_http_sessionData); err == nil {
				user_http_session := &model.UserHttpSession{
					UserHttpSessionData: user_http_sessionData,
					UserHttpSessionId:   model.UserHttpSessionId{Id: id},
				}
				if err := checkDataUserHttpSession(user_http_session.UserHttpSessionData); err {
					checkUserHttpSession := &model.UserHttpSession{
						UserHttpSessionData: user_http_sessionData,
						UserHttpSessionId:   model.UserHttpSessionId{Id: id},
					}
					if err := db.First(checkUserHttpSession).Error; err == nil {
						db.Save(&user_http_session)
						c.JSON(http.StatusOK, user_http_session)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:user_http_session.go

示例4: PutLike

func PutLike(db gorm.DB, router *gin.Engine) {
	// PUT /like
	// Update like data by id
	router.PUT("/like/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var likeData model.LikeData
			if err := c.BindJSON(&likeData); err == nil {
				like := &model.Like{
					LikeData: likeData,
					LikeId:   model.LikeId{Id: id},
				}
				if err := checkDataLike(like.LikeData); err {
					checkLike := &model.Like{
						LikeData: likeData,
						LikeId:   model.LikeId{Id: id},
					}
					if err := db.First(checkLike).Error; err == nil {
						db.Save(&like)
						c.JSON(http.StatusOK, like)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:like.go

示例5: PutContent

func PutContent(db gorm.DB, router *gin.Engine) {
	// PUT /content
	// Update content data by id
	router.PUT("/content/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var contentData model.ContentData
			if err := c.BindJSON(&contentData); err == nil {
				content := &model.Content{
					ContentData: contentData,
					ContentId:   model.ContentId{Id: id},
				}
				if err := checkDataContent(content.ContentData); err {
					checkContent := &model.Content{
						ContentData: contentData,
						ContentId:   model.ContentId{Id: id},
					}
					if err := db.First(checkContent).Error; err == nil {
						db.Save(&content)
						c.JSON(http.StatusOK, content)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:content.go

示例6: PutModuleEnabled

func PutModuleEnabled(db gorm.DB, router *gin.Engine) {
	// PUT /module_enabled
	// Update module_enabled data by id
	router.PUT("/module_enabled/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var module_enabledData model.ModuleEnabledData
			if err := c.BindJSON(&module_enabledData); err == nil {
				module_enabled := &model.ModuleEnabled{
					ModuleEnabledData: module_enabledData,
					ModuleEnabledId:   model.ModuleEnabledId{Id: id},
				}
				if err := checkDataModuleEnabled(module_enabled.ModuleEnabledData); err {
					checkModuleEnabled := &model.ModuleEnabled{
						ModuleEnabledData: module_enabledData,
						ModuleEnabledId:   model.ModuleEnabledId{Id: id},
					}
					if err := db.First(checkModuleEnabled).Error; err == nil {
						db.Save(&module_enabled)
						c.JSON(http.StatusOK, module_enabled)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:module_enabled.go

示例7: PutWallEntry

func PutWallEntry(db gorm.DB, router *gin.Engine) {
	// PUT /wall_entry
	// Update wall_entry data by id
	router.PUT("/wall_entry/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var wall_entryData model.WallEntryData
			if err := c.BindJSON(&wall_entryData); err == nil {
				wall_entry := &model.WallEntry{
					WallEntryData: wall_entryData,
					WallEntryId:   model.WallEntryId{Id: id},
				}
				if err := checkDataWallEntry(wall_entry.WallEntryData); err {
					checkWallEntry := &model.WallEntry{
						WallEntryData: wall_entryData,
						WallEntryId:   model.WallEntryId{Id: id},
					}
					if err := db.First(checkWallEntry).Error; err == nil {
						db.Save(&wall_entry)
						c.JSON(http.StatusOK, wall_entry)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:wall_entry.go

示例8: PutPost

func PutPost(db gorm.DB, router *gin.Engine) {
	// PUT /post
	// Update post data by id
	router.PUT("/post/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var postData model.PostData
			if err := c.BindJSON(&postData); err == nil {
				post := &model.Post{
					PostData: postData,
					PostId:   model.PostId{Id: id},
				}
				if err := checkDataPost(post.PostData); err {
					checkPost := &model.Post{
						PostData: postData,
						PostId:   model.PostId{Id: id},
					}
					if err := db.First(checkPost).Error; err == nil {
						db.Save(&post)
						c.JSON(http.StatusOK, post)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:post.go

示例9: PutActivity

func PutActivity(db gorm.DB, router *gin.Engine) {
	// PUT /activity
	// Update activity data by id
	router.PUT("/activity/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var activityData model.ActivityData
			if err := c.BindJSON(&activityData); err == nil {
				activity := &model.Activity{
					ActivityData: activityData,
					ActivityId:   model.ActivityId{Id: id},
				}
				if err := checkDataActivity(activity.ActivityData); err {
					checkActivity := &model.Activity{
						ActivityData: activityData,
						ActivityId:   model.ActivityId{Id: id},
					}
					if err := db.First(checkActivity).Error; err == nil {
						db.Save(&activity)
						c.JSON(http.StatusOK, activity)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:activity.go

示例10: PutGroupAdmin

func PutGroupAdmin(db gorm.DB, router *gin.Engine) {
	// PUT /group_admin
	// Update group_admin data by id
	router.PUT("/group_admin/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var group_adminData model.GroupAdminData
			if err := c.BindJSON(&group_adminData); err == nil {
				group_admin := &model.GroupAdmin{
					GroupAdminData: group_adminData,
					GroupAdminId:   model.GroupAdminId{Id: id},
				}
				if err := checkDataGroupAdmin(group_admin.GroupAdminData); err {
					checkGroupAdmin := &model.GroupAdmin{
						GroupAdminData: group_adminData,
						GroupAdminId:   model.GroupAdminId{Id: id},
					}
					if err := db.First(checkGroupAdmin).Error; err == nil {
						db.Save(&group_admin)
						c.JSON(http.StatusOK, group_admin)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:group_admin.go

示例11: PutUrlOembed

func PutUrlOembed(db gorm.DB, router *gin.Engine) {
	// PUT /url_oembed
	// Update url_oembed data by id
	router.PUT("/url_oembed/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var url_oembedData model.UrlOembedData
			if err := c.BindJSON(&url_oembedData); err == nil {
				url_oembed := &model.UrlOembed{
					UrlOembedData: url_oembedData,
					UrlOembedId:   model.UrlOembedId{Id: id},
				}
				if err := checkDataUrlOembed(url_oembed.UrlOembedData); err {
					checkUrlOembed := &model.UrlOembed{
						UrlOembedData: url_oembedData,
						UrlOembedId:   model.UrlOembedId{Id: id},
					}
					if err := db.First(checkUrlOembed).Error; err == nil {
						db.Save(&url_oembed)
						c.JSON(http.StatusOK, url_oembed)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:url_oembed.go

示例12: PutSpaceSetting

func PutSpaceSetting(db gorm.DB, router *gin.Engine) {
	// PUT /space_setting
	// Update space_setting data by id
	router.PUT("/space_setting/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var space_settingData model.SpaceSettingData
			if err := c.BindJSON(&space_settingData); err == nil {
				space_setting := &model.SpaceSetting{
					SpaceSettingData: space_settingData,
					SpaceSettingId:   model.SpaceSettingId{Id: id},
				}
				if err := checkDataSpaceSetting(space_setting.SpaceSettingData); err {
					checkSpaceSetting := &model.SpaceSetting{
						SpaceSettingData: space_settingData,
						SpaceSettingId:   model.SpaceSettingId{Id: id},
					}
					if err := db.First(checkSpaceSetting).Error; err == nil {
						db.Save(&space_setting)
						c.JSON(http.StatusOK, space_setting)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:space_setting.go

示例13: PutFile

func PutFile(db gorm.DB, router *gin.Engine) {
	// PUT /file
	// Update file data by id
	router.PUT("/file/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var fileData model.FileData
			if err := c.BindJSON(&fileData); err == nil {
				file := &model.File{
					FileData: fileData,
					FileId:   model.FileId{Id: id},
				}
				if err := checkDataFile(file.FileData); err {
					checkFile := &model.File{
						FileData: fileData,
						FileId:   model.FileId{Id: id},
					}
					if err := db.First(checkFile).Error; err == nil {
						db.Save(&file)
						c.JSON(http.StatusOK, file)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
开发者ID:ali-abdalla,项目名称:humhub-api,代码行数:33,代码来源:file.go

示例14: ProjectGet

func ProjectGet(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
	}
	r.JSON(http.StatusOK, project)
}
开发者ID:jerryclinesmith,项目名称:notabbble,代码行数:8,代码来源:project_controller.go

示例15: findTodo

func findTodo(db *gorm.DB, predicate *todo) (*todo, error) {
	t := new(todo)
	err := db.First(t, predicate).Error
	if err != nil {
		return nil, err
	}
	return t, nil
}
开发者ID:danihodovic,项目名称:go-martini-gorm-angular-todo,代码行数:8,代码来源:server.go


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