示例#1
0
文件: comparison.go 项目: qtabot/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)
}
示例#2
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)
}
示例#3
0
文件: delete.go 项目: qtabot/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
	}

}
示例#4
0
文件: bind.go 项目: qtabot/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]

}