本文整理匯總了Golang中github.com/corestoreio/csfw/storage/dbr.SessionRunner.Select方法的典型用法代碼示例。如果您正苦於以下問題:Golang SessionRunner.Select方法的具體用法?Golang SessionRunner.Select怎麽用?Golang SessionRunner.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/corestoreio/csfw/storage/dbr.SessionRunner
的用法示例。
在下文中一共展示了SessionRunner.Select方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}