Пример #1
0
//The first result of the query is put in the passed struct.
//Returns true if a result was found, false if no result
func (this *Query) SelectTo(instance interface{}) (bool, error) {
	res, err := this.selectTransformer(NewEntityTransformer(this, instance))
	if err != nil {
		return false, err
	}
	if res != nil {
		tk.Set(instance, res)
		return true, nil
	}
	// remove previous marks
	if t, ok := instance.(Markable); ok {
		t.Unmark()
	}
	return false, nil
}
Пример #2
0
//Executes the query and builds a struct tree putting the first element in the supplied struct pointer.
//
//If the reuse parameter is true, when a
//new entity is needed, the cache is checked to see if there is one instance for this entity,
//and if found it will use it to build the tree. Because of this the supplied instance
//must implement the toolkit.Hasher interface.
//
//If the reuse parameter is false, each element of the tree is always a new instance
//even if representing the same entity. This is most useful for tabular results.
//Since there is no need for caching the entities it is not mandatory to implement
//the toolkit.Hasher interface.
//
//The first result of the query is put in the passed struct.
//Returns true if a result was found, false if no result
func (this *Query) selectTreeTo(instance interface{}, reuse bool) (bool, error) {
	res, err := this.selectTree(instance, reuse)
	if err != nil {
		return false, err
	}
	if res != nil {
		tk.Set(instance, res)
		return true, nil
	}
	// remove previous marks
	if t, ok := instance.(Markable); ok {
		t.Unmark()
	}
	return false, nil
}