Exemplo n.º 1
0
func main() {

	session := integration.TestSession("127.0.0.1", "cqlc")
	integration.Truncate(session, EVENTS)

	result := "FAILED"

	ctx := cqlc.NewContext()

	var sensorId int64 = 100

	ctx.Upsert(EVENTS).
		SetInt64(EVENTS.SENSOR, sensorId).
		SetTimeUUID(EVENTS.TIMESTAMP, gocql.TimeUUID()).
		SetFloat32(EVENTS.TEMPERATURE, 19.8).
		SetInt32(EVENTS.PRESSURE, 357).
		Exec(session)

	iter, err := ctx.Select().
		From(EVENTS).
		Where(
			EVENTS.SENSOR.Eq(sensorId),
			EVENTS.TIMESTAMP.Lt(gocql.TimeUUID())).
		Fetch(session)

	if err != nil {
		log.Fatalf("Could not execute query: %v", err)
		return
	}

	events, err := BindEvents(iter)
	if err != nil {
		log.Fatalf("Could not bind data: %v", err)
		return
	}

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

	if len(events) == 1 {
		result = "PASSED"
	}

	os.Stdout.WriteString(result)
}
Exemplo n.º 2
0
Arquivo: basic.go Projeto: qtabot/cqlc
func main() {

	session := integration.TestSession("127.0.0.1", "cqlc")
	integration.Truncate(session, BASIC)

	result := "FAILED"

	ctx := cqlc.NewContext()

	basic := Basic{
		Id:              "x",
		Int32Column:     111,
		Int64Column:     1 << 32,
		AsciiColumn:     "ABC",
		TimestampColumn: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), // Keep it simple for reflect.DeepEqual
		BooleanColumn:   true,
		TextColumn:      "foo",
		VarcharColumn:   "bar",
		FloatColumn:     math.MaxFloat32,
		DoubleColumn:    math.MaxFloat64,
		DecimalColumn:   inf.NewDec(1, 3),
		TimeuuidColumn:  gocql.TimeUUID(),
		MapColumn:       map[string]string{"baz": "quux"},
		ArrayColumn:     []string{"baz", "quux"},
	}

	create(ctx, session, basic)

	iter, err := ctx.Select(
		BASIC.ID,
		BASIC.ASCII_COLUMN,
		BASIC.INT32_COLUMN,
		BASIC.INT64_COLUMN,
		BASIC.FLOAT_COLUMN,
		BASIC.DOUBLE_COLUMN,
		BASIC.DECIMAL_COLUMN,
		BASIC.TIMESTAMP_COLUMN,
		BASIC.TIMEUUID_COLUMN,
		BASIC.BOOLEAN_COLUMN,
		BASIC.TEXT_COLUMN,
		BASIC.VARCHAR_COLUMN,
		BASIC.MAP_COLUMN,
		BASIC.ARRAY_COLUMN).
		From(BASIC).
		Where(BASIC.ID.Eq("x")).
		Fetch(session)

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

	result, _ = checkBasics(iter, basic)

	iter, err = ctx.Select(
		BASIC.ID,
		BASIC.ASCII_COLUMN,
		BASIC.INT32_COLUMN,
		BASIC.INT64_COLUMN,
		BASIC.FLOAT_COLUMN,
		BASIC.DOUBLE_COLUMN,
		BASIC.DECIMAL_COLUMN,
		BASIC.TIMESTAMP_COLUMN,
		BASIC.TIMEUUID_COLUMN,
		BASIC.BOOLEAN_COLUMN,
		BASIC.TEXT_COLUMN,
		BASIC.VARCHAR_COLUMN,
		BASIC.MAP_COLUMN,
		BASIC.ARRAY_COLUMN).
		From(BASIC).
		Fetch(session)

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

	result, _ = checkBasics(iter, basic)

	// TODO write test case for a non-matching WHERE clause

	os.Stdout.WriteString(result)
}
Exemplo n.º 3
0
Arquivo: into.go Projeto: qtabot/cqlc
func main() {

	session := integration.TestSession("127.0.0.1", "cqlc")
	integration.Truncate(session, BASIC)

	result := "FAILED"

	ctx := cqlc.NewContext()

	basic := Basic{
		Id:              "x",
		Int32Column:     999,
		Int64Column:     1 << 55,
		AsciiColumn:     "do-re-me",
		TimestampColumn: time.Date(1999, time.December, 31, 23, 59, 59, 59, time.UTC), // Keep it simple for reflect.DeepEqual
		BooleanColumn:   true,
		TextColumn:      "ipso",
		VarcharColumn:   "lorem",
		FloatColumn:     math.MaxFloat32,
		DoubleColumn:    math.MaxFloat64,
		DecimalColumn:   inf.NewDec(1, 9),
		TimeuuidColumn:  gocql.TimeUUID(),
		MapColumn:       map[string]string{"baz": "quux"},
		ArrayColumn:     []string{"baz", "quux"},
	}

	err := ctx.Store(BASIC.Bind(basic)).Exec(session)

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

	var int32Column int32
	var decimalColumn *inf.Dec

	found, err := ctx.Select().
		From(BASIC).
		Where(BASIC.ID.Eq("x")).
		Bind(BASIC.INT32_COLUMN.To(&int32Column), BASIC.DECIMAL_COLUMN.To(&decimalColumn)).
		FetchOne(session)

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

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

	if int32Column == 999 && reflect.DeepEqual(decimalColumn, basic.DecimalColumn) && found {

		found, err := ctx.Select().
			From(BASIC).
			Where(BASIC.ID.Eq("y")).
			Bind(BASIC.INT32_COLUMN.To(&int32Column), BASIC.DECIMAL_COLUMN.To(&decimalColumn)).
			FetchOne(session)

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

		if !found {
			result = "PASSED"
		}

	} else {
		result = fmt.Sprintf("int32Column: %d, decimalColumn %v", int32Column, decimalColumn)
	}

	os.Stdout.WriteString(result)

}
Exemplo n.º 4
0
func main() {
	session := integration.TestSession("127.0.0.1", "cqlc")
	integration.Truncate(session, FIRST_TIMELINE)
	integration.Truncate(session, SECOND_TIMELINE)

	result := "FAILED"

	timestamp := gocql.TimeUUID()

	first := FirstTimeline{
		When: timestamp,
		Tag:  "foobar",
	}

	second := SecondTimeline{
		When:      timestamp,
		Latitude:  50.12,
		Longitude: 0.87,
	}

	ctx := cqlc.NewContext()
	err := ctx.Store(FIRST_TIMELINE.Bind(first)).Exec(session)
	err = ctx.Store(SECOND_TIMELINE.Bind(second)).Exec(session)

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

	var tag string
	var latitude float32

	f1, err := fetchOne(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&tag))
	f2, err := fetchOne(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&latitude))

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

	if f1 && f2 && tag == "foobar" && math.Float32bits(latitude) == math.Float32bits(50.12) {

		// TODO Implement a FROM binding
		t := "bar"
		l := float32(72.34)

		err = upsert(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&t))
		err = upsert(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&l))

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

		f1, err = fetchOne(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&tag))
		f2, err = fetchOne(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&latitude))

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

		if f1 && f2 && tag == t && math.Float32bits(latitude) == math.Float32bits(l) {

			err = deleteByTimestamp(ctx, session, FIRST_TIMELINE, timestamp)
			err = deleteByTimestamp(ctx, session, SECOND_TIMELINE, timestamp)

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

			var tag string
			var latitude float32

			f1, err = fetchOne(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&tag))
			f2, err = fetchOne(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&latitude))

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

			if !f1 && !f2 && tag == "" && latitude == 0.0 {
				result = "PASSED"
			} else {
				result = fmt.Sprintf("After delete - Tag was: %s; Latitude was %f", tag, latitude)
			}
		} else {
			result = fmt.Sprintf("After upsert - Tag was: %s; Latitude was %f", tag, latitude)
		}

	} else {
		result = fmt.Sprintf("Before delete - Tag was: %s; Latitude was %f", tag, latitude)
	}

	os.Stdout.WriteString(result)
}