예제 #1
0
파일: basic.go 프로젝트: arkxu/cqlc
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)
	}
}
예제 #2
0
파일: comparison.go 프로젝트: arkxu/cqlc
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)
}
예제 #3
0
파일: keyspace.go 프로젝트: arkxu/cqlc
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
}
예제 #4
0
파일: composition.go 프로젝트: arkxu/cqlc
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)
}
예제 #5
0
파일: composition.go 프로젝트: arkxu/cqlc
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)
}
예제 #6
0
파일: delete.go 프로젝트: arkxu/cqlc
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
	}

}
예제 #7
0
파일: bind.go 프로젝트: EverythingMe/cqlc
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]

}
예제 #8
0
파일: keyspace.go 프로젝트: arkxu/cqlc
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
}
예제 #9
0
파일: composition.go 프로젝트: arkxu/cqlc
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)
}