• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang db.Query类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/quintans/goSQL/db.Query的典型用法代码示例。如果您正苦于以下问题:Golang Query类的具体用法?Golang Query怎么用?Golang Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: Group

func (this *QueryBuilder) Group(query *db.Query) {
	groups := query.GetGroupByTokens()
	for _, group := range groups {
		//this.groupPart.Add(this.translator.ColumnAlias(group.Token, group.Position))
		this.groupPart.Add(this.translator.Translate(db.QUERY, group.Token))
	}
}
开发者ID:quintans,项目名称:goSQL,代码行数:7,代码来源:GenericTranslator.go


示例2: FromSubQuery

func (this *QueryBuilder) FromSubQuery(query *db.Query) {
	subquery := query.GetSubQuery()
	alias := query.GetSubQueryAlias()
	this.fromPart.AddAsOne("(", this.translator.GetSqlForQuery(subquery), ")")
	if alias != "" {
		this.fromPart.Append(" ", alias)
	}
}
开发者ID:quintans,项目名称:goSQL,代码行数:8,代码来源:GenericTranslator.go


示例3: Union

func (this *QueryBuilder) Union(query *db.Query) {
	unions := query.GetUnions()
	for _, u := range unions {
		this.unionPart.Add(" UNION ")
		if u.All {
			this.unionPart.Add("ALL ")
		}
		this.unionPart.Add(this.translator.GetSqlForQuery(u.Query))
	}
}
开发者ID:quintans,项目名称:goSQL,代码行数:10,代码来源:GenericTranslator.go


示例4: Order

func (this *QueryBuilder) Order(query *db.Query) {
	orders := query.GetOrders()
	for _, ord := range orders {
		if ord.GetHolder() != nil {
			this.orderPart.Add(this.translator.Translate(db.QUERY, ord.GetHolder()))
		} else {
			this.orderPart.Add(ord.GetAlias())
		}

		if ord.IsAsc() {
			this.orderPart.Append(" ASC")
		} else {
			this.orderPart.Append(" DESC")
		}
	}
}
开发者ID:quintans,项目名称:goSQL,代码行数:16,代码来源:GenericTranslator.go


示例5: CreateQueryProcessor

func (this *GenericTranslator) CreateQueryProcessor(query *db.Query) QueryProcessor {
	proc := this.QueryProcessorFactory()

	proc.Column(query)
	if query.GetTable() != nil {
		proc.From(query)
	} else {
		proc.FromSubQuery(query)
	}
	proc.Where(query)
	// it is after the where clause because the joins can go to the where clause,
	// and this way the restrictions over the driving table will be applied first
	AppendJoins(query.GetJoins(), proc)
	proc.Group(query)
	proc.Having(query)
	proc.Union(query)
	proc.Order(query)

	return proc
}
开发者ID:quintans,项目名称:goSQL,代码行数:20,代码来源:GenericTranslator.go


示例6: GetSqlForQuery

func (this *GenericTranslator) GetSqlForQuery(query *db.Query) string {
	proc := this.CreateQueryProcessor(query)

	// SELECT COLUNAS
	sel := tk.NewStrBuffer()
	sel.Add("SELECT ")
	if query.IsDistinct() {
		sel.Add("DISTINCT ")
	}
	sel.Add(proc.ColumnPart())
	// FROM
	sel.Add(" FROM ", proc.FromPart())
	// JOINS
	sel.Add(proc.JoinPart())
	// WHERE - conditions
	if query.GetCriteria() != nil {
		sel.Add(" WHERE ", proc.WherePart())
	}
	// GROUP BY
	if len(query.GetGroupBy()) != 0 {
		sel.Add(" GROUP BY ", proc.GroupPart())
	}
	// HAVING
	if query.GetHaving() != nil {
		sel.Add(" HAVING ", proc.HavingPart())
	}
	// UNION
	if len(query.GetUnions()) != 0 {
		sel.Add(proc.UnionPart())
	}
	// ORDER
	if len(query.GetOrders()) != 0 {
		sel.Add(" ORDER BY ", proc.OrderPart())
	}

	sql := this.overrider.PaginateSQL(query, sel.String())

	return sql
}
开发者ID:quintans,项目名称:goSQL,代码行数:39,代码来源:GenericTranslator.go


示例7: Having

func (this *QueryBuilder) Having(query *db.Query) {
	having := query.GetHaving()
	if having != nil {
		this.havingPart.Add(this.translator.Translate(db.QUERY, having))
	}
}
开发者ID:quintans,项目名称:goSQL,代码行数:6,代码来源:GenericTranslator.go


示例8: Where

func (this *QueryBuilder) Where(query *db.Query) {
	criteria := query.GetCriteria()
	if criteria != nil {
		this.wherePart.Add(this.translator.Translate(db.QUERY, criteria))
	}
}
开发者ID:quintans,项目名称:goSQL,代码行数:6,代码来源:GenericTranslator.go


示例9: From

func (this *QueryBuilder) From(query *db.Query) {
	table := query.GetTable()
	alias := query.GetTableAlias()
	this.fromPart.AddAsOne(this.translator.TableName(table), " ", alias)
}
开发者ID:quintans,项目名称:goSQL,代码行数:5,代码来源:GenericTranslator.go


示例10: PaginateSQL

func (this *FirebirdSQLTranslator) PaginateSQL(query *db.Query, sql string) string {
	sb := tk.NewStrBuffer()
	if query.GetLimit() > 0 {
		sb.Add(sql, " ROWS ")
		if query.GetSkip() > 0 {
			sb.Add(":", db.OFFSET_PARAM, " TO ")
			query.SetParameter(db.OFFSET_PARAM, query.GetSkip()+1)
		}
		sb.Add(":", db.LIMIT_PARAM)
		query.SetParameter(db.LIMIT_PARAM, query.GetSkip()+query.GetLimit())

		return sb.String()
	}

	return sql
}
开发者ID:quintans,项目名称:goSQL,代码行数:16,代码来源:FirebirdSQLTranslator.go


示例11: PaginateSQL

func (this *MySQL5Translator) PaginateSQL(query *db.Query, sql string) string {
	sb := tk.NewStrBuffer()
	if query.GetLimit() > 0 {
		sb.Add(sql, " LIMIT :", db.OFFSET_PARAM, ", :", db.LIMIT_PARAM)
		if query.GetSkip() >= 0 {
			query.SetParameter(db.OFFSET_PARAM, query.GetSkip())
		}
		query.SetParameter(db.LIMIT_PARAM, query.GetLimit())
		return sb.String()
	}

	return sql
}
开发者ID:quintans,项目名称:goSQL,代码行数:13,代码来源:MySQL5Translator.go


示例12: PaginateSQL

func (this *OracleTranslator) PaginateSQL(query *db.Query, sql string) string {
	if query.GetSkip() > 0 {
		query.SetParameter(db.OFFSET_PARAM, query.GetSkip()+1)
		query.SetParameter(db.LIMIT_PARAM, query.GetSkip()+query.GetLimit())
		return fmt.Sprintf("select * from ( select a.*, rownum rnum from ( %s ) a where rownum <= :%s ) where rnum >= :%s",
			sql, db.LIMIT_PARAM, db.OFFSET_PARAM)
	} else if query.GetLimit() > 0 {
		query.SetParameter(db.LIMIT_PARAM, query.GetLimit())
		return fmt.Sprintf("select * from ( %s ) where rownum <= :%s", sql, db.LIMIT_PARAM)
	}

	return sql
}
开发者ID:quintans,项目名称:goSQL,代码行数:13,代码来源:OracleTranslator.go


示例13: QueryForPage

func QueryForPage(
	query *db.Query,
	criteria Criteria,
	target interface{},
	transformer func(in interface{}) interface{},
) (Page, error) {
	max := criteria.PageSize
	first := (criteria.Page - 1) * max
	// for the first page the offset is zero
	query.Skip(first)
	if max > 0 {
		query.Limit(max + 1)
	}

	var entities coll.Collection
	var err error
	var results []interface{}

	if reflect.TypeOf(target).Kind() == reflect.Func {
		results, err = query.ListInto(target)
	} else if _, ok := target.(tk.Hasher); ok {
		entities, err = query.ListFlatTreeOf(target)
	} else {
		entities, err = query.ListOf(target)
	}
	if err != nil {
		return Page{}, err
	}

	if results == nil {
		results = entities.Elements()
	}

	page := Page{}
	size := int64(len(results))
	if max > 0 && size > max {
		page.Last = false
		page.Results = results[:max]
	} else {
		page.Last = true
		page.Results = results
	}

	// transform results
	if transformer != nil {
		for k, v := range page.Results {
			page.Results[k] = transformer(v)
		}
	}

	// count records
	if criteria.CountRecords {
		DB := query.GetDb()
		cnt := DB.Query(query.GetTable())
		cnt.Copy(query)
		cnt.ColumnsReset()
		cnt.CountAll()
		cnt.OrdersReset()
		var recs int64
		_, err = cnt.SelectInto(&recs)
		if err != nil {
			return Page{}, err
		}
		page.Count = Int64(recs)
	}

	return page, nil
}
开发者ID:quintans,项目名称:toolkit,代码行数:68,代码来源:DAOUtils.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang db.Table类代码示例发布时间:2022-05-28
下一篇:
Golang db.Column类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap