當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。