本文整理汇总了Golang中github.com/cloudwan/gohan/db/transaction.Transaction类的典型用法代码示例。如果您正苦于以下问题:Golang Transaction类的具体用法?Golang Transaction怎么用?Golang Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: DBDelete
//DBDelete deletes a resource in a db.
func DBDelete(tx transaction.Transaction, schemaID string, id string) error {
manager := schema.GetManager()
schemaObj, ok := manager.Schema(schemaID)
if !ok {
return fmt.Errorf("Schema %s not found", schemaID)
}
return tx.Delete(schemaObj, id)
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:9,代码来源:gohan.go
示例4: DBUpdate
//DBUpdate updates a resource in a db.
func DBUpdate(tx transaction.Transaction, schemaID string, data map[string]interface{}) error {
manager := schema.GetManager()
resource, err := manager.LoadResource(schemaID, data)
if err != nil {
return err
}
return tx.Update(resource)
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:9,代码来源:gohan.go
示例5: DBQuery
//DBQuery fetchs data from db with additional query
func DBQuery(tx transaction.Transaction, schemaID string, sql string, arguments []interface{}) ([]interface{}, error) {
manager := schema.GetManager()
schemaObj, ok := manager.Schema(schemaID)
if !ok {
return nil, fmt.Errorf("Schema %s not found", schemaID)
}
resources, err := tx.Query(schemaObj, sql, arguments)
resp := []interface{}{}
for _, resource := range resources {
resp = append(resp, resource.Data())
}
return resp, err
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:14,代码来源:gohan.go
示例6: DBGet
//DBGet get resource from a db.
func DBGet(tx transaction.Transaction, schemaID string, id string, tenantID string) (map[string]interface{}, error) {
manager := schema.GetManager()
schemaObj, ok := manager.Schema(schemaID)
if !ok {
return nil, fmt.Errorf("Schema %s not found", schemaID)
}
var tenantFilter []string
if tenantID != "" {
tenantFilter = []string{tenantID}
}
resp, err := tx.Fetch(schemaObj, id, tenantFilter)
if err != nil {
return nil, err
}
return resp.Data(), err
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:17,代码来源:gohan.go
示例7: GohanDbDelete
//GohanDbDelete deletes resource from database
func GohanDbDelete(transaction transaction.Transaction, needCommit bool, schemaID, ID string) error {
schema, err := getSchema(schemaID)
if err != nil {
return fmt.Errorf("Error during gohan_db_delete: %s", err.Error())
}
if err := transaction.Delete(schema, ID); err != nil {
return fmt.Errorf("Error during gohan_db_delete: %s", err.Error())
}
if needCommit {
err := transaction.Commit()
if err != nil {
return fmt.Errorf("Error during gohan_db_delete: %s", err.Error())
}
}
return nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:17,代码来源:gohan_db.go
示例8: 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
示例9: GohanDbFetch
//GohanDbFetch gets resource from database
func GohanDbFetch(tx transaction.Transaction, schemaID, ID,
tenantID string) (*schema.Resource, error) {
schema, err := getSchema(schemaID)
if err != nil {
return nil, err
}
filter := transaction.IDFilter(ID)
if tenantID != "" {
filter["tenant_id"] = tenantID
}
resp, err := tx.Fetch(schema, filter)
if err != nil {
return nil, fmt.Errorf("Error during gohan_db_fetch: %s", err.Error())
}
return resp, nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:18,代码来源:gohan_db.go
示例10: GohanDbStateUpdate
//GohanDbStateUpdate updates resource's state in database
func GohanDbStateUpdate(transaction transaction.Transaction, needCommit bool, schemaID string,
dataMap map[string]interface{}) (*schema.Resource, error) {
manager := schema.GetManager()
resource, err := manager.LoadResource(schemaID, dataMap)
if err != nil {
return nil, fmt.Errorf("Error during gohan_db_state_update: %s", err.Error())
}
if err = transaction.StateUpdate(resource, nil); err != nil {
return nil, fmt.Errorf("Error during gohan_db_state_update: %s", err.Error())
}
if needCommit {
err = transaction.Commit()
if err != nil {
return nil, fmt.Errorf("Error during gohan_db_state_update: %s", err.Error())
}
}
return resource, nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:20,代码来源:gohan_db.go
示例11: 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
示例12: GohanDbQuery
//GohanDbQuery get resources from database with query
func GohanDbQuery(transaction transaction.Transaction, needCommit bool, schemaID,
sqlString string, arguments []interface{}) ([]map[string]interface{}, error) {
schema, err := getSchema(schemaID)
if err != nil {
return []map[string]interface{}{}, err
}
resources, err := transaction.Query(schema, sqlString, arguments)
if err != nil {
return []map[string]interface{}{}, fmt.Errorf("Error during gohan_db_query: %s", err.Error())
}
if needCommit {
err = transaction.Commit()
if err != nil {
return []map[string]interface{}{}, fmt.Errorf("Error during gohan_db_query: %s", err.Error())
}
}
resp := []map[string]interface{}{}
for _, resource := range resources {
resp = append(resp, resource.Data())
}
return resp, nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:24,代码来源:gohan_db.go
示例13: GohanDbStateFetch
//GohanDbStateFetch gets resource's state from database
func GohanDbStateFetch(tx transaction.Transaction, schemaID, ID,
tenantID string) (map[string]interface{}, error) {
schema, err := getSchema(schemaID)
if err != nil {
return map[string]interface{}{}, err
}
filter := transaction.IDFilter(ID)
if tenantID != "" {
filter["tenant_id"] = tenantID
}
resp, err := tx.StateFetch(schema, filter)
if err != nil {
return map[string]interface{}{}, fmt.Errorf("Error during gohan_db_state_fetch: %s", err.Error())
}
data := map[string]interface{}{
"config_version": resp.ConfigVersion,
"state_version": resp.StateVersion,
"error": resp.Error,
"state": resp.State,
"monitoring": resp.Monitoring,
}
return data, nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:25,代码来源:gohan_db.go
示例14: GohanDbFetch
//GohanDbFetch gets resource from database
func GohanDbFetch(transaction transaction.Transaction, schemaID, ID,
tenantID string) (*schema.Resource, error) {
schema, err := getSchema(schemaID)
if err != nil {
return nil, err
}
var tenantFilter []string
if tenantID != "" {
tenantFilter = []string{tenantID}
}
resp, err := transaction.Fetch(schema, ID, tenantFilter)
if err != nil {
return nil, fmt.Errorf("Error during gohan_db_fetch: %s", err.Error())
}
return resp, nil
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:18,代码来源:gohan_db.go
示例15:
"os"
"strings"
"github.com/cloudwan/gohan/db"
. "github.com/cloudwan/gohan/db/sql"
"github.com/cloudwan/gohan/db/transaction"
"github.com/cloudwan/gohan/schema"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Sql", func() {
var conn string
var tx transaction.Transaction
var sqlConn *DB
BeforeEach(func() {
var dbType string
if os.Getenv("MYSQL_TEST") == "true" {
conn = "gohan:[email protected]/gohan_test"
dbType = "mysql"
} else {
conn = "./test.db"
dbType = "sqlite3"
}
manager := schema.GetManager()
dbc, err := db.ConnectDB(dbType, conn, db.DefaultMaxOpenConn)
sqlConn = dbc.(*DB)
开发者ID:cloudwan,项目名称:gohan,代码行数:31,代码来源:sql_test.go
示例16:
BeforeEach(func() {
manager = schema.GetManager()
Expect(manager.LoadSchemaFromFile("../etc/schema/gohan.json")).To(Succeed())
})
AfterEach(func() {
schema.ClearManager()
if os.Getenv("MYSQL_TEST") != "true" {
os.Remove(conn)
}
})
Describe("Base operations", func() {
var (
tx transaction.Transaction
)
BeforeEach(func() {
Expect(manager.LoadSchemaFromFile("../tests/test_abstract_schema.yaml")).To(Succeed())
Expect(manager.LoadSchemaFromFile("../tests/test_schema.yaml")).To(Succeed())
networkSchema, ok = manager.Schema("network")
Expect(ok).To(BeTrue())
_, ok = manager.Schema("subnet")
Expect(ok).To(BeTrue())
serverSchema, ok = manager.Schema("server")
Expect(ok).To(BeTrue())
network1 := map[string]interface{}{
"id": "networkRed",
"name": "NetworkRed",
开发者ID:vozhyk-,项目名称:gohan,代码行数:30,代码来源:db_test.go
示例17: DBClose
//DBClose closes a transaction.
func DBClose(tx transaction.Transaction) error {
return tx.Close()
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:4,代码来源:gohan.go
示例18: DBExec
//DBExec closes a transaction.
func DBExec(tx transaction.Transaction, sql string, arguments []interface{}) error {
return tx.Exec(sql, arguments...)
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:4,代码来源:gohan.go
示例19:
}
Expect(env.HandleEvent("test_event", context)).To(Succeed())
Expect(context["network"]).ToNot(BeNil())
Expect(context["networks"]).ToNot(BeNil())
})
})
})
Describe("Using chaining builtins", func() {
BeforeEach(func() {
schemaID = "network"
})
Describe("Using gohan_model_list", func() {
var (
tx transaction.Transaction
)
BeforeEach(func() {
resource, err := manager.LoadResource(schemaID, network1)
Expect(err).NotTo(HaveOccurred())
tx, err = testDB.Begin()
Expect(err).NotTo(HaveOccurred())
defer tx.Close()
Expect(tx.Create(resource)).To(Succeed())
Expect(tx.Commit()).To(Succeed())
action = "read"
})
Describe("When invoked correctly", func() {
开发者ID:nati,项目名称:gohan,代码行数:31,代码来源:otto_test.go
示例20: DBCommit
//DBCommit commits transaction
func DBCommit(tx transaction.Transaction) error {
return tx.Commit()
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:4,代码来源:gohan.go
注:本文中的github.com/cloudwan/gohan/db/transaction.Transaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论