本文整理汇总了Golang中github.com/theduke/go-dukedb.Backend.FindBy方法的典型用法代码示例。如果您正苦于以下问题:Golang Backend.FindBy方法的具体用法?Golang Backend.FindBy怎么用?Golang Backend.FindBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/theduke/go-dukedb.Backend
的用法示例。
在下文中一共展示了Backend.FindBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBackend
//.........这里部分代码省略.........
m := NewTestModel(1)
m2 := NewTestModel(1)
m.IntVal = 71
m2.IntVal = 71
Expect(backend.Create(&m)).ToNot(HaveOccurred())
Expect(backend.Create(&m2)).ToNot(HaveOccurred())
res, err := backend.Last(backend.Q("test_models").Filter("int_val", 71))
Expect(err).ToNot(HaveOccurred())
Expect(res).To(Equal(&m2))
})
It("Should .Last() with target model", func() {
m := NewTestModel(1)
Expect(backend.Create(&m)).ToNot(HaveOccurred())
var model TestModel
_, err := backend.Last(backend.Q("test_models").Filter("id", m.Id), &model)
Expect(err).ToNot(HaveOccurred())
Expect(model).To(Equal(m))
})
It("Should .Last() with target pointer", func() {
m := NewTestModel(1)
Expect(backend.Create(&m)).ToNot(HaveOccurred())
var model *TestModel
_, err := backend.Last(backend.Q("test_models").Filter("id", m.Id), &model)
Expect(err).ToNot(HaveOccurred())
Expect(model).To(Equal(&m))
})
It("Should .FindBy()", func() {
m := NewTestModel(1)
m2 := NewTestModel(1)
m.IntVal = 72
m2.IntVal = 72
Expect(backend.Create(&m)).ToNot(HaveOccurred())
Expect(backend.Create(&m2)).ToNot(HaveOccurred())
res, err := backend.FindBy("test_models", "int_val", 72)
Expect(err).ToNot(HaveOccurred())
Expect(len(res)).To(Equal(2))
Expect(res[0]).To(Equal(&m))
Expect(res[1]).To(Equal(&m2))
})
It("Should .FindBy() with target slice", func() {
m := NewTestModel(1)
m2 := NewTestModel(1)
m.IntVal = 73
m2.IntVal = 73
Expect(backend.Create(&m)).ToNot(HaveOccurred())
Expect(backend.Create(&m2)).ToNot(HaveOccurred())
var res []TestModel
_, err := backend.FindBy("test_models", "int_val", 73, &res)
Expect(err).ToNot(HaveOccurred())
Expect(len(res)).To(Equal(2))
Expect(res[0]).To(Equal(m))
Expect(res[1]).To(Equal(m2))