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


Golang dbr.SelectBuilder類代碼示例

本文整理匯總了Golang中github.com/corestoreio/csfw/storage/dbr.SelectBuilder的典型用法代碼示例。如果您正苦於以下問題:Golang SelectBuilder類的具體用法?Golang SelectBuilder怎麽用?Golang SelectBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: SQLQueryToColumns

// SQLQueryToColumns generates from a SQL query an array containing all the column properties.
// dbSelect argument can be nil but then you must provide query strings which will be joined to the final query.
func SQLQueryToColumns(db *sql.DB, dbSelect *dbr.SelectBuilder, query ...string) (Columns, error) {

	tableName := "tmp_" + randSeq(20)
	dropTable := func() {
		_, err := db.Exec("DROP TABLE IF EXISTS `" + tableName + "`")
		if err != nil {
			panic(err)
		}
	}
	dropTable()
	defer dropTable()

	qry := strings.Join(query, " ")
	var args []interface{}
	if qry == "" && dbSelect != nil {
		var err error
		qry, args, err = dbSelect.ToSql()
		if err != nil {
			return nil, errgo.Mask(err)
		}
	}
	_, err := db.Exec("CREATE TABLE `"+tableName+"` AS "+qry, args...)
	if err != nil {
		return nil, errgo.Mask(err)
	}

	return GetColumns(db, tableName)
}
開發者ID:joao-parana,項目名稱:csfw,代碼行數:30,代碼來源:database.go

示例2: LoadStringEntities

// LoadStringEntities executes a SELECT query and returns a slice containing columns names and its string values
func LoadStringEntities(db *sql.DB, dbSelect *dbr.SelectBuilder) ([]StringEntities, error) {

	qry, args, err := dbSelect.ToSql()
	if err != nil {
		return nil, errgo.Mask(err)
	}

	rows, err := db.Query(qry, args...)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	defer rows.Close()

	columnNames, err := rows.Columns()
	if err != nil {
		return nil, errgo.Mask(err)
	}

	ret := make([]StringEntities, 0, 2000)
	rss := newRowTransformer(columnNames)
	for rows.Next() {

		if err := rows.Scan(rss.cp...); err != nil {
			return nil, errgo.Mask(err)
		}
		err := rss.toString()
		if err != nil {
			return nil, errgo.Mask(err)
		}
		rss.append(&ret)
	}
	return ret, nil
}
開發者ID:joao-parana,項目名稱:csfw,代碼行數:34,代碼來源:database.go

示例3: LoadStringEntities

// LoadStringEntities executes a SELECT query and returns a slice containing columns names and its string values
func LoadStringEntities(db *sql.DB, dbSelect *dbr.SelectBuilder, query ...string) ([]StringEntities, error) {

	qry := strings.Join(query, " ")
	var args []interface{}
	if qry == "" && dbSelect != nil {
		qry, args = dbSelect.ToSql()
	}

	rows, err := db.Query(qry, args...)
	if err != nil {
		return nil, log.Error("codegen.LoadStringEntities.Query420", "err", err)
	}
	defer rows.Close()

	columnNames, err := rows.Columns()
	if err != nil {
		return nil, log.Error("codegen.LoadStringEntities.Columns", "err", err)
	}

	ret := make([]StringEntities, 0, 2000)
	rss := newRowTransformer(columnNames)
	for rows.Next() {

		if err := rows.Scan(rss.cp...); err != nil {
			return nil, log.Error("codegen.LoadStringEntities.Scan", "err", err)
		}
		err := rss.toString()
		if err != nil {
			return nil, log.Error("codegen.LoadStringEntities.ToString", "err", err)
		}
		rss.append(&ret)
	}
	return ret, nil
}
開發者ID:hafeez3000,項目名稱:csfw,代碼行數:35,代碼來源:database.go


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