本文整理汇总了Golang中github.com/jinzhu/gorm.Scope类的典型用法代码示例。如果您正苦于以下问题:Golang Scope类的具体用法?Golang Scope怎么用?Golang Scope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scope类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:nilslice,项目名称:qor,代码行数:7,代码来源:scope.go
示例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
}
开发者ID:caizengjun,项目名称:qor,代码行数:8,代码来源:resource.go
示例3: assignCreatedBy
func assignCreatedBy(scope *gorm.Scope) {
if isAuditable(scope) {
if user, ok := getCurrentUser(scope); ok {
scope.SetColumn("CreatedBy", user)
}
}
}
开发者ID:8legd,项目名称:qor-qor,代码行数:7,代码来源:callbacks.go
示例4: updateTimeStampWhenCreate
func updateTimeStampWhenCreate(scope *gorm.Scope) {
if !scope.HasError() {
now := time.Now()
scope.SetColumn("Created", now)
scope.SetColumn("Updated", now)
}
}
开发者ID:thnguyn2,项目名称:WebGPU,代码行数:7,代码来源:models.go
示例5: syncToProductionAfterDelete
func syncToProductionAfterDelete(scope *gorm.Scope) {
if !scope.HasError() {
if ok, clone := getModeAndNewScope(scope); ok {
gorm.Delete(clone)
}
}
}
开发者ID:JosephBuchma,项目名称:qor,代码行数:7,代码来源:callbacks.go
示例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)
}
}
}
开发者ID:tomi-,项目名称:qor,代码行数:7,代码来源:callbacks.go
示例7: setLocale
func setLocale(scope *gorm.Scope, locale string) {
for _, field := range scope.Fields() {
if field.Name == "LanguageCode" {
field.Set(locale)
}
}
}
开发者ID:nilslice,项目名称:qor,代码行数:7,代码来源:scope.go
示例8: syncDeleteFromProductionToDraft
func syncDeleteFromProductionToDraft(scope *gorm.Scope) {
if !scope.HasError() {
if ok, clone := isProductionModeAndNewScope(scope); ok {
scope.DB().Callback().Delete().Get("gorm:delete")(clone)
}
}
}
开发者ID:qor,项目名称:publish,代码行数:7,代码来源:callbacks.go
示例9: syncDeleteFromProductionToDraft
func syncDeleteFromProductionToDraft(scope *gorm.Scope) {
if !scope.HasError() {
if ok, clone := isProductionModeAndNewScope(scope); ok {
gorm.Delete(clone)
}
}
}
开发者ID:8legd,项目名称:qor-qor,代码行数:7,代码来源:callbacks.go
示例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
}
开发者ID:kennylixi,项目名称:qor,代码行数:8,代码来源:callbacks.go
示例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
}
开发者ID:nilslice,项目名称:qor,代码行数:8,代码来源:scope.go
示例12: syncColumns
func syncColumns(scope *gorm.Scope) (columns []string) {
for _, field := range scope.GetModelStruct().StructFields {
if isSyncField(field) {
columns = append(columns, field.DBName)
}
}
return
}
开发者ID:nilslice,项目名称:qor,代码行数:8,代码来源:scope.go
示例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")
}
}
开发者ID:kennylixi,项目名称:qor,代码行数:10,代码来源:callbacks.go
示例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)
}
}
开发者ID:kennylixi,项目名称:qor,代码行数:11,代码来源:callbacks.go
示例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
}
开发者ID:fengjh,项目名称:gorm_cannot_updates_virtual_attributes,代码行数:11,代码来源:main.go
示例16: toQueryCondition
func toQueryCondition(scope *gorm.Scope, columns []string) string {
var newColumns []string
for _, column := range columns {
newColumns = append(newColumns, scope.Quote(column))
}
if len(columns) > 1 {
return fmt.Sprintf("(%v)", strings.Join(newColumns, ","))
}
return strings.Join(columns, ",")
}
开发者ID:qor,项目名称:publish,代码行数:11,代码来源:resolver.go
示例17: beforeCreate
func beforeCreate(scope *gorm.Scope) {
if isLocalizable(scope) {
if locale, ok := getLocale(scope); ok { // is locale
if isLocaleCreateable(scope) || !scope.PrimaryKeyZero() {
setLocale(scope, locale)
} else {
scope.Err(errors.New("permission denied to create from locale"))
}
} else {
setLocale(scope, Global)
}
}
}
开发者ID:nilslice,项目名称:qor,代码行数:13,代码来源:callbacks.go
示例18: BeforeCreate
func (session *Session) BeforeCreate(scope *gorm.Scope) error {
scope.SetColumn("Token", GenerateRandomString(64))
scope.SetColumn("UUID", generateUUID())
scope.SetColumn("Moment", time.Now().UTC().Unix())
scope.SetColumn("ExpiresIn", expirationLengthForTokenType(session.TokenType))
return nil
}
开发者ID:earaujoassis,项目名称:space,代码行数:7,代码来源:sessions.go
示例19: getFuncMap
func getFuncMap(scope *gorm.Scope, field *gorm.Field, filename string) template.FuncMap {
hash := func() string { return strings.Replace(time.Now().Format("20060102150506.000000000"), ".", "", -1) }
return template.FuncMap{
"class": scope.TableName,
"primary_key": func() string { return fmt.Sprintf("%v", scope.PrimaryKeyValue()) },
"column": func() string { return field.Name },
"filename": func() string { return filename },
"basename": func() string { return strings.TrimSuffix(path.Base(filename), path.Ext(filename)) },
"hash": hash,
"filename_with_hash": func() string {
return fmt.Sprintf("%v.%v%v", strings.TrimSuffix(filename, path.Ext(filename)), hash(), path.Ext(filename))
},
"extension": func() string { return strings.TrimPrefix(path.Ext(filename), ".") },
}
}
开发者ID:gitter-badger,项目名称:qor,代码行数:15,代码来源:base.go
示例20: getFuncMap
func getFuncMap(scope *gorm.Scope, field *gorm.Field, filename string) template.FuncMap {
hash := func() string { return strings.Replace(time.Now().Format("20060102150506.000000000"), ".", "", -1) }
return template.FuncMap{
"class": func() string { return inflection.Plural(utils.ToParamString(scope.GetModelStruct().ModelType.Name())) },
"primary_key": func() string { return fmt.Sprintf("%v", scope.PrimaryKeyValue()) },
"column": func() string { return strings.ToLower(field.Name) },
"filename": func() string { return filename },
"basename": func() string { return strings.TrimSuffix(path.Base(filename), path.Ext(filename)) },
"hash": hash,
"filename_with_hash": func() string {
return urlReplacer.ReplaceAllString(fmt.Sprintf("%v.%v%v", strings.TrimSuffix(filename, path.Ext(filename)), hash(), path.Ext(filename)), "-")
},
"extension": func() string { return strings.TrimPrefix(path.Ext(filename), ".") },
}
}
开发者ID:qor,项目名称:media_library,代码行数:15,代码来源:base.go
注:本文中的github.com/jinzhu/gorm.Scope类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论