当前位置: 首页>>代码示例>>Golang>>正文


Golang Transaction.List方法代码示例

本文整理汇总了Golang中github.com/cloudwan/gohan/db/transaction.Transaction.List方法的典型用法代码示例。如果您正苦于以下问题:Golang Transaction.List方法的具体用法?Golang Transaction.List怎么用?Golang Transaction.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudwan/gohan/db/transaction.Transaction的用法示例。


在下文中一共展示了Transaction.List方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: clearTable

func clearTable(tx transaction.Transaction, s *schema.Schema) error {
	if s.IsAbstract() {
		return nil
	}
	for _, schema := range schema.GetManager().Schemas() {
		if schema.ParentSchema == s {
			err := clearTable(tx, schema)
			if err != nil {
				return err
			}
		} else {
			for _, property := range schema.Properties {
				if property.Relation == s.Singular {
					err := clearTable(tx, schema)
					if err != nil {
						return err
					}
				}
			}
		}
	}
	resources, _, err := tx.List(s, nil, nil)
	if err != nil {
		return err
	}
	for _, resource := range resources {
		err = tx.Delete(s, resource.ID())
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:33,代码来源:server_test.go

示例2: DBList

//DBList lists data from database.
func DBList(tx transaction.Transaction, schemaID string, filter map[string]interface{}) ([]interface{}, error) {
	manager := schema.GetManager()
	schemaObj, ok := manager.Schema(schemaID)
	if !ok {
		return nil, fmt.Errorf("Schema %s not found", schemaID)
	}
	for key, value := range filter {
		switch v := value.(type) {
		case string:
			filter[key] = []string{v}
		case bool:
			filter[key] = []string{fmt.Sprintf("%v", v)}
		case int:
			filter[key] = []string{fmt.Sprintf("%v", v)}
		case []interface{}:
			filterList := make([]string, len(v))
			for _, item := range v {
				filterList = append(filterList, fmt.Sprintf("%v", item))
			}
			filter[key] = filterList
		}
	}
	resources, _, err := tx.List(schemaObj, filter, nil)
	resp := []interface{}{}
	for _, resource := range resources {
		resp = append(resp, resource.Data())
	}
	return resp, err
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:30,代码来源:gohan.go

示例3: GohanDbList

//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
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:28,代码来源:gohan_db.go

示例4: clearTable

func clearTable(tx transaction.Transaction, s *schema.Schema) error {
	for _, schema := range schema.GetManager().Schemas() {
		if schema.ParentSchema == s {
			err := clearTable(tx, schema)
			if err != nil {
				return err
			}
		}
	}
	resources, _, err := tx.List(s, nil, nil)
	if err != nil {
		return err
	}
	for _, resource := range resources {
		err = tx.Delete(s, resource.ID())
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:21,代码来源:otto_suite_test.go

示例5:

		})

		Describe("Using sql", func() {
			BeforeEach(func() {
				if os.Getenv("MYSQL_TEST") == "true" {
					conn = "[email protected]/gohan_test"
					dbType = "mysql"
				} else {
					conn = "./test.db"
					dbType = "sqlite3"
				}
			})

			Context("When the database is empty", func() {
				It("Returns an empty list", func() {
					list, num, err := tx.List(networkSchema, nil, nil)
					Expect(err).ToNot(HaveOccurred())
					Expect(num).To(Equal(uint64(0)))
					Expect(list).To(BeEmpty())
					Expect(tx.Commit()).To(Succeed())
				})

				It("Creates a resource", func() {
					Expect(tx.Create(networkResource1)).To(Succeed())

					Expect(tx.Commit()).To(Succeed())
				})
			})

			Describe("When the database is not empty", func() {
				JustBeforeEach(func() {
开发者ID:vozhyk-,项目名称:gohan,代码行数:31,代码来源:db_test.go

示例6:

		})

		Describe("Using sql", func() {
			BeforeEach(func() {
				if os.Getenv("MYSQL_TEST") == "true" {
					conn = "[email protected]/gohan_test"
					dbType = "mysql"
				} else {
					conn = "./test.db"
					dbType = "sqlite3"
				}
			})

			Context("When the database is empty", func() {
				It("Returns an empty list", func() {
					list, num, err := tx.List(networkSchema, nil, nil)
					Expect(err).ToNot(HaveOccurred())
					Expect(num).To(Equal(uint64(0)))
					Expect(list).To(BeEmpty())
					Expect(tx.Commit()).To(Succeed())
				})

				It("Creates a resource", func() {
					Expect(tx.Create(networkResource)).To(Succeed())
					Expect(tx.Commit()).To(Succeed())
				})
			})

			Describe("When the database is not empty", func() {
				JustBeforeEach(func() {
					Expect(tx.Create(networkResource)).To(Succeed())
开发者ID:masaki-saeki,项目名称:gohan,代码行数:31,代码来源:db_test.go


注:本文中的github.com/cloudwan/gohan/db/transaction.Transaction.List方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。