本文整理汇总了Golang中github.com/theduke/go-dukedb.Backend类的典型用法代码示例。如果您正苦于以下问题:Golang Backend类的具体用法?Golang Backend怎么用?Golang Backend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Backend类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetBackend
func (r *Runner) SetBackend(backend db.Backend) {
r.backend = backend
if backend != nil && r.taskModel != nil && !backend.HasCollection(r.taskModel.Collection()) {
backend.RegisterModel(r.taskModel)
}
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:7,代码来源:runner.go
示例2: BeforeDelete
func (p PageIntId) BeforeDelete(b db.Backend) error {
// Delete tags.
m2m, _ := b.M2M(p, "Tags")
if err := m2m.Clear(); err != nil {
return err
}
if p.MenuItemId != 0 {
if err := b.Q("menu_items").Filter("id", p.MenuItemId).Delete(); err != nil {
return err
}
}
return nil
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:15,代码来源:models.go
示例3: NewService
func NewService(reg kit.Registry, b db.Backend) *Service {
var model kit.Model
if b.HasStringIds() {
model = &TaskStrId{}
} else {
model = &TaskIntId{}
}
s := &Service{}
runner := NewRunner(reg, b, model)
s.Runner = *runner
return s
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:15,代码来源:service.go
示例4: RegisterBackend
func (a *App) RegisterBackend(b db.Backend) {
if b.Logger() == nil {
b.SetLogger(a.Logger())
}
isDefault := a.DefaultBackend() == nil
a.registry.AddBackend(b)
// If no backend was registered before, create a default UserService and FileService.
if isDefault && a.defaults {
if a.UserService() == nil {
a.BuildDefaultUserService(b)
}
if a.FileService() == nil {
a.BuildDefaultFileService(b)
}
if a.registry.TaskService() == nil {
a.BuildDefaultTaskService(b)
}
}
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:21,代码来源:app.go
示例5: SetBackend
func (res *Resource) SetBackend(b db.Backend) {
res.backend = b
if !b.HasCollection(res.Collection()) {
b.RegisterModel(res.Model())
}
res.modelInfo = b.ModelInfo(res.Collection())
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:8,代码来源:resource.go
示例6: SetBackend
func (a *AuthAdaptorPassword) SetBackend(b db.Backend) {
b.RegisterModel(&AuthItemPassword{})
a.backend = b
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:4,代码来源:password.go
示例7: TestBackend
func TestBackend(skipFlag *bool, backendBuilder func() (db.Backend, apperror.Error)) {
doSkip := false
var backend db.Backend
BeforeEach(func() {
if *skipFlag || doSkip {
Skip("Skipping due to previous error.")
}
var err apperror.Error
backend, err = backendBuilder()
Expect(err).ToNot(HaveOccurred())
backend.SetDebug(true)
backend.RegisterModel(&Tag{})
backend.RegisterModel(&Project{})
backend.RegisterModel(&Task{})
backend.RegisterModel(&File{})
backend.RegisterModel(&TestModel{})
backend.RegisterModel(&TestParent{})
backend.RegisterModel(&HooksModel{})
backend.RegisterModel(&ValidationsModel{})
backend.RegisterModel(&MarshalledModel{})
backend.Build()
})
It("Should drop all collections", func() {
doSkip = true
err := backend.DropAllCollections()
Expect(err).ToNot(HaveOccurred())
doSkip = false
})
It("Should create collections", func() {
doSkip = true
err := backend.CreateCollection(
"test_models",
"test_parents",
"hooks_models",
"validations_models",
"marshalled_models",
"tags",
"projects",
"tasks",
"files",
)
Expect(err).ToNot(HaveOccurred())
doSkip = false
})
It("Should count with zero entries", func() {
Expect(backend.Q("test_models").Count()).To(Equal(0))
})
It("Should insert and set Id, then FindOne()", func() {
testModel := NewTestModel(1)
testModel.Id = 0
err := backend.Create(&testModel)
Expect(err).ToNot(HaveOccurred())
Expect(testModel.Id).ToNot(Equal(0))
m, err := backend.FindOne("test_models", testModel.Id)
Expect(err).ToNot(HaveOccurred())
Expect(*m.(*TestModel)).To(Equal(testModel))
})
It("Should count with 1 entry", func() {
Expect(backend.Create(&Project{Name: "Test"})).ToNot(HaveOccurred())
Expect(backend.Q("projects").Count()).To(Equal(1))
})
It("Should update", func() {
// Persist model to update.
testModel := NewTestModel(2)
err := backend.Create(&testModel)
Expect(err).ToNot(HaveOccurred())
testModel.IntVal = 33
testModel.StrVal = "str33"
err = backend.Update(&testModel)
Expect(err).ToNot(HaveOccurred())
m, err := backend.FindOne("test_models", testModel.Id)
Expect(err).ToNot(HaveOccurred())
Expect(m).To(Equal(&testModel))
})
It("Should delete", func() {
// Persist model to update.
testModel := NewTestModel(3)
err := backend.Create(&testModel)
Expect(err).ToNot(HaveOccurred())
err = backend.Delete(&testModel)
Expect(err).ToNot(HaveOccurred())
m, err := backend.FindOne("test_models", testModel.Id)
//.........这里部分代码省略.........
开发者ID:theduke,项目名称:go-dukedb,代码行数:101,代码来源:tests.go
示例8: AddBackend
func (d *Registry) AddBackend(b db.Backend) {
d.backends[b.Name()] = b
if d.defaultBackend == nil {
d.defaultBackend = b
}
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:6,代码来源:registry.go
示例9: SetBackend
func (s *Service) SetBackend(b db.Backend) {
s.Users.SetBackend(b)
b.RegisterModel(s.Users.Model())
if s.Profiles != nil {
s.Profiles.SetBackend(b)
b.RegisterModel(s.Profiles.Model())
}
s.Sessions.SetBackend(b)
b.RegisterModel(s.Sessions.Model())
s.Tokens.SetBackend(b)
b.RegisterModel(s.Tokens.Model())
s.Roles.SetBackend(b)
b.RegisterModel(s.Roles.Model())
s.Permissions.SetBackend(b)
b.RegisterModel(s.Permissions.Model())
for name := range s.AuthAdaptors {
s.AuthAdaptors[name].SetBackend(b)
}
s.backend = b
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:27,代码来源:service.go
示例10: SerializeModel
func SerializeModel(backend db.Backend, m kit.Model) (*ApiModel, []*ApiModel, apperror.Error) {
modelData, err := backend.ModelToMap(m, true, false)
if err != nil {
return nil, nil, apperror.Wrap(err, "model_convert_error", "")
}
info := backend.ModelInfo(m.Collection())
data := &ApiModel{
Type: m.Collection(),
Id: m.GetStrId(),
Attributes: modelData,
}
// Build relationship data.
includedModels := make([]*ApiModel, 0)
// Check every model field.
r := reflector.R(m).MustStruct()
for fieldName, rel := range info.Relations() {
// Retrieve the related model.
field := r.Field(fieldName)
if field != nil {
return nil, nil, apperror.Wrap(err, "model_get_field_error")
}
// If field is zero value, skip.
if field.IsZero() {
continue
}
related := make([]kit.Model, 0)
if !rel.IsMany() {
// Make sure that we have a pointer.
if !field.IsPtr() {
field = field.Addr()
}
related = append(related, field.Interface().(kit.Model))
} else {
slice := field.MustSlice()
for _, item := range slice.Items() {
if !item.IsPtr() {
item = item.Addr()
}
related = append(related, item.Interface().(kit.Model))
}
}
for _, relatedModel := range related {
// Convert the related model.
relationData, included, err := SerializeModel(backend, relatedModel)
if err != nil {
return nil, nil, apperror.Wrap(err, "included_model_serialize_error", "")
}
// Build relation info and set in in relationships map.
relation := &ApiModel{
Type: relatedModel.Collection(),
Id: relatedModel.GetStrId(),
}
isSingle := !rel.IsMany()
data.AddRelation(rel.MarshalName(), relation, isSingle)
// Add related model to included data.
includedModels = append(includedModels, relationData)
// Add nested included models to included data.
includedModels = append(includedModels, included...)
}
}
return data, includedModels, nil
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:76,代码来源:jsonapi.go
示例11: SetBackend
func (item *AuthAdaptorOauth) SetBackend(b db.Backend) {
b.RegisterModel(&AuthItemOauth{})
item.backend = b
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:4,代码来源:oauth.go
注:本文中的github.com/theduke/go-dukedb.Backend类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论