本文整理汇总了Golang中google/golang.org/cloud/datastore.NewQuery函数的典型用法代码示例。如果您正苦于以下问题:Golang NewQuery函数的具体用法?Golang NewQuery怎么用?Golang NewQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewQuery函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ExampleQuery
func ExampleQuery() {
ctx := context.Background()
client, err := datastore.NewClient(ctx, "project-id")
if err != nil {
log.Fatal(err)
}
// Count the number of the post entities.
q := datastore.NewQuery("Post")
n, err := client.Count(ctx, q)
if err != nil {
log.Fatal(err)
}
log.Println("There are %d posts.", n)
// List the posts published since yesterday.
yesterday := time.Now().Add(-24 * time.Hour)
q = datastore.NewQuery("Post").Filter("PublishedAt >", yesterday)
it := client.Run(ctx, q)
// Use the iterator.
_ = it
// Order the posts by the number of comments they have recieved.
datastore.NewQuery("Post").Order("-Comments")
// Start listing from an offset and limit the results.
datastore.NewQuery("Post").Offset(20).Limit(10)
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:28,代码来源:example_test.go
示例2: ExampleQuery_kindless
func ExampleQuery_kindless() {
var lastSeenKey *datastore.Key
// [START kindless_query]
query := datastore.NewQuery("").Filter("__key__ >", lastSeenKey)
// [END kindless_query]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:7,代码来源:examples_test.go
示例3: GetEntity
func (ds *Datastore) GetEntity(t, subject string) (reply []x.Instruction, rerr error) {
skey := datastore.NewKey(ds.ctx, t+"Entity", subject, 0, nil)
log.Infof("skey: %+v", skey)
dkeys, rerr := datastore.NewQuery(t+"Instruction").Ancestor(skey).GetAll(ds.ctx, &reply)
log.Debugf("Got num keys: %+v", len(dkeys))
return
}
开发者ID:dancannon,项目名称:gocrud,代码行数:7,代码来源:datastore.go
示例4: tryLocateOnce
func (loc *INodeDBSSLocator) tryLocateOnce(history int) (string, error) {
start := time.Now()
cli, err := loc.cfg.getClient(context.TODO())
if err != nil {
return "", err
}
dstx, err := cli.NewTransaction(context.TODO(), datastore.Serializable)
if err != nil {
return "", err
}
q := datastore.NewQuery(kindINodeDBSS).Ancestor(loc.rootKey).Order("-TxID").Offset(history).Limit(1).Transaction(dstx)
it := cli.Run(context.TODO(), q)
var e sslocentry
if _, err := it.Next(&e); err != nil {
dstx.Rollback()
if err == datastore.Done {
return "", EEMPTY
}
return "", err
}
if _, err := dstx.Commit(); err != nil {
return "", err
}
logger.Infof(sslog, "LocateSnapshot(%d) took %s. Found entry: %+v", history, time.Since(start), e)
return e.BlobPath, nil
}
开发者ID:postfix,项目名称:otaru,代码行数:29,代码来源:inodedbsslocator.go
示例5: query
func query() (key *AuthorizedKey, username string, err error) {
ctx, err := connect()
if err != nil {
return
}
rawFingerprint, err := decodeFingerprint(fingerprint)
if err != nil {
return
}
key = new(AuthorizedKey)
it := datastore.NewQuery(keyKind).Filter("Fingerprint =", rawFingerprint).Limit(1).Run(ctx)
_, err = it.Next(key)
if err != nil {
return
}
var coder Coder
err = datastore.Get(ctx, key.Coder, &coder)
if err != nil {
return
}
username = coder.Nickname
return
}
开发者ID:coduno,项目名称:tools,代码行数:29,代码来源:akc.go
示例6: ExampleIterator_Cursor
func ExampleIterator_Cursor() {
ctx := context.Background()
client, _ := datastore.NewClient(ctx, "my-proj")
cursorStr := ""
// [START cursor_paging]
const pageSize = 5
query := datastore.NewQuery("Tasks").Limit(pageSize)
if cursorStr != "" {
cursor, err := datastore.DecodeCursor(cursorStr)
if err != nil {
log.Fatalf("Bad cursor %q: %v", cursorStr, err)
}
query = query.Start(cursor)
}
// Read the tasks.
var tasks []Task
var task Task
it := client.Run(ctx, query)
_, err := it.Next(&task)
for err == nil {
tasks = append(tasks, task)
_, err = it.Next(&task)
}
if err != datastore.Done {
log.Fatalf("Failed fetching results: %v", err)
}
// Get the cursor for the next page of results.
nextCursor, err := it.Cursor()
// [END cursor_paging]
_ = err // Check the error.
_ = nextCursor // Use nextCursor.String as the next page's token.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:34,代码来源:examples_test.go
示例7: ExampleQuery_keyFilter
func ExampleQuery_keyFilter() {
ctx := context.Background()
// [START key_filter]
key := datastore.NewKey(ctx, "Task", "someTask", 0, nil)
query := datastore.NewQuery("Task").Filter("__key__ >", key)
// [END key_filter]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例8: ExampleQuery_invalidInequalitySortA
func ExampleQuery_invalidInequalitySortA() {
// [START inequality_sort_invalid_not_same]
query := datastore.NewQuery("Task").
Filter("Priority >", 3).
Order("Created")
// [END inequality_sort_invalid_not_same]
_ = query // The query is invalid.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例9: ExampleQuery_Filter_arrayEquality
func ExampleQuery_Filter_arrayEquality() {
// [START array_value_equality]
query := datastore.NewQuery("Task").
Filter("Tag =", "fun").
Filter("Tag =", "programming")
// [END array_value_equality]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例10: ExampleQuery_Filter_inequality
func ExampleQuery_Filter_inequality() {
// [START inequality_range]
query := datastore.NewQuery("Task").
Filter("Created >", time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC)).
Filter("Created <", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
// [END inequality_range]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例11: ExampleQuery_EventualConsistency
func ExampleQuery_EventualConsistency() {
ctx := context.Background()
// [START eventual_consistent_query]
ancestor := datastore.NewKey(ctx, "TaskList", "default", 0, nil)
query := datastore.NewQuery("Task").Ancestor(ancestor).EventualConsistency()
// [END eventual_consistent_query]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例12: ExampleQuery_Filter_invalidInequality
func ExampleQuery_Filter_invalidInequality() {
// [START inequality_invalid]
query := datastore.NewQuery("Task").
Filter("Created >", time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC)).
Filter("Priority >", 3)
// [END inequality_invalid]
_ = query // The query is invalid.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例13: ExampleQuery_Filter_arrayInequality
func ExampleQuery_Filter_arrayInequality() {
// [START array_value_inequality_range]
query := datastore.NewQuery("Task").
Filter("Tag >", "learn").
Filter("Tag <", "math")
// [END array_value_inequality_range]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:8,代码来源:examples_test.go
示例14: ExampleQuery_inequalitySort
func ExampleQuery_inequalitySort() {
// [START inequality_sort]
query := datastore.NewQuery("Task").
Filter("Priority >", 3).
Order("Priority").
Order("Created")
// [END inequality_sort]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:9,代码来源:examples_test.go
示例15: ExampleQuery_Filter_mixed
func ExampleQuery_Filter_mixed() {
// [START equal_and_inequality_range]
query := datastore.NewQuery("Task").
Filter("Priority =", 4).
Filter("Done =", false).
Filter("Created >", time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC)).
Filter("Created <", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
// [END equal_and_inequality_range]
_ = query // Use client.Run or client.GetAll to execute the query.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:10,代码来源:examples_test.go
示例16: queryVisits
func queryVisits(ctx context.Context, limit int64) ([]*visit, error) {
// Print out previous visits.
q := datastore.NewQuery("Visit").
Order("-Timestamp").
Limit(10)
visits := make([]*visit, 0)
_, err := datastoreClient.GetAll(ctx, q, &visits)
return visits, err
}
开发者ID:jeffmendoza,项目名称:golang-samples,代码行数:10,代码来源:datastore.go
示例17: IsNew
func (ds *Datastore) IsNew(t, id string) bool {
dkey := datastore.NewKey(ds.ctx, t+"Entity", id, 0, nil)
keys, err := datastore.NewQuery(t+"Instruction").Ancestor(dkey).
Limit(1).KeysOnly().GetAll(ds.ctx, nil)
if err != nil {
return false
}
if len(keys) > 0 {
return false
}
return true
}
开发者ID:dancannon,项目名称:gocrud,代码行数:12,代码来源:datastore.go
示例18: ExampleQuery_KeysOnly
func ExampleQuery_KeysOnly() {
ctx := context.Background()
client, _ := datastore.NewClient(ctx, "my-proj")
// [START keys_only_query]
query := datastore.NewQuery("Task").KeysOnly()
// [END keys_only_query]
// [START run_keys_only_query]
keys, err := client.GetAll(ctx, query, nil)
// [END run_keys_only_query]
_ = err // Make sure you check err.
_ = keys // Keys contains keys for all stored tasks.
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:12,代码来源:examples_test.go
示例19: ExampleQuery_Distinct
func ExampleQuery_Distinct() {
// [START distinct_query]
query := datastore.NewQuery("Task").
Project("Priority", "PercentComplete").
Distinct().
Order("Type").Order("Priority")
// [END distinct_query]
_ = query // Use client.Run or client.GetAll to execute the query.
// [START distinct_on_query]
// DISTINCT ON not supported in Go API
// [END distinct_on_query]
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:13,代码来源:examples_test.go
示例20: example2
func example2() {
// [START high_replication_data_definition_code]
g := Greeting{ /* ... */ }
key := datastore.NewIncompleteKey(ctx, "Greeting", guestbookKey(ctx))
// [END high_replication_data_definition_code]
// [START high_replication_query_code]
q := datastore.NewQuery("Greeting").Ancestor(guestbookKey(ctx)).Order("-Date").Limit(10)
// [END high_replication_query_code]
_ = g
_ = key
_ = q
}
开发者ID:jeffmendoza,项目名称:golang-samples,代码行数:14,代码来源:consistency.go
注:本文中的google/golang.org/cloud/datastore.NewQuery函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论