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


Golang cqlc.Context類代碼示例

本文整理匯總了Golang中github.com/relops/cqlc/cqlc.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: create

func create(ctx *cqlc.Context, s *gocql.Session, basic Basic) {

	err := ctx.Upsert(BASIC).
		SetString(BASIC.ID, basic.Id).
		SetInt32(BASIC.INT32_COLUMN, basic.Int32Column).
		SetInt64(BASIC.INT64_COLUMN, basic.Int64Column).
		SetFloat32(BASIC.FLOAT_COLUMN, basic.FloatColumn).
		SetFloat64(BASIC.DOUBLE_COLUMN, basic.DoubleColumn).
		SetString(BASIC.ASCII_COLUMN, basic.AsciiColumn).
		SetTimestamp(BASIC.TIMESTAMP_COLUMN, basic.TimestampColumn).
		SetUUID(BASIC.UUID_COLUMN, basic.UuidColumn).
		SetTimeUUID(BASIC.TIMEUUID_COLUMN, basic.TimeuuidColumn).
		SetBoolean(BASIC.BOOLEAN_COLUMN, basic.BooleanColumn).
		SetString(BASIC.TEXT_COLUMN, basic.TextColumn).
		SetString(BASIC.VARCHAR_COLUMN, basic.VarcharColumn).
		SetStringStringMap(BASIC.MAP_COLUMN, basic.MapColumn).
		SetStringSlice(BASIC.ARRAY_COLUMN, basic.ArrayColumn).
		SetStringSlice(BASIC.SET_COLUMN, basic.SetColumn).
		SetDecimal(BASIC.DECIMAL_COLUMN, basic.DecimalColumn).
		SetVarint(BASIC.VARINT_COLUMN, basic.VarintColumn).
		Exec(s)

	if err != nil {
		log.Fatalf("Could not execute query: %v", err)
		os.Exit(1)
	}
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:27,代碼來源:basic.go

示例2: expectComparisonResult

func expectComparisonResult(ctx *cqlc.Context,
	s *gocql.Session,
	callback func([]ClusterByStringAndInt) bool,
	comparisons ...cqlc.Condition) bool {

	iter, err := ctx.Select().
		From(CLUSTER_BY_STRING_AND_INT).
		Where(comparisons...).
		Fetch(s)

	if err != nil {
		log.Fatalf("Could not run query: %v", err)
		os.Exit(1)
	}

	clustered, err := BindClusterByStringAndInt(iter)
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}

	err = iter.Close()
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}

	return callback(clustered)
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:29,代碼來源:comparison.go

示例3: get

func get(s *gocql.Session, ctx *cqlc.Context, key string) (bool, string) {
	var value string

	found, err := ctx.Select(SHARED.VALUE).
		From(SHARED).
		Where(SHARED.ID.Eq("foo")).
		Bind(SHARED.VALUE.To(&value)).
		FetchOne(s)

	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}
	return found, value
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:15,代碼來源:keyspace.go

示例4: deleteByTimestamp

func deleteByTimestamp(ctx *cqlc.Context, s *gocql.Session, w WhenRowKey, t gocql.UUID) error {
	return ctx.
		Delete().
		From(w).
		Where(w.WhenColumn().Eq(t)).
		Exec(s)
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:7,代碼來源:composition.go

示例5: fetchOne

func fetchOne(ctx *cqlc.Context, s *gocql.Session, w WhenRowKey, t gocql.UUID, binding cqlc.ColumnBinding) (bool, error) {
	return ctx.
		Select().
		From(w).
		Where(w.WhenColumn().Eq(t)).
		Bind(binding).
		FetchOne(s)
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:8,代碼來源:composition.go

示例6: fetchFirstBasic

func fetchFirstBasic(ctx *cqlc.Context, s *gocql.Session, key string) *Basic {
	iter, err := ctx.Select().From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("x")).Fetch(s)

	basics, err := BindBasic(iter)
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}

	err = iter.Close()
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}

	if len(basics) > 0 {
		return &basics[0]
	} else {
		return nil
	}

}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:22,代碼來源:delete.go

示例7: fetchFirstReallyBasic

func fetchFirstReallyBasic(ctx *cqlc.Context, s *gocql.Session, key string) ReallyBasic {
	iter, err := ctx.Select().From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq(key)).Fetch(s)

	basics, err := BindReallyBasic(iter)
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}

	err = iter.Close()
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		os.Exit(1)
	}

	if len(basics) != 1 {
		log.Fatalf("Could not fetch data for key: %s", key)
		os.Exit(1)
	}

	return basics[0]

}
開發者ID:EverythingMe,項目名稱:cqlc,代碼行數:23,代碼來源:bind.go

示例8: runWithContext

func runWithContext(s *gocql.Session, ctx *cqlc.Context) string {

	result := "FAILED"

	shared := Shared{
		Id:    "foo",
		Value: "bar",
	}

	err := ctx.Store(SHARED.Bind(shared)).Exec(s)

	if err != nil {
		log.Fatalf("Could not store data: %v", err)
		os.Exit(1)
	}

	found, value := get(s, ctx, "foo")

	if found && value == "bar" {

		err := ctx.Upsert(SHARED).SetString(SHARED.VALUE, "baz").Where(SHARED.ID.Eq("foo")).Exec(s)
		if err != nil {
			log.Fatalf("Could not upsert row: %v", err)
			os.Exit(1)
		}

		found, value := get(s, ctx, "foo")

		if found && value == "baz" {

			err = ctx.Delete().From(SHARED).Where(SHARED.ID.Eq("foo")).Exec(s)
			if err != nil {
				log.Fatalf("Could not delete row: %v", err)
				os.Exit(1)
			}

			found, _ := get(s, ctx, "foo")

			if !found {
				result = "PASSED"
			}
		}

	}

	return result
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:47,代碼來源:keyspace.go

示例9: upsert

func upsert(ctx *cqlc.Context, s *gocql.Session, w WhenRowKey, t gocql.UUID, binding cqlc.ColumnBinding) error {
	return ctx.Upsert(w).
		Apply(binding).
		Where(w.WhenColumn().Eq(t)).
		Exec(s)
}
開發者ID:arkxu,項目名稱:cqlc,代碼行數:6,代碼來源:composition.go


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