本文整理汇总了Golang中github.com/relops/cqlc/cqlc.NewContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContext函数的具体用法?Golang NewContext怎么用?Golang NewContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, REVERSE_TIMESERIES)
result := "FAILED"
ctx := cqlc.NewContext()
batch := gocql.NewBatch(gocql.LoggedBatch)
events := 100
for i := 0; i < events; i++ {
unix := time.Now().Unix()
t := time.Unix(unix+int64(i), 0)
ctx.Upsert(REVERSE_TIMESERIES).
SetString(REVERSE_TIMESERIES.EVENT_TYPE, "x").
SetTimestamp(REVERSE_TIMESERIES.INSERTION_TIME, t).
SetBytes(REVERSE_TIMESERIES.EVENT, []byte("neb")).
Batch(batch)
}
if err := session.ExecuteBatch(batch); err != nil {
log.Fatalf("Could not execute batch: %v", err)
os.Exit(1)
}
iter, err := ctx.Select().From(REVERSE_TIMESERIES).Fetch(session)
if err != nil {
log.Fatalf("Could not read REVERSE_TIMESERIES: %v", err)
os.Exit(1)
}
var previous time.Time
err = MapReverseTimeseries(iter, func(e ReverseTimeseries) (bool, error) {
current := e.InsertionTime
if !previous.IsZero() {
if current.After(previous) {
return false, fmt.Errorf("Wrong ordering (DESC): previous was %v but current is %v", previous, current)
}
}
previous = current
return true, nil
})
if err != nil {
log.Fatalf("Unexpected order of REVERSE_TIMESERIES: %v", err)
os.Exit(1)
}
result = "PASSED"
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:60,代码来源:reverse.go
示例2: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, REALLY_BASIC)
result := "FAILED"
ctx := cqlc.NewContext()
basic := ReallyBasic{
Id: "y",
Int32Column: 2001,
}
err := ctx.Store(REALLY_BASIC.Bind(basic)).Exec(session)
if err != nil {
log.Fatalf("Could not bind data: %v", err)
os.Exit(1)
}
fetched := fetchFirstReallyBasic(ctx, session, "y")
if reflect.DeepEqual(fetched, basic) {
result = "PASSED"
} else {
result = fmt.Sprintf("[%+v] [%+v]", fetched, basic)
}
os.Stdout.WriteString(result)
}
开发者ID:EverythingMe,项目名称:cqlc,代码行数:32,代码来源:bind.go
示例3: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
session.SetPageSize(1000)
integration.Truncate(session, EVENTS)
result := "FAILED"
ctx := cqlc.NewContext()
batch := gocql.NewBatch(gocql.LoggedBatch)
rounds := 10
distinct := 10
for i := 0; i < rounds; i++ {
for j := 0; j < distinct; j++ {
ctx.Upsert(EVENTS).
SetInt64(EVENTS.SENSOR, int64(j)).
SetTimeUUID(EVENTS.TIMESTAMP, gocql.TimeUUID()).
SetFloat32(EVENTS.TEMPERATURE, 19.8).
SetInt32(EVENTS.PRESSURE, 357).
Batch(batch)
}
}
err := session.ExecuteBatch(batch)
if err != nil {
log.Fatalf("Could not execute batch: %v", err)
os.Exit(1)
}
iter, err := ctx.SelectDistinct(EVENTS.SENSOR).From(EVENTS).Fetch(session)
if err != nil {
log.Fatalf("Could not prepare query: %v", err)
os.Exit(1)
}
count := 0
MapEvents(iter, func(e Events) (bool, error) {
count++
return true, nil
})
if err := iter.Close(); err != nil {
log.Fatalf("Could not close iterator: %v", err)
os.Exit(1)
}
if count == distinct {
result = "PASSED"
} else {
result = fmt.Sprintf("Expected %d distinct rows; got %d", distinct, count)
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:58,代码来源:distinct.go
示例4: runWithStaticKeyspace
func runWithStaticKeyspace(s *gocql.Session) string {
truncate := fmt.Sprintf("TRUNCATE %s.%s", SHARED.Keyspace(), SHARED.TableName())
if err := s.Query(truncate).Exec(); err != nil {
log.Fatalf("Could not connect to cassandra: %v", err)
os.Exit(1)
}
ctx := cqlc.NewContext()
ctx.StaticKeyspace = true
return runWithContext(s, ctx)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:12,代码来源:keyspace.go
示例5: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, BASIC_CLUSTERED)
result := "FAILED"
rows := 10
ctx := cqlc.NewContext()
batch := gocql.NewBatch(gocql.LoggedBatch)
for i := 0; i < rows; i++ {
err := ctx.Upsert(BASIC_CLUSTERED).
SetInt64(BASIC_CLUSTERED.ID, int64(0)).
SetInt32(BASIC_CLUSTERED.INT32_CLUSTER, int32(i)).
SetInt32(BASIC_CLUSTERED.INT32_COLUMN, int32(i)).
Batch(batch)
if err != nil {
log.Fatalf("Could not batch upsert: %v", err)
os.Exit(1)
}
}
err := session.ExecuteBatch(batch)
if err != nil {
log.Fatalf("Could not execute batch: %v", err)
os.Exit(1)
}
iter, err := ctx.Select().From(BASIC_CLUSTERED).Where(BASIC_CLUSTERED.ID.Eq(0)).Fetch(session)
basics, err := BindBasicClustered(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) == rows {
result = "PASSED"
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:52,代码来源:batch.go
示例6: checkOrderedLimit
func checkOrderedLimit(session *gocql.Session, col ...cqlc.ClusteredColumn) (gocql.UUID, error) {
var u gocql.UUID
ctx := cqlc.NewContext()
_, err := ctx.Select().
From(SIGNIFICANT_EVENTS).
Where(SIGNIFICANT_EVENTS.SENSOR.Eq(100)).
OrderBy(col...).
Limit(1).
Bind(SIGNIFICANT_EVENTS.TIMESTAMP.To(&u)).
FetchOne(session)
return u, err
}
开发者ID:arkxu,项目名称:cqlc,代码行数:13,代码来源:order.go
示例7: runWithKeyspace
func runWithKeyspace(s *gocql.Session, keyspace string) string {
truncate := fmt.Sprintf("TRUNCATE %s.shared", keyspace)
if err := s.Query(truncate).Exec(); err != nil {
log.Fatalf("Could not connect to cassandra: %v", err)
os.Exit(1)
}
ctx := cqlc.NewContext()
ctx.Keyspace = keyspace
return runWithContext(s, ctx)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:13,代码来源:keyspace.go
示例8: main
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)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:48,代码来源:sensor.go
示例9: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, REALLY_BASIC)
result := "FAILED"
ctx := cqlc.NewContext()
err := ctx.Upsert(REALLY_BASIC).
SetString(REALLY_BASIC.ID, "x").
SetInt32(REALLY_BASIC.INT32_COLUMN, 222).
Exec(session)
if err != nil {
log.Fatalf("Could not execute upsert: %v", err)
os.Exit(1)
}
err = ctx.Delete(REALLY_BASIC.INT32_COLUMN).From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("x")).Exec(session)
if err != nil {
log.Fatalf("Could not execute delete: %v", err)
os.Exit(1)
}
basic := fetchFirstBasic(ctx, session, "x")
if basic.Int32Column != 0 {
log.Fatalf("Got bogus basic: %v", basic)
os.Exit(1)
}
err = ctx.Delete().From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("x")).Exec(session)
if err != nil {
log.Fatalf("Could not execute delete: %v", err)
os.Exit(1)
}
basic = fetchFirstBasic(ctx, session, "x")
if basic == nil {
result = "PASSED"
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:47,代码来源:delete.go
示例10: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, ORIGINAL)
result := "FAILED"
ctx := cqlc.NewContext()
o := Original{
Id: "x",
Date: time.Now().UTC().Truncate(time.Millisecond),
Comment: "foo",
}
if err := ctx.Store(ORIGINAL.Bind(o)).Exec(session); err != nil {
log.Fatalf("Could not upsert ORIGINAL: %v", err)
os.Exit(1)
}
iter, err := ctx.Select().From(ORIGINAL).Fetch(session)
if err != nil {
log.Fatalf("Could not read ORIGINAL: %v", err)
os.Exit(1)
}
var c Clone
err = MapOriginal(iter, func(o Original) (bool, error) {
c = duplicate(&o)
return false, nil
})
if err != nil {
log.Fatalf("Could not map ORIGINAL: %v", err)
os.Exit(1)
}
if o.Id == c.Id && o.Date == c.Date {
result = "PASSED"
} else {
result = fmt.Sprintf("Original: %+v; clone: %+v", o, c)
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:47,代码来源:like.go
示例11: main
func main() {
host := "127.0.0.1"
keyspace := "twitter_example"
cluster := gocql.NewCluster(host)
cluster.Keyspace = keyspace
session, err := cluster.CreateSession()
if err != nil {
log.Fatalf("Could not create CQL session: %s", err)
}
ctx := cqlc.NewContext()
err = ctx.Upsert(TWEETS).
SetString(TWEETS.NAME, "tweeter").
Where(TWEETS.ID.Eq(1)).
Exec(session)
if err != nil {
log.Fatalf("Could not execute CQL upsert: %s", err)
}
iter, err := ctx.Select().
From(TWEETS).
Where(TWEETS.ID.Eq(1)).
Fetch(session)
if err != nil {
log.Fatalf("Could not execute CQL select: %s", err)
}
tweets, err := twitter.BindTweets(iter)
if err != nil {
log.Fatalf("Could not bind tweets: %s", err)
}
err = iter.Close()
if err != nil {
log.Fatalf("Could not bind tweets: %s", err)
}
log.Printf("Got tweets: %+v\n", tweets)
}
开发者ID:relops,项目名称:cqlc-example,代码行数:45,代码来源:main.go
示例12: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, CLUSTER_BY_STRING_AND_INT)
result := "FAILED"
ctx := cqlc.NewContext()
err := ctx.Upsert(CLUSTER_BY_STRING_AND_INT).
SetString(CLUSTER_BY_STRING_AND_INT.ID, "a").
SetString(CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER, "y").
SetInt64(CLUSTER_BY_STRING_AND_INT.INT64_CLUSTER, 4).
SetInt64(CLUSTER_BY_STRING_AND_INT.LAST_CLUSTER_ELEMENT, 40).
SetInt32(CLUSTER_BY_STRING_AND_INT.INT32_COLUMN, 100).
Exec(session)
if err != nil {
log.Fatalf("Could not execute upsert: %v", err)
os.Exit(1)
}
id := CLUSTER_BY_STRING_AND_INT.ID.Eq("a")
passed := expectComparisonResult(ctx, session, expect(1), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Gt("x"))
passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Gt("y"))
passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Ge("z"))
passed = expectComparisonResult(ctx, session, expect(1), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Lt("z"))
passed = expectComparisonResult(ctx, session, expect(1), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Le("y"))
passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Lt("y"))
passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Lt("y"))
stringCluster := CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Eq("y")
int64Cluster := CLUSTER_BY_STRING_AND_INT.INT64_CLUSTER.Eq(4)
lastClusterElement := CLUSTER_BY_STRING_AND_INT.LAST_CLUSTER_ELEMENT.In(39, 40, 41)
passed = expectComparisonResult(ctx, session, expect(1), id, stringCluster, int64Cluster, lastClusterElement)
passed = expectComparisonResult(ctx, session, expect(1), CLUSTER_BY_STRING_AND_INT.ID.In("a"))
if passed {
result = "PASSED"
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:45,代码来源:comparison.go
示例13: readCounter
func readCounter(session *gocql.Session, key string) (bool, int64) {
var counter int64
ctx := cqlc.NewContext()
found, err := ctx.Select(COUNTER.COUNTER_COLUMN).
From(COUNTER).
Where(COUNTER.ID.Eq(key)).
Bind(COUNTER.COUNTER_COLUMN.To(&counter)).
FetchOne(session)
if err != nil {
log.Fatalf("Could not bind data: %v", err)
os.Exit(1)
}
return found, counter
}
开发者ID:arkxu,项目名称:cqlc,代码行数:18,代码来源:counter.go
示例14: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, SIMPLE_INDEXED_COMPOSITE)
result := "FAILED"
ctx := cqlc.NewContext()
s := SimpleIndexedComposite{
X: 1,
Y: 2,
Z: 3,
}
if err := ctx.Store(SIMPLE_INDEXED_COMPOSITE.Bind(s)).Exec(session); err != nil {
log.Fatalf("Could not upsert ORIGINAL: %v", err)
os.Exit(1)
}
var z int32
found, err := ctx.Select(SIMPLE_INDEXED_COMPOSITE.Z).
From(SIMPLE_INDEXED_COMPOSITE).
Where(SIMPLE_INDEXED_COMPOSITE.X.Eq(s.X), SIMPLE_INDEXED_COMPOSITE.Y.Eq(s.Y)).
Bind(SIMPLE_INDEXED_COMPOSITE.Z.To(&z)).
FetchOne(session)
if !found {
log.Fatalf("Could not find SIMPLE_INDEXED_COMPOSITE with key %v", 1)
os.Exit(1)
}
if err != nil {
log.Fatalf("Could not retrieve SIMPLE_INDEXED_COMPOSITE: %v", err)
os.Exit(1)
}
if z == s.Z {
result = "PASSED"
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:43,代码来源:composite_index.go
示例15: compareAndSwap
func compareAndSwap(session *gocql.Session, id string, int32column int32) (bool, string, int32) {
var casId string
var casInt32column int32
ctx := cqlc.NewContext()
applied, err := ctx.Upsert(REALLY_BASIC).
SetString(REALLY_BASIC.ID, id).
SetInt32(REALLY_BASIC.INT32_COLUMN, int32column).
IfExists(REALLY_BASIC.ID.To(&casId), REALLY_BASIC.INT32_COLUMN.To(&casInt32column)).
Swap(session)
if err != nil {
log.Fatalf("Could not execute CAS statement: %v", err)
os.Exit(1)
}
return applied, casId, casInt32column
}
开发者ID:arkxu,项目名称:cqlc,代码行数:20,代码来源:cas.go
示例16: checkOrdering
func checkOrdering(session *gocql.Session, col ...cqlc.ClusteredColumn) (int, error) {
ctx := cqlc.NewContext()
iter, err := ctx.Select().
From(SIGNIFICANT_EVENTS).
Where(SIGNIFICANT_EVENTS.SENSOR.Eq(100)).
OrderBy(col...).
Fetch(session)
if err != nil {
log.Fatalf("Could not execute query: %v", err)
os.Exit(1)
}
count := 0
var previous time.Time
err = MapSignificantEvents(iter, func(e SignificantEvents) (bool, error) {
current := e.Timestamp.Time()
if !previous.IsZero() {
if col[0].IsDescending() {
if current.After(previous) {
return false, fmt.Errorf("Wrong ordering (DESC): previous was %v but current is %v", previous, current)
}
} else {
if current.Before(previous) {
return false, fmt.Errorf("Wrong ordering (ASC): previous was %v but current is %v", previous, current)
}
}
}
previous = current
count++
return true, nil
})
return count, err
}
开发者ID:arkxu,项目名称:cqlc,代码行数:41,代码来源:order.go
示例17: main
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)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:41,代码来源:bind.go
示例18: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, COUNTER)
result := "FAILED"
ctx := cqlc.NewContext()
err := ctx.UpdateCounter(COUNTER).
Increment(COUNTER.COUNTER_COLUMN, 13).
Having(COUNTER.ID.Eq("x")).
Exec(session)
if err != nil {
log.Fatalf("Could not execute counter increment: %v", err)
}
found, counter := readCounter(session, "x")
if found && counter == 13 {
result = "PASSED"
}
c := BasicCounter{
Id: "x",
CounterColumn: 11,
}
err = ctx.Add(COUNTER.Bind(c)).Exec(session)
if err != nil {
log.Fatalf("Could not execute counter increment: %v", err)
}
found, counter = readCounter(session, "x")
if !found && counter != 24 {
result = fmt.Sprintf("Expected 24, but counter was %d", counter)
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:40,代码来源:counter.go
示例19: main
func main() {
session := integration.TestSession("127.0.0.1", "cqlc")
integration.Truncate(session, BASIC_BLOB)
result := "FAILED"
ctx := cqlc.NewContext()
blob := BasicBlob{
Id: "baz",
BlobColumn: []byte("foo"),
}
err := ctx.Store(BASIC_BLOB.Bind(blob)).Exec(session)
if err != nil {
log.Fatalf("Could not bind data: %v", err)
os.Exit(1)
}
var b []byte
found, err := ctx.Select().
From(BASIC_BLOB).
Where(BASIC_BLOB.ID.Eq("baz")).
Bind(BASIC_BLOB.BLOB_COLUMN.To(&b)).
FetchOne(session)
if found && bytes.Equal(blob.BlobColumn, b) {
result = "PASSED"
} else {
result = fmt.Sprintf("Blob was %s", string(b))
}
os.Stdout.WriteString(result)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:37,代码来源:blob.go
示例20: main
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)
}
开发者ID:arkxu,项目名称:cqlc,代码行数:36,代码来源:collections.go
注:本文中的github.com/relops/cqlc/cqlc.NewContext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论