本文整理汇总了Golang中google/golang.org/cloud/datastore.NewIncompleteKey函数的典型用法代码示例。如果您正苦于以下问题:Golang NewIncompleteKey函数的具体用法?Golang NewIncompleteKey怎么用?Golang NewIncompleteKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewIncompleteKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExampleClient_PutMulti
func ExampleClient_PutMulti() {
ctx := context.Background()
client, _ := datastore.NewClient(ctx, "my-proj")
// [START batch_upsert]
tasks := []*Task{
{
Type: "Personal",
Done: false,
Priority: 4,
Description: "Learn Cloud Datastore",
},
{
Type: "Personal",
Done: false,
Priority: 5,
Description: "Integrate Cloud Datastore",
},
}
keys := []*datastore.Key{
datastore.NewIncompleteKey(ctx, "Task", nil),
datastore.NewIncompleteKey(ctx, "Task", nil),
}
keys, err := client.PutMulti(ctx, keys, tasks)
// [END batch_upsert]
_ = err // Make sure you check err.
_ = keys // keys now has the complete keys for the newly stored tasks.
}
示例2: LogRunComplete
// LogRunComplete logs the end of a completed (failed of finished) run of
// a coduno testrun
func LogRunComplete(pKey *datastore.Key, build *BuildData, in,
out, extra string, exit error, prepLog string, stats syscall.Rusage) {
tx, err := datastore.NewTransaction(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "LogRunComplete: Could not get transaction!")
}
build.EndTime = time.Now()
if exit != nil {
build.Status = "failed"
} else {
build.Status = "good"
}
_, err = tx.Put(pKey, build)
if err != nil {
fmt.Fprintf(os.Stderr, "LogRunComplete: Putting build failed!")
tx.Rollback()
return
}
data := &LogData{in, out, extra, prepLog, stats}
k := datastore.NewIncompleteKey(ctx, buildKind, pKey)
_, err = tx.Put(k, data)
if err != nil {
fmt.Fprintf(os.Stderr, "LogRunComplete: Putting data failed!")
tx.Rollback()
return
}
tx.Commit()
}
示例3: ExampleNewIncompleteKey
func ExampleNewIncompleteKey() {
ctx := context.Background()
// [START incomplete_key]
taskKey := datastore.NewIncompleteKey(ctx, "Task", nil)
// [END incomplete_key]
_ = taskKey // Use the task key for datastore operations.
}
示例4: ExamplePut
func ExamplePut() {
ctx := context.Background()
client, err := datastore.NewClient(ctx, "project-id")
if err != nil {
log.Fatal(err)
}
type Article struct {
Title string
Description string
Body string `datastore:",noindex"`
Author *datastore.Key
PublishedAt time.Time
}
newKey := datastore.NewIncompleteKey(ctx, "Article", nil)
_, err = client.Put(ctx, newKey, &Article{
Title: "The title of the article",
Description: "The description of the article...",
Body: "...",
Author: datastore.NewKey(ctx, "Author", "jbd", 0, nil),
PublishedAt: time.Now(),
})
if err != nil {
log.Fatal(err)
}
}
示例5: AddTask
// AddTask adds a task with the given description to the datastore,
// returning the key of the newly created entity.
func AddTask(ctx context.Context, client *datastore.Client, desc string) (*datastore.Key, error) {
task := &Task{
Desc: desc,
Created: time.Now(),
}
key := datastore.NewIncompleteKey(ctx, "Task", nil)
return client.Put(ctx, key, task)
}
示例6: AddBook
// AddBook saves a given book, assigning it a new ID.
func (db *datastoreDB) AddBook(b *Book) (id int64, err error) {
ctx := context.Background()
k := datastore.NewIncompleteKey(ctx, "Book", nil)
k, err = db.client.Put(ctx, k, b)
if err != nil {
return 0, fmt.Errorf("datastoredb: could not put Book: %v", err)
}
return k.ID(), nil
}
示例7: LogBuildStart
// LogBuildStart sends info to the datastore, informing that a new build
// started
func LogBuildStart(challenge string, commit string, user string) (*datastore.Key, *BuildData) {
key := datastore.NewIncompleteKey(ctx, buildKind, nil)
build := &BuildData{challenge, user, commit, "started", time.Now(), time.Unix(0, 0)}
key, err := datastore.Put(ctx, key, build)
if err != nil {
fmt.Fprintf(os.Stderr, "LogBuildStart: %v", err)
}
return key, build
}
示例8: Save
// Save will put this AccessToken into Datastore using the given key.
func (x AccessToken) Save(ctx context.Context, key ...*datastore.Key) (*datastore.Key, error) {
if len(key) > 1 {
panic("zero or one key expected")
}
if len(key) == 1 && key[0] != nil {
return datastore.Put(ctx, key[0], &x)
}
return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, AccessTokenKind, nil), &x)
}
示例9: ExampleClient_Put_upsert
func ExampleClient_Put_upsert() {
ctx := context.Background()
client, _ := datastore.NewClient(ctx, "my-proj")
task := &Task{} // Populated with appropriate data.
key := datastore.NewIncompleteKey(ctx, "Task", nil)
// [START upsert]
key, err := client.Put(ctx, key, task)
// [END upsert]
_ = err // Make sure you check err.
_ = key // key is the complete key for the newly stored task
}
示例10: recordVisit
func recordVisit(ctx context.Context, now time.Time, userIP string) error {
v := &visit{
Timestamp: now,
UserIP: userIP,
}
k := datastore.NewIncompleteKey(ctx, "Visit", nil)
_, err := datastoreClient.Put(ctx, k, v)
return err
}
示例11: Put
// Put installs the Repository in the Client's datastore.
func (r *Repository) Put(c *Client) error {
key := datastore.NewIncompleteKey(c.ctx, repositoryKind, nil)
key, err := c.datastore.Put(c.ctx, key, r)
if err != nil {
return err
}
r.key = key
return nil
}
示例12: example
func example() {
// [START master_slave_data_definition_code]
g := Greeting{ /* ... */ }
key := datastore.NewIncompleteKey(ctx, "Greeting", nil)
// [END master_slave_data_definition_code]
// [START master_slave_query_code]
q := datastore.NewQuery("Greeting").Order("-Date").Limit(10)
// [END master_slave_query_code]
_ = g
_ = key
_ = q
}
示例13: 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
}
示例14: ExampleClient_Put
func ExampleClient_Put() {
ctx := context.Background()
client, _ := datastore.NewClient(ctx, "my-proj")
// [START entity_with_parent]
parentKey := datastore.NewKey(ctx, "TaskList", "default", 0, nil)
key := datastore.NewIncompleteKey(ctx, "Task", parentKey)
task := Task{
Type: "Personal",
Done: false,
Priority: 4,
Description: "Learn Cloud Datastore",
}
// A complete key is assigned to the entity when it is Put.
var err error
key, err = client.Put(ctx, key, &task)
// [END entity_with_parent]
_ = err // Make sure you check err.
}
示例15: putAuthorizedKey
func putAuthorizedKey(ak *AuthorizedKey, username string) (err error) {
ctx, err := connect()
if err != nil {
return
}
var coder Coder
it := datastore.NewQuery(coderKind).Filter("Nickname =", username).Limit(1).Run(ctx)
ck, err := it.Next(&coder)
if err != nil {
return
}
ak.Coder = ck
dk := datastore.NewIncompleteKey(ctx, keyKind, nil)
_, err = datastore.Put(ctx, dk, ak)
return
}