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


Golang transaction.Transaction类代码示例

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


在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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