當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SelectBuilder.Where方法代碼示例

本文整理匯總了Golang中github.com/lann/squirrel.SelectBuilder.Where方法的典型用法代碼示例。如果您正苦於以下問題:Golang SelectBuilder.Where方法的具體用法?Golang SelectBuilder.Where怎麽用?Golang SelectBuilder.Where使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/lann/squirrel.SelectBuilder的用法示例。


在下文中一共展示了SelectBuilder.Where方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addFilterToQuery

func addFilterToQuery(s *schema.Schema, q sq.SelectBuilder, filter map[string]interface{}, join bool) sq.SelectBuilder {
	if filter == nil {
		return q
	}
	for key, value := range filter {
		property, err := s.GetPropertyByID(key)
		var column string
		if join {
			column = makeColumn(s, *property)
		} else {
			column = quote(key)
		}
		if err != nil {
			log.Notice(err.Error())
			continue
		}

		if property.Type == "boolean" {
			v := make([]bool, len(value.([]string)))
			for i, j := range value.([]string) {
				v[i], _ = strconv.ParseBool(j)
			}
			q = q.Where(sq.Eq{column: v})
		} else {
			q = q.Where(sq.Eq{column: value})
		}
	}
	return q
}
開發者ID:gitter-badger,項目名稱:gohan,代碼行數:29,代碼來源:sql.go

示例2: addFilterToQuery

func addFilterToQuery(s *schema.Schema, q sq.SelectBuilder, filter map[string]interface{}, join bool) (sq.SelectBuilder, error) {
	if filter == nil {
		return q, nil
	}
	for key, value := range filter {
		property, err := s.GetPropertyByID(key)

		if err != nil {
			return q, err
		}

		var column string
		if join {
			column = makeColumn(s.GetDbTableName(), *property)
		} else {
			column = quote(key)
		}

		queryValues, ok := value.([]string)
		if ok && property.Type == "boolean" {
			v := make([]bool, len(queryValues))
			for i, j := range queryValues {
				v[i], _ = strconv.ParseBool(j)
			}
			q = q.Where(sq.Eq{column: v})
		} else {
			q = q.Where(sq.Eq{column: value})
		}
	}
	return q, nil
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:31,代碼來源:sql.go

示例3: ApplyTo

// ApplyTo returns a new SelectBuilder after applying the paging effects of
// `p` to `sql`.  This method provides the default case for paging: int64
// cursor-based paging by an id column.
func (p PageQuery) ApplyTo(
	sql sq.SelectBuilder,
	col string,
) (sq.SelectBuilder, error) {
	sql = sql.Limit(p.Limit)

	cursor, err := p.CursorInt64()
	if err != nil {
		return sql, err
	}

	switch p.Order {
	case "asc":
		sql = sql.
			Where(fmt.Sprintf("%s > ?", col), cursor).
			OrderBy(fmt.Sprintf("%s asc", col))
	case "desc":
		sql = sql.
			Where(fmt.Sprintf("%s < ?", col), cursor).
			OrderBy(fmt.Sprintf("%s desc", col))
	default:
		return sql, errors.Errorf("invalid order: %s", p.Order)
	}

	return sql, nil
}
開發者ID:irisli,項目名稱:horizon,代碼行數:29,代碼來源:page_query.go

示例4: Apply

func (f *EffectLedgerFilter) Apply(ctx context.Context, sql sq.SelectBuilder) (sq.SelectBuilder, error) {
	start := TotalOrderID{LedgerSequence: f.LedgerSequence}
	end := TotalOrderID{LedgerSequence: f.LedgerSequence + 1}
	return sql.Where(
		"(heff.history_operation_id >= ? AND heff.history_operation_id < ?)",
		start.ToInt64(),
		end.ToInt64(),
	), nil
}
開發者ID:zenododobird,項目名稱:horizon,代碼行數:9,代碼來源:record_effect.go

示例5: whereValueForKey

func whereValueForKey(builder squirrel.SelectBuilder, src interface{}, key, value string) (squirrel.SelectBuilder, error) {
	keyParts := strings.Split(key, "-")
	sqlString := ""

	switch len(keyParts) {
	case 1:
		if !structHasField(src, keyParts[0]) {
			return builder, nil
		}
		sqlString = keyParts[0] + " = ?"
	case 2:
		op := Operator(keyParts[0])
		field := keyParts[1]
		if !structHasField(src, field) {
			return builder, nil
		}
		switch op {
		case Lt:
			sqlString = field + " < ?"
		case Lte:
			sqlString = field + " <= ?"
		case Gt:
			sqlString = field + " > ?"
		case Gte:
			sqlString = field + " >= ?"
		case In:
			values := strings.Split(value, ",")
			builder = builder.Where(squirrel.Eq{field: values})
			return builder, nil
		default:
			return builder, nil
		}
	default:
		return builder, nil
	}

	builder = builder.Where(sqlString, value)
	return builder, nil
}
開發者ID:nancyandrews,項目名稱:MobileMainStreet,代碼行數:39,代碼來源:query.go


注:本文中的github.com/lann/squirrel.SelectBuilder.Where方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。