本文整理汇总了Golang中github.com/theduke/go-dukedb.Backend.HasCollection方法的典型用法代码示例。如果您正苦于以下问题:Golang Backend.HasCollection方法的具体用法?Golang Backend.HasCollection怎么用?Golang Backend.HasCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/theduke/go-dukedb.Backend
的用法示例。
在下文中一共展示了Backend.HasCollection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
示例2: 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())
}
示例3: TestBackend
//.........这里部分代码省略.........
tags[0].Tag = "X1"
tags[1].Tag = "X2"
t := &Task{
Name: "test",
Tags: []Tag{tags[0], tags[1]},
}
Expect(backend.Create(t)).ToNot(HaveOccurred())
col, _ := backend.M2M(t, "Tags")
all, err := col.All()
Expect(err).ToNot(HaveOccurred())
Expect(all).To(HaveLen(2))
Expect(all[0].(*Tag).Tag).To(Equal("X1"))
Expect(all[1].(*Tag).Tag).To(Equal("X2"))
})
It("Should auto-delete m2m", func() {
rel := backend.ModelInfo("tasks").Relation("Tags")
rel.SetAutoDelete(true)
tags := []Tag{Tag{Tag: "T1"}, {Tag: "T2"}, {Tag: "T3"}, {Tag: "T4"}}
Expect(backend.Create(&tags[0], &tags[1], &tags[2], &tags[3])).ToNot(HaveOccurred())
t := &Task{
Name: "test",
Tags: []Tag{tags[0], tags[1]},
}
Expect(backend.Create(t)).ToNot(HaveOccurred())
Expect(backend.Delete(t)).ToNot(HaveOccurred())
// If a m2m collection exists, check that is was cleared properly.
if backend.HasCollection("tasks_tags") {
q := backend.Q("tasks_tags").Filter("tasks.id", t.Id)
Expect(q.Count()).To(Equal(0))
}
})
It("Should join m2m", func() {
rel := backend.ModelInfo("tasks").Relation("Tags")
rel.SetAutoDelete(true)
tags := []Tag{Tag{Tag: "T1"}, {Tag: "T2"}, {Tag: "T3"}, {Tag: "T4"}}
Expect(backend.Create(&tags[0], &tags[1], &tags[2], &tags[3])).ToNot(HaveOccurred())
t := &Task{
Name: "test",
Tags: []Tag{tags[0], tags[1]},
}
Expect(backend.Create(t)).ToNot(HaveOccurred())
m, err := backend.Q("tasks").Filter("id", t.Id).Join("Tags").First()
Expect(err).ToNot(HaveOccurred())
taskTags := m.(*Task).Tags
Expect(taskTags).To(HaveLen(2))
})
It("Should .Related() with model", func() {
rel := backend.ModelInfo("tasks").Relation("Tags")
rel.SetAutoDelete(true)
tags := []Tag{Tag{Tag: "T1"}, {Tag: "T2"}, {Tag: "T3"}, {Tag: "T4"}}
Expect(backend.Create(&tags[0], &tags[1], &tags[2], &tags[3])).ToNot(HaveOccurred())