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