本文整理汇总了Golang中github.com/jinzhu/gorm.Scope类的典型用法代码示例。如果您正苦于以下问题:Golang Scope类的具体用法?Golang Scope怎么用?Golang Scope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: isLocalizable
func isLocalizable(scope *gorm.Scope) (isLocalizable bool) {
if scope.GetModelStruct().ModelType == nil {
return false
}
_, isLocalizable = reflect.New(scope.GetModelStruct().ModelType).Interface().(l10nInterface)
return
}
示例2: PrimaryField
// PrimaryField return gorm's primary field
func (res *Resource) PrimaryField() *gorm.Field {
if res.primaryField == nil {
scope := gorm.Scope{Value: res.Value}
res.primaryField = scope.PrimaryField()
}
return res.primaryField
}
示例3: assignCreatedBy
func assignCreatedBy(scope *gorm.Scope) {
if isAuditable(scope) {
if user, ok := getCurrentUser(scope); ok {
scope.SetColumn("CreatedBy", user)
}
}
}
示例4: updateTimeStampWhenCreate
func updateTimeStampWhenCreate(scope *gorm.Scope) {
if !scope.HasError() {
now := time.Now()
scope.SetColumn("Created", now)
scope.SetColumn("Updated", now)
}
}
示例5: syncToProductionAfterDelete
func syncToProductionAfterDelete(scope *gorm.Scope) {
if !scope.HasError() {
if ok, clone := getModeAndNewScope(scope); ok {
gorm.Delete(clone)
}
}
}
示例6: beforeDelete
func beforeDelete(scope *gorm.Scope) {
if isLocalizable(scope) {
if locale, ok := getLocale(scope); ok { // is locale
scope.Search.Where(fmt.Sprintf("%v.language_code = ?", scope.QuotedTableName()), locale)
}
}
}
示例7: setLocale
func setLocale(scope *gorm.Scope, locale string) {
for _, field := range scope.Fields() {
if field.Name == "LanguageCode" {
field.Set(locale)
}
}
}
示例8: syncDeleteFromProductionToDraft
func syncDeleteFromProductionToDraft(scope *gorm.Scope) {
if !scope.HasError() {
if ok, clone := isProductionModeAndNewScope(scope); ok {
scope.DB().Callback().Delete().Get("gorm:delete")(clone)
}
}
}
示例9: syncDeleteFromProductionToDraft
func syncDeleteFromProductionToDraft(scope *gorm.Scope) {
if !scope.HasError() {
if ok, clone := isProductionModeAndNewScope(scope); ok {
gorm.Delete(clone)
}
}
}
示例10: isDraftMode
func isDraftMode(scope *gorm.Scope) bool {
if draftMode, ok := scope.Get("publish:draft_mode"); ok {
if isDraft, ok := draftMode.(bool); ok && isDraft {
return true
}
}
return false
}
示例11: getLocale
func getLocale(scope *gorm.Scope) (locale string, ok bool) {
if str, ok := scope.DB().Get("l10n:locale"); ok {
if locale, ok := str.(string); ok {
return locale, (locale != Global) && (locale != "")
}
}
return Global, false
}
示例12: syncColumns
func syncColumns(scope *gorm.Scope) (columns []string) {
for _, field := range scope.GetModelStruct().StructFields {
if isSyncField(field) {
columns = append(columns, field.DBName)
}
}
return
}
示例13: validate
func validate(scope *gorm.Scope) {
db := scope.DB()
if _, ok := db.Get(settingKey); !ok {
db.InstantSet(settingKey, map[string][]string{})
}
if result, ok := db.Get(skipValidations); !(ok && result.(bool)) {
scope.CallMethodWithErrorCheck("Validate")
}
}
示例14: syncToProductionAfterUpdate
func syncToProductionAfterUpdate(scope *gorm.Scope) {
if ok, clone := getModeAndNewScope(scope); ok {
if updateAttrs, ok := scope.InstanceGet("gorm:update_attrs"); ok {
table := originalTableName(scope.TableName())
clone.Search = scope.Search
clone.Search.Table(table)
clone.InstanceSet("gorm:update_attrs", updateAttrs)
}
gorm.Update(clone)
}
}
示例15: setEncryptedPassword
func (user *User) setEncryptedPassword(scope *gorm.Scope) error {
pw, err := bcrypt.GenerateFromPassword([]byte(user.Password), 0)
if err != nil {
return err
}
scope.SetColumn("EncryptedPassword", string(pw))
user.Password = ""
return nil
}