goa_model_gen 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/goa_model_gen/templates/store.go.erb +38 -16
- data/lib/goa_model_gen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c67de54e5abf8bccd463399f089b2d1ca6dd608c771dae7e4102e3c742a63a66
|
4
|
+
data.tar.gz: 9fbcbec4ed85e6e30f87ff8da15a2599c38089aa19fbefb857a1d50066f19aad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05112dfd0abc2818371f55103d60f137994e3ea60d1e8503e576c04bc0331bf2bba591b8282bd3931b9048c194d0cf5d88ba2ab4246d43d9800e5d756747512
|
7
|
+
data.tar.gz: d28035567f27259a583a270dc2142083850955bc2067a71ad0954a7b987fff881fad3d6d7d94082365075018ae6139a97f85c803143d8f20e5b5bffd08f6a1f7
|
@@ -8,6 +8,7 @@
|
|
8
8
|
import "google.golang.org/appengine/log"
|
9
9
|
import config.model_package_path
|
10
10
|
import :goon, "#{config.store_package_path}/goon_store"
|
11
|
+
import :goonorig, "github.com/mjibson/goon"
|
11
12
|
|
12
13
|
model_name = "model.#{model.name}"
|
13
14
|
-%>
|
@@ -24,22 +25,54 @@ type <%= store_name %> struct{
|
|
24
25
|
<%- end -%>
|
25
26
|
}
|
26
27
|
|
28
|
+
func (s *<%= store_name %>) KindName() string {
|
29
|
+
return "<%= model.name%>"
|
30
|
+
}
|
31
|
+
|
32
|
+
func (s *<%= store_name %>) Query() *datastore.Query {
|
33
|
+
q := datastore.NewQuery(s.KindName())
|
34
|
+
if s.Binder != nil {
|
35
|
+
q = s.Binder.Query(q)
|
36
|
+
}
|
37
|
+
return q
|
38
|
+
}
|
39
|
+
|
40
|
+
func (s *<%= store_name %>) Run(ctx context.Context, q *datastore.Query) *goonorig.Iterator {
|
41
|
+
g := goon.FromContext(ctx)
|
42
|
+
return g.Run(q)
|
43
|
+
}
|
44
|
+
|
27
45
|
func (s *<%= store_name %>) All(ctx context.Context) ([]*<%= model_name %>, error) {
|
28
|
-
return s.
|
46
|
+
return s.AllBy(ctx, s.Query())
|
29
47
|
}
|
30
48
|
|
31
|
-
func (s *<%= store_name %>)
|
49
|
+
func (s *<%= store_name %>) AllBy(ctx context.Context, q *datastore.Query) ([]*<%= model_name %>, error) {
|
32
50
|
g := goon.FromContext(ctx)
|
33
51
|
r := []*<%= model_name %>{}
|
34
|
-
log.Infof(ctx, "q is %v\n", q)
|
35
52
|
_, err := g.GetAll(q.EventualConsistency(), &r)
|
36
53
|
if err != nil {
|
37
|
-
log.Errorf(ctx, "Failed to
|
54
|
+
log.Errorf(ctx, "Failed to AllBy <%= model_name %> because of %v\n", err)
|
38
55
|
return nil, err
|
39
56
|
}
|
40
57
|
return r, nil
|
41
58
|
}
|
42
59
|
|
60
|
+
func (s *<%= store_name %>) Select(ctx context.Context, q *datastore.Query) ([]*<%= model_name %>, error) {
|
61
|
+
return s.AllBy(ctx, q)
|
62
|
+
}
|
63
|
+
|
64
|
+
func (s *<%= store_name %>) FirstBy(ctx context.Context, q *datastore.Query) (*<%= model_name %>, error) {
|
65
|
+
r, err := s.AllBy(ctx, q.Limit(1))
|
66
|
+
if err != nil {
|
67
|
+
return nil, err
|
68
|
+
}
|
69
|
+
if len(r) > 0 {
|
70
|
+
return r[0], nil
|
71
|
+
} else {
|
72
|
+
return nil, nil
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
43
76
|
func (s *<%= store_name %>) CountBy(ctx context.Context, q *datastore.Query) (int, error) {
|
44
77
|
g := goon.FromContext(ctx)
|
45
78
|
c, err := g.Count(q)
|
@@ -50,17 +83,6 @@ func (s *<%= store_name %>) CountBy(ctx context.Context, q *datastore.Query) (in
|
|
50
83
|
return c, nil
|
51
84
|
}
|
52
85
|
|
53
|
-
func (s *<%= store_name %>) Query(ctx context.Context) *datastore.Query {
|
54
|
-
g := goon.FromContext(ctx)
|
55
|
-
k := g.Kind(new(<%= model_name %>))
|
56
|
-
// log.Infof(ctx, "Kind for <%= model_name %> is %v\n", k)
|
57
|
-
q := datastore.NewQuery(k)
|
58
|
-
if s.Binder != nil {
|
59
|
-
q = s.Binder.Query(q)
|
60
|
-
}
|
61
|
-
return q
|
62
|
-
}
|
63
|
-
|
64
86
|
func (s *<%= store_name %>) ByID(ctx context.Context, <%= model.id_name_var %> <%= model.id_golang_type %>) (*<%= model_name %>, error) {
|
65
87
|
<%- if model.parent -%>
|
66
88
|
r := <%= model_name %>{ParentKey: s.ParentKey, <%= model.id_name %>: <%= model.id_name_var %>}
|
@@ -250,7 +272,7 @@ func (s *<%= store_name %>) ValidateUniqueness(ctx context.Context, m *<%= model
|
|
250
272
|
<%- end -%>
|
251
273
|
}
|
252
274
|
for field, value := range conditions {
|
253
|
-
q := s.Query(
|
275
|
+
q := s.Query().Filter(field + " =", value)
|
254
276
|
c, err := s.CountBy(ctx, q)
|
255
277
|
if err != nil {
|
256
278
|
return err
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goa_model_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|