本文整理匯總了Golang中github.com/corestoreio/csfw/storage/dbr.Session類的典型用法代碼示例。如果您正苦於以下問題:Golang Session類的具體用法?Golang Session怎麽用?Golang Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Session類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoadByCode
func (et *TableEntityType) LoadByCode(dbrSess *dbr.Session, code string, cbs ...csdb.DbrSelectCb) error {
s, err := TableCollection.Structure(TableIndexEntityType)
if err != nil {
return errgo.Mask(err)
}
sb := dbrSess.Select(s.AllColumnAliasQuote(csdb.MainTable)...).From(s.Name, csdb.MainTable).Where("entity_type_code = ?", code)
for _, cb := range cbs {
sb = cb(sb)
}
return errgo.Mask(sb.LoadStruct(et))
}
示例2: InitEntityStoreMap
func InitEntityStoreMap(dbrSess *dbr.Session) error {
if atomic.LoadUint32(&initMapDone.done) == 1 {
return ErrStoreMapInitialized
}
initMapDone.m.Lock()
defer initMapDone.m.Unlock()
if initMapDone.done == 0 {
defer atomic.StoreUint32(&initMapDone.done, 1)
s, err := TableCollection.Structure(TableIndexEntityStore)
if err != nil {
return errgo.Mask(err)
}
var ess TableEntityStoreSlice
_, err = dbrSess.
Select(s.Columns.FieldNames()...).
From(s.Name).
LoadStructs(&ess)
if err != nil {
return errgo.Mask(err)
}
for _, es := range ess {
EntityStoreMap.Set(es.EntityTypeID, es.StoreID, es)
}
ess = ess[:len(ess)-1] // delete Struct Slice https://code.google.com/p/go-wiki/wiki/SliceTricks
return nil
}
return ErrStoreMapInitialized
}
示例3: getEntityTypeData
// getEntityTypeData retrieves all EAV models from table eav_entity_type but only those listed in variable
// codegen.ConfigEntityType. It then applies the mapping data from codegen.ConfigEntityType to the entity_type struct.
// Depends on generated code from tableToStruct.
func getEntityTypeData(dbrSess *dbr.Session) (etc eav.TableEntityTypeSlice, err error) {
s, err := eav.TableCollection.Structure(eav.TableIndexEntityType)
if err != nil {
return nil, errgo.Mask(err)
}
_, err = dbrSess.
Select(s.AllColumnAliasQuote(s.Name)...).
From(s.Name).
Where("entity_type_code IN ?", codegen.ConfigEntityType.Keys()).
LoadStructs(&etc)
if err != nil {
return nil, errgo.Mask(err)
}
for typeCode, mapData := range codegen.ConfigEntityType {
// map the fields from the config struct to the data retrieved from the database.
et, err := etc.GetByCode(typeCode)
codegen.LogFatal(err)
et.EntityModel = codegen.ParseString(mapData.EntityModel, et)
et.AttributeModel.String = codegen.ParseString(mapData.AttributeModel, et)
et.EntityTable.String = codegen.ParseString(mapData.EntityTable, et)
et.IncrementModel.String = codegen.ParseString(mapData.IncrementModel, et)
et.AdditionalAttributeTable.String = codegen.ParseString(mapData.AdditionalAttributeTable, et)
et.EntityAttributeCollection.String = codegen.ParseString(mapData.EntityAttributeCollection, et)
}
return etc, nil
}