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


Golang Context.Upsert方法代碼示例

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


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

示例3: 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.Upsert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。