本文整理汇总了Golang中github.com/corestoreio/csfw/storage/dbr.SessionRunner类的典型用法代码示例。如果您正苦于以下问题:Golang SessionRunner类的具体用法?Golang SessionRunner怎么用?Golang SessionRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SessionRunner类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetColumns
// GetColumns returns all columns from a table. It discards the column entity_type_id from some
// entity tables.
func GetColumns(dbrSess dbr.SessionRunner, table string) (Columns, error) {
var cols = make(Columns, 0, 100)
sel := dbrSess.SelectBySql("SHOW COLUMNS FROM " + dbr.Quoter.Table(table))
selSql, selArg := sel.ToSql()
rows, err := sel.Query(selSql, selArg...)
if err != nil {
return nil, log.Error("csdb.GetColumns.Query", "err", err, "query", selSql, "args", selArg)
}
defer rows.Close()
col := Column{}
for rows.Next() {
err := rows.Scan(&col.Field, &col.Type, &col.Null, &col.Key, &col.Default, &col.Extra)
if err != nil {
return nil, log.Error("csdb.GetColumns.Rows.Scan", "err", err, "query", selSql, "args", selArg)
}
cols = append(cols, col)
}
err = rows.Err()
if err != nil {
return nil, log.Error("csdb.GetColumns.Rows.Err", "err", err, "query", selSql, "args", selArg)
}
return cols, nil
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:28,代码来源:columns.go
示例2: Select
// Select generates a SELECT * FROM tableName statement
func (ts *Table) Select(dbrSess dbr.SessionRunner) (*dbr.SelectBuilder, error) {
if ts == nil {
return nil, ErrTableNotFound
}
return dbrSess.
Select(ts.AllColumnAliasQuote("main_table")...).
From(ts.Name, "main_table"), nil
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:9,代码来源:table.go
示例3: GetTables
// GetTables returns all tables from a database. AndWhere can be optionally applied.
// Only first index (0) will be added.
func GetTables(dbrSess dbr.SessionRunner, sql ...string) ([]string, error) {
qry := "SHOW TABLES"
if len(sql) > 0 && sql[0] != "" {
if false == dbr.Stmt.IsSelect(sql[0]) {
qry = qry + " LIKE '" + sql[0] + "'"
} else {
qry = sql[0]
}
}
if PkgLog.IsDebug() { // this if reduces 9 allocs ...
defer log.WhenDone(PkgLog).Debug("Stats", "Package", "codegen", "Step", "GetTables", "query", qry)
}
sb := dbrSess.SelectBySql(qry)
query, args, err := sb.ToSql()
if err != nil {
return nil, errgo.Mask(err)
}
rows, err := sb.Query(query, args...)
if err != nil {
return nil, errgo.Mask(err)
}
defer rows.Close()
var tableName string
var tableNames = make([]string, 0, 200)
for rows.Next() {
if err := rows.Scan(&tableName); err != nil {
return nil, errgo.Mask(err)
}
tableNames = append(tableNames, tableName)
}
if err = rows.Err(); err != nil {
return nil, errgo.Mask(err)
}
return tableNames, nil
}
开发者ID:joao-parana,项目名称:csfw,代码行数:41,代码来源:database.go
示例4: GetAttributeSelectSql
// GetAttributeSelectSql generates the select query to retrieve full attribute configuration
// Implements the scope on a SQL query basis so that attribute functions does not need to deal with it.
// Tests see the tools package
// @see magento2/app/code/Magento/Eav/Model/Resource/Attribute/Collection.php::_initSelect()
func GetAttributeSelectSql(dbrSess dbr.SessionRunner, aat EntityTypeAdditionalAttributeTabler, entityTypeID, websiteID int64) (*dbr.SelectBuilder, error) {
ta, err := TableCollection.Structure(TableIndexAttribute)
if err != nil {
return nil, log.Error("eav.GetAttributeSelectSql.TableCollection.Structure", "err", err, "entityTypeID", entityTypeID, "websiteID", websiteID)
}
taa, err := aat.TableAdditionalAttribute()
if err != nil {
return nil, log.Error("eav.GetAttributeSelectSql.TableAdditionalAttribute", "err", err, "ta", ta, "entityTypeID", entityTypeID, "websiteID", websiteID)
}
tew, err := aat.TableEavWebsite()
if err != nil {
return nil, log.Error("eav.GetAttributeSelectSql.TableEavWebsite", "err", err, "ta", ta, "taa", taa, "entityTypeID", entityTypeID, "websiteID", websiteID)
}
// tew table can now contains columns names which can occur in table eav_attribute and
// or [catalog|customer|entity]_eav_attribute
var (
ifnull []string
tewAddedCols []string
taColumnsQuoted = utils.StringSlice(ta.AllColumnAliasQuote(csdb.MainTable))
taaColumnsQuoted = utils.StringSlice(taa.ColumnAliasQuote(csdb.AdditionalTable))
)
if tew != nil {
ifnull = make([]string, len(tew.Columns))
for i, tewC := range tew.Columns.ColumnsNoPK().FieldNames() {
t := ""
switch {
case ta.In(tewC):
t = csdb.MainTable
break
case taa.In(tewC):
t = csdb.AdditionalTable
break
default:
return nil, log.Error("eav.GetAttributeSelectSql.Columns.FieldNames.default", "err",
fmt.Errorf("Cannot find column name %s.%s neither in table %s nor in %s.", tew.Name, tewC, ta.Name, taa.Name),
"ta", ta, "taa", taa,
"entityTypeID", entityTypeID, "websiteID", websiteID)
}
ifnull[i] = dbr.IfNullAs(csdb.ScopeTable, tewC, t, tewC, tewC)
tewAddedCols = append(tewAddedCols, tewC)
}
taColumnsQuoted.ReduceContains(tewAddedCols...)
taaColumnsQuoted.ReduceContains(tewAddedCols...)
}
selectSql := dbrSess.
Select(taColumnsQuoted...).
From(ta.Name, csdb.MainTable).
Join(
dbr.JoinTable(taa.Name, csdb.AdditionalTable),
taaColumnsQuoted,
dbr.JoinOn(dbr.Quote+csdb.AdditionalTable+"`.`attribute_id` = `"+csdb.MainTable+"`.`attribute_id`"),
dbr.JoinOn(dbr.Quote+csdb.MainTable+"`.`entity_type_id` = ?", entityTypeID),
)
if len(tewAddedCols) > 0 {
selectSql.
LeftJoin(
dbr.JoinTable(tew.Name, csdb.ScopeTable),
append(ifnull),
dbr.JoinOn(dbr.Quote+csdb.ScopeTable+dbr.Quote+"."+dbr.Quote+"attribute_id"+dbr.Quote+" = "+dbr.Quote+csdb.MainTable+dbr.Quote+"."+dbr.Quote+"attribute_id"+dbr.Quote),
dbr.JoinOn(dbr.Quote+csdb.ScopeTable+dbr.Quote+"."+dbr.Quote+"website_id"+dbr.Quote+" = ?", websiteID),
)
}
return selectSql, nil
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:72,代码来源:attribute_sql.go
注:本文中的github.com/corestoreio/csfw/storage/dbr.SessionRunner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论