當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Transaction.Query方法代碼示例

本文整理匯總了Golang中github.com/cloudwan/gohan/db/transaction.Transaction.Query方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transaction.Query方法的具體用法?Golang Transaction.Query怎麽用?Golang Transaction.Query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudwan/gohan/db/transaction.Transaction的用法示例。


在下文中一共展示了Transaction.Query方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: 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

示例3:

		BeforeEach(func() {
			manager := schema.GetManager()
			var ok bool
			s, ok = manager.Schema("test")
			Expect(ok).To(BeTrue())
		})

		Context("Without place holders", func() {
			It("Returns resources", func() {
				query := fmt.Sprintf(
					"SELECT %s FROM %s",
					strings.Join(MakeColumns(s, s.GetDbTableName(), false), ", "),
					s.GetDbTableName(),
				)
				results, err := tx.Query(s, query, []interface{}{})
				Expect(err).ToNot(HaveOccurred())
				Expect(results[0].Get("tenant_id")).To(Equal("tenant0"))
				Expect(results[0].Get("test_string")).To(Equal("obj0"))
				Expect(results[2].Get("tenant_id")).To(Equal("tenant1"))
				Expect(results[2].Get("test_string")).To(Equal("obj2"))
				Expect(len(results)).To(Equal(4))
			})
		})

		Context("With a place holder", func() {
			It("Replace the place holder and returns resources", func() {
				query := fmt.Sprintf(
					"SELECT %s FROM %s WHERE tenant_id = ?",
					strings.Join(MakeColumns(s, s.GetDbTableName(), false), ", "),
					s.GetDbTableName(),
開發者ID:cloudwan,項目名稱:gohan,代碼行數:30,代碼來源:sql_test.go


注:本文中的github.com/cloudwan/gohan/db/transaction.Transaction.Query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。