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


Golang Scope.Quote方法代码示例

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


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

示例1: beforeQuery

func beforeQuery(scope *gorm.Scope) {
	if isLocalizable(scope) {
		quotedTableName := scope.QuotedTableName()
		quotedPrimaryKey := scope.Quote(scope.PrimaryKey())

		locale, isLocale := getLocale(scope)
		switch mode, _ := scope.DB().Get("l10n:mode"); mode {
		case "unscoped":
		case "global":
			scope.Search.Where(fmt.Sprintf("%v.language_code = ?", quotedTableName), Global)
		case "locale":
			scope.Search.Where(fmt.Sprintf("%v.language_code = ?", quotedTableName), locale)
		case "reverse":
			if !scope.Search.Unscoped && scope.Fields()["deleted_at"] != nil {
				scope.Search.Where(fmt.Sprintf("(%v NOT IN (SELECT DISTINCT(%v) FROM %v t2 WHERE t2.language_code = ? AND t2.deleted_at IS NULL) AND language_code = ?)", quotedPrimaryKey, quotedPrimaryKey, quotedTableName), locale, Global)
			} else {
				scope.Search.Where(fmt.Sprintf("(%v NOT IN (SELECT DISTINCT(%v) FROM %v t2 WHERE t2.language_code = ?) AND language_code = ?)", quotedPrimaryKey, quotedPrimaryKey, quotedTableName), locale, Global)
			}
		default:
			if isLocale {
				if !scope.Search.Unscoped && scope.Fields()["deleted_at"] != nil {
					scope.Search.Where(fmt.Sprintf("((%v NOT IN (SELECT DISTINCT(%v) FROM %v t2 WHERE t2.language_code = ? AND t2.deleted_at IS NULL) AND language_code = ?) OR language_code = ?) AND deleted_at IS NULL", quotedPrimaryKey, quotedPrimaryKey, quotedTableName), locale, Global, locale)
				} else {
					scope.Search.Where(fmt.Sprintf("(%v NOT IN (SELECT DISTINCT(%v) FROM %v t2 WHERE t2.language_code = ?) AND language_code = ?) OR (language_code = ?)", quotedPrimaryKey, quotedPrimaryKey, quotedTableName), locale, Global, locale)
				}
			} else {
				scope.Search.Where(fmt.Sprintf("%v.language_code = ?", quotedTableName), Global)
			}
		}
	}
}
开发者ID:strogo,项目名称:qor,代码行数:31,代码来源:callbacks.go

示例2: scopePrimaryKeys

func scopePrimaryKeys(scope *gorm.Scope, tableName string) string {
	var primaryKeys []string
	for _, field := range scope.PrimaryFields() {
		key := fmt.Sprintf("%v.%v", scope.Quote(tableName), scope.Quote(field.DBName))
		primaryKeys = append(primaryKeys, key)
	}
	if len(primaryKeys) > 1 {
		return fmt.Sprintf("(%v)", strings.Join(primaryKeys, ","))
	}
	return strings.Join(primaryKeys, "")
}
开发者ID:kennylixi,项目名称:qor,代码行数:11,代码来源:resolver.go

示例3: 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


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