Пример #1
0
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)
}
Пример #2
0
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)
}
Пример #3
0
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)
}
Пример #4
0
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
	}

}
Пример #5
0
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]

}
Пример #6
0
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).
		SetTimeUUID(BASIC.TIMEUUID_COLUMN, basic.TimeuuidColumn).
		SetBoolean(BASIC.BOOLEAN_COLUMN, basic.BooleanColumn).
		SetString(BASIC.TEXT_COLUMN, basic.TextColumn).
		SetString(BASIC.VARCHAR_COLUMN, basic.VarcharColumn).
		SetMap(BASIC.MAP_COLUMN, basic.MapColumn).
		SetArray(BASIC.ARRAY_COLUMN, basic.ArrayColumn).
		SetDecimal(BASIC.DECIMAL_COLUMN, basic.DecimalColumn).
		Exec(s)

	if err != nil {
		log.Fatalf("Could not execute query: %v", err)
		os.Exit(1)
	}
}
Пример #7
0
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)
}