本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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() {
示例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())