-
Notifications
You must be signed in to change notification settings - Fork 3
/
task_impl.go
79 lines (66 loc) · 1.89 KB
/
task_impl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This file was automatically generated from
//
// task.go
//
// by
//
// generator
//
// DO NOT EDIT
package model
import (
"errors"
"golang.org/x/net/context"
"google.golang.org/appengine/datastore"
)
// TaskKind is the kind used in Datastore to store entities Task entities.
const TaskKind = "Task"
// Tasks is just a slice of Task.
type Tasks []Task
// KeyedTask is a struct that embeds Task and also contains a Key, mainly used for encoding to JSON.
type KeyedTask struct {
*Task
Key *datastore.Key
}
// Key is a shorthand to fill a KeyedTask with an entity and it's key.
func (ƨ *Task) Key(key *datastore.Key) *KeyedTask {
return &KeyedTask{
Task: ƨ,
Key: key,
}
}
// Key is a shorthand to fill a slice of KeyedTask with some entities alongside their keys.
func (ƨ Tasks) Key(keys []*datastore.Key) (keyed []KeyedTask) {
if len(keys) != len(ƨ) {
panic("Key() called on an slice with len(keys) != len(slice)")
}
keyed = make([]KeyedTask, len(ƨ))
for i := range keyed {
keyed[i] = KeyedTask{
Task: &ƨ[i],
Key: keys[i],
}
}
return
}
// Put will put this Task into Datastore using the given key.
func (ƨ Task) Put(ctx context.Context, key *datastore.Key) (*datastore.Key, error) {
if key != nil {
return datastore.Put(ctx, key, &ƨ)
}
return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "Task", nil), &ƨ)
}
// PutWithParent can be used to save this Task as child of another
// entity.
// This will error if parent == nil.
func (ƨ Task) PutWithParent(ctx context.Context, parent *datastore.Key) (*datastore.Key, error) {
if parent == nil {
return nil, errors.New("parent key is nil, expected a valid key")
}
return datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "Task", parent), &ƨ)
}
// NewQueryForTask prepares a datastore.Query that can be
// used to query entities of type Task.
func NewQueryForTask() *datastore.Query {
return datastore.NewQuery("Task")
}