goa_model_gen 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a94a826ba73aaaf70ac461966a30335bd2172b4b21dc8b2a9cdb67b900c18adb
4
- data.tar.gz: c98e3ae9d9e57a0c45bd2cc5fcf8452ae40de3957a7813cb1fc8ba67ce0ff874
3
+ metadata.gz: 0cef817b3a53794219db9757fa0afe0aa7a288a6bd4b3bce8048ce14a8cb45c6
4
+ data.tar.gz: 7bc9fdb4fe7722865fa6edd81d5716a1e3f00a1d62d447ca3f292eccc271a471
5
5
  SHA512:
6
- metadata.gz: 5d4f762066e7d4d2f797a159041833918f955107b51fcb39f52b02050e2eb9252fdc1e594aafc22d30c8d7c8da5aecee58c31df66d522c6f194d52ddf94e6b45
7
- data.tar.gz: 8c00b816ebd1805f36f497e9e336794abb403d57dbf5a9282cd6f461246ca8a05bec0b8ec4ee0192ce837f31d3a17cbe3f8a83cdb8a22be8cc33a43a3bcd14cf
6
+ metadata.gz: cb69b2304c295fd3419b295b5880b741ea3f74aa78ac04a80cb44b4903b08839c7f3f6741b90c9f0a3d6f2c7df3e2e0bd3bba5a2b07ed29d064dc84d7fd7174b
7
+ data.tar.gz: 2ad75dccfe25fdb3192ba38e3f16ea211f0b0d12ba84c233a219934139373d7d6e11b253cd0685544ebcfe297899ac56a4fe63e6be4d34fddd9daceaa6fac934
@@ -80,23 +80,28 @@ type <%= store_name %> struct{
80
80
  }
81
81
 
82
82
  func (s *<%= store_name %>) All(ctx context.Context) ([]*<%= model.name %>, error) {
83
+ return s.Select(ctx, s.Query(ctx))
84
+ }
85
+
86
+ func (s *<%= store_name %>) Select(ctx context.Context, q *datastore.Query) ([]*<%= model.name %>, error) {
83
87
  g := GoonFromContext(ctx)
84
88
  r := []*<%= model.name %>{}
85
- k := g.Kind(new(<%= model.name %>))
86
- log.Infof(ctx, "Kind is %v\n", k)
87
- q := datastore.NewQuery(k)
88
- <%- if model.parent -%>
89
- q = q.Ancestor(s.ParentKey)
90
- <%- end -%>
91
89
  log.Infof(ctx, "q is %v\n", q)
92
90
  _, err := g.GetAll(q.EventualConsistency(), &r)
93
91
  if err != nil {
94
- log.Errorf(ctx, "Failed to GetAll <%= model.name %> because of %v\n", err)
92
+ log.Errorf(ctx, "Failed to Select <%= model.name %> because of %v\n", err)
95
93
  return nil, err
96
94
  }
97
95
  return r, nil
98
96
  }
99
97
 
98
+ func (s *<%= store_name %>) Query(ctx context.Context) *datastore.Query {
99
+ g := GoonFromContext(ctx)
100
+ k := g.Kind(new(<%= model.name %>))
101
+ // log.Infof(ctx, "Kind for <%= model.name %> is %v\n", k)
102
+ return datastore.NewQuery(k)
103
+ }
104
+
100
105
  func (s *<%= store_name %>) ByID(ctx context.Context, <%= model.id_name_var %> <%= model.id_golang_type %>) (*<%= model.name %>, error) {
101
106
  <%- if model.parent -%>
102
107
  r := <%= model.name %>{ParentKey: s.ParentKey, <%= model.id_name %>: <%= model.id_name_var %>}
@@ -261,15 +266,15 @@ func (s *<%= store_name %>) ValidateParent(m *<%= model.name %>) error {
261
266
  return nil
262
267
  }
263
268
 
269
+ <%- end -%>
264
270
  func (s *<%= store_name %>) Delete(ctx context.Context, m *<%= model.name %>) error {
265
271
  g := GoonFromContext(ctx)
266
272
  key, err := g.KeyError(m)
267
273
  if err != nil {
268
- log.Errorf(ctx, "Failed to Get %v because of %v\n", m, err)
274
+ log.Errorf(ctx, "Failed to Get key of %v because of %v\n", m, err)
269
275
  return err
270
276
  }
271
- err = g.Delete(key)
272
- if err != nil {
277
+ if err := g.Delete(key); err != nil {
273
278
  log.Errorf(ctx, "Failed to Delete %v because of %v\n", m, err)
274
279
  return err
275
280
  }
@@ -277,5 +282,3 @@ func (s *<%= store_name %>) Delete(ctx context.Context, m *<%= model.name %>) er
277
282
  }
278
283
 
279
284
  <%- end -%>
280
-
281
- <%- end -%>
@@ -102,8 +102,8 @@ module GoaModelGen
102
102
  end
103
103
 
104
104
  def fields_including_id
105
- if goon && goon['id_type'] == 'string'
106
- id_field = Field.new(goon['id_name'], {'type' => 'string'})
105
+ if goon && goon['id_type']
106
+ id_field = Field.new(id_name, {'type' => goon['id_type']})
107
107
  [id_field] + fields
108
108
  else
109
109
  fields
@@ -1,3 +1,3 @@
1
1
  module GoaModelGen
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-20 00:00:00.000000000 Z
11
+ date: 2018-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor