Exemple #1
0
//GohanDbList lists resources in database filtered by filter and paginator
func GohanDbList(transaction transaction.Transaction, schemaID string,
	filter map[string]interface{}, key string, limit uint64, offset uint64) ([]map[string]interface{}, error) {

	schema, err := getSchema(schemaID)
	if err != nil {
		return []map[string]interface{}{}, err
	}

	var paginator *pagination.Paginator
	if key != "" {
		paginator, err = pagination.NewPaginator(schema, key, "", limit, offset)
		if err != nil {
			return []map[string]interface{}{}, fmt.Errorf("Error during gohan_db_list: %s", err.Error())
		}
	}

	resources, _, err := transaction.List(schema, filter, paginator)
	if err != nil {
		return []map[string]interface{}{}, fmt.Errorf("Error during gohan_db_list: %s", err.Error())
	}

	resp := []map[string]interface{}{}
	for _, resource := range resources {
		resp = append(resp, resource.Data())
	}
	return resp, nil
}
Exemple #2
0
func (server *Server) listEvents() ([]*schema.Resource, error) {
	tx, err := server.db.Begin()
	if err != nil {
		return nil, err
	}
	defer tx.Close()
	schemaManager := schema.GetManager()
	eventSchema, _ := schemaManager.Schema("event")
	paginator, _ := pagination.NewPaginator(eventSchema, "id", pagination.ASC, eventPollingLimit, 0)
	resourceList, _, err := tx.List(eventSchema, nil, paginator)
	if err != nil {
		return nil, err
	}
	return resourceList, nil
}