本文整理汇总了Golang中github.com/theduke/go-dukedb.Backend.Query方法的典型用法代码示例。如果您正苦于以下问题:Golang Backend.Query方法的具体用法?Golang Backend.Query怎么用?Golang Backend.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/theduke/go-dukedb.Backend
的用法示例。
在下文中一共展示了Backend.Query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBackend
//.........这里部分代码省略.........
IntVal: 22,
StringVal: "test",
}
m := &MarshalledModel{
StructVal: data,
}
Expect(backend.Create(m)).ToNot(HaveOccurred())
rawModel, err := backend.FindOne("marshalled_models", m.Id)
Expect(err).ToNot(HaveOccurred())
Expect(rawModel.(*MarshalledModel).StructVal).To(Equal(data))
})
It("Should persist marshalled field with STRUCT POINTER and unmarshal on query", func() {
data := &MarshalledData{
IntVal: 22,
StringVal: "test",
}
m := &MarshalledModel{
StructPtrVal: data,
}
Expect(backend.Create(m)).ToNot(HaveOccurred())
rawModel, err := backend.FindOne("marshalled_models", m.Id)
Expect(err).ToNot(HaveOccurred())
Expect(rawModel.(*MarshalledModel).StructPtrVal).To(Equal(data))
})
})
Describe("Querying", func() {
It("Should filter with field backend name", func() {
model := NewTestModel(60)
Expect(backend.Create(&model)).ToNot(HaveOccurred())
m, err := backend.Q("test_models").Filter("int_val", 60).First()
Expect(err).ToNot(HaveOccurred())
Expect(m.(*TestModel).Id).To(Equal(model.Id))
})
It("Should filter with struct field name", func() {
model := NewTestModel(61)
Expect(backend.Create(&model)).ToNot(HaveOccurred())
m, err := backend.Q("test_models").Filter("IntVal", 61).First()
Expect(err).ToNot(HaveOccurred())
Expect(m.(*TestModel).Id).To(Equal(model.Id))
})
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