Exemplo n.º 1
0
Arquivo: bind.go Projeto: arkxu/cqlc
func main() {

	s := integration.TestSession("127.0.0.1", "cqlc")
	cqlc.Truncate(s, REALLY_BASIC)

	result := "FAILED"

	ctx := cqlc.NewContext()

	basic := ReallyBasic{
		Id:          "y",
		Int32Column: 2001,
	}

	err := ctx.Store(REALLY_BASIC.Bind(basic)).Exec(s)

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

	query := ctx.Select().From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("y"))

	var fetched ReallyBasic
	found, err := query.Into(REALLY_BASIC.To(&fetched)).FetchOne(s)

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

	if found {
		if reflect.DeepEqual(fetched, basic) {
			result = "PASSED"
		} else {
			result = fmt.Sprintf("[%+v] [%+v]", fetched, basic)
		}
	}

	os.Stdout.WriteString(result)
}
Exemplo n.º 2
0
func main() {

	s := integration.TestSession("127.0.0.1", "cqlc")
	cqlc.Truncate(s, COLLECTIONS)

	result := "FAILED"

	Input.Id = 12

	ctx := cqlc.NewContext()
	if err := ctx.Store(COLLECTIONS.Bind(Input)).Exec(s); err != nil {
		log.Fatalf("Could not store collections: %v", err)
		os.Exit(1)
	}

	var output Collections
	found, err := ctx.Select().From(COLLECTIONS).Where(COLLECTIONS.ID.Eq(Input.Id)).Into(COLLECTIONS.To(&output)).FetchOne(s)
	if err != nil {
		log.Fatalf("Could not store collections: %v", err)
		os.Exit(1)
	}

	if found {

		lhs := fmt.Sprintf("%+v", Input)
		rhs := fmt.Sprintf("%+v", output)

		if lhs == rhs {
			result = "PASSED"
		} else {
			result = fmt.Sprintf("Expected %s but got %s", lhs, rhs)
		}
	}

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

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

	result := "FAILED"

	ctx := cqlc.NewContext()

	uuid, _ := gocql.RandomUUID()

	biggie := new(big.Int)
	biggie.SetString("830169365738487321165427203929228", 10)

	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),
		VarintColumn:    biggie,
		TimeuuidColumn:  gocql.TimeUUID(),
		UuidColumn:      uuid,
		MapColumn:       map[string]string{"baz": "quux"},
		ArrayColumn:     []string{"baz", "quux"},
		SetColumn:       []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.VARINT_COLUMN,
		BASIC.TIMESTAMP_COLUMN,
		BASIC.TIMEUUID_COLUMN,
		BASIC.UUID_COLUMN,
		BASIC.BOOLEAN_COLUMN,
		BASIC.TEXT_COLUMN,
		BASIC.VARCHAR_COLUMN,
		BASIC.MAP_COLUMN,
		BASIC.ARRAY_COLUMN,
		BASIC.SET_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.VARINT_COLUMN,
		BASIC.TIMESTAMP_COLUMN,
		BASIC.TIMEUUID_COLUMN,
		BASIC.UUID_COLUMN,
		BASIC.BOOLEAN_COLUMN,
		BASIC.TEXT_COLUMN,
		BASIC.VARCHAR_COLUMN,
		BASIC.MAP_COLUMN,
		BASIC.ARRAY_COLUMN,
		BASIC.SET_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.º 4
0
func main() {

	s := integration.TestSession("127.0.0.1", "cqlc")
	cqlc.Truncate(s, COLLECTIONS)

	result := "FAILED"

	ctx := cqlc.NewContext()

	if err := ctx.Upsert(COLLECTIONS).AppendInt32Slice(COLLECTIONS.INT32_COLUMN, 1, 2).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil {
		log.Fatalf("Could not increment collections: %v", err)
		os.Exit(1)
	}

	var output []int32
	found, err := ctx.Select(COLLECTIONS.INT32_COLUMN).
		From(COLLECTIONS).
		Where(COLLECTIONS.ID.Eq(20)).
		Bind(COLLECTIONS.INT32_COLUMN.To(&output)).
		FetchOne(s)
	if err != nil {
		log.Fatalf("Could not retreive collections: %v", err)
		os.Exit(1)
	}

	if found {
		if reflect.DeepEqual([]int32{1, 2}, output) {
			if err := ctx.Upsert(COLLECTIONS).AppendInt32Slice(COLLECTIONS.INT32_COLUMN, 3, 4).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil {
				log.Fatalf("Could not increment collections: %v", err)
				os.Exit(1)
			}

			var output []int32
			found, err := ctx.Select(COLLECTIONS.INT32_COLUMN).
				From(COLLECTIONS).
				Where(COLLECTIONS.ID.Eq(20)).
				Bind(COLLECTIONS.INT32_COLUMN.To(&output)).
				FetchOne(s)
			if err != nil {
				log.Fatalf("Could not retreive collections: %v", err)
				os.Exit(1)
			}

			if found {
				if reflect.DeepEqual([]int32{1, 2, 3, 4}, output) {

					if err := ctx.Upsert(COLLECTIONS).PrependInt32Slice(COLLECTIONS.INT32_COLUMN, 0).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil {
						log.Fatalf("Could not increment collections: %v", err)
						os.Exit(1)
					}

					var output []int32
					found, err := ctx.Select(COLLECTIONS.INT32_COLUMN).
						From(COLLECTIONS).
						Where(COLLECTIONS.ID.Eq(20)).
						Bind(COLLECTIONS.INT32_COLUMN.To(&output)).
						FetchOne(s)
					if err != nil {
						log.Fatalf("Could not retreive collections: %v", err)
						os.Exit(1)
					}

					if found {

						if reflect.DeepEqual([]int32{0, 1, 2, 3, 4}, output) {

							if err := ctx.Upsert(COLLECTIONS).RemoveInt32Slice(COLLECTIONS.INT32_COLUMN, 3, 1).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil {
								log.Fatalf("Could not increment collections: %v", err)
								os.Exit(1)
							}

							var output []int32
							found, err := ctx.Select(COLLECTIONS.INT32_COLUMN).
								From(COLLECTIONS).
								Where(COLLECTIONS.ID.Eq(20)).
								Bind(COLLECTIONS.INT32_COLUMN.To(&output)).
								FetchOne(s)
							if err != nil {
								log.Fatalf("Could not retreive collections: %v", err)
								os.Exit(1)
							}

							if found {

								if reflect.DeepEqual([]int32{0, 2, 4}, output) {
									result = "PASSED"
								}
							}

						}
					}
				}
			}
		}
	}

	os.Stdout.WriteString(result)
}