Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: service/datastore/pls_impl.go

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 100% coverage of new code Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // HEAVILY adapted from github.com/golang/appengine/datastore 5 // HEAVILY adapted from github.com/golang/appengine/datastore
6 6
7 package rawdatastore 7 package datastore
8 8
9 import ( 9 import (
10 "fmt" 10 "fmt"
11 "reflect" 11 "reflect"
12 "strconv" 12 "strconv"
13 "strings" 13 "strings"
14 "sync" 14 "sync"
15 "time" 15 "time"
16 "unicode" 16 "unicode"
17 17
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return fmt.Errorf("gae/helper: cannot set meta %q: unexported fi eld", key) 352 return fmt.Errorf("gae/helper: cannot set meta %q: unexported fi eld", key)
353 } 353 }
354 // setting a BoolField 354 // setting a BoolField
355 if b, ok := val.(bool); ok { 355 if b, ok := val.(bool); ok {
356 if b { 356 if b {
357 val = On 357 val = On
358 } else { 358 } else {
359 val = Off 359 val = Off
360 } 360 }
361 } 361 }
362 » p.o.Field(idx).Set(reflect.ValueOf(val)) 362 » f := p.o.Field(idx)
363 » if val == nil {
364 » » f.Set(reflect.Zero(f.Type()))
365 » } else {
366 » » f.Set(reflect.ValueOf(val))
367 » }
363 return nil 368 return nil
364 } 369 }
365 370
366 func (p *structPLS) Problem() error { return p.c.problem } 371 func (p *structPLS) Problem() error { return p.c.problem }
367 372
368 var ( 373 var (
369 // The RWMutex is chosen intentionally, as the majority of access to the 374 // The RWMutex is chosen intentionally, as the majority of access to the
370 // structCodecs map will be in parallel and will be to read an existing codec. 375 // structCodecs map will be in parallel and will be to read an existing codec.
371 // There's no reason to serialize goroutines on every 376 // There's no reason to serialize goroutines on every
372 » // gae.RawDatastore.{Get,Put}{,Multi} call. 377 » // gae.Interface.{Get,Put}{,Multi} call.
373 structCodecsMutex sync.RWMutex 378 structCodecsMutex sync.RWMutex
374 structCodecs = map[reflect.Type]*structCodec{} 379 structCodecs = map[reflect.Type]*structCodec{}
375 ) 380 )
376 381
377 // validPropertyName returns whether name consists of one or more valid Go 382 // validPropertyName returns whether name consists of one or more valid Go
378 // identifiers joined by ".". 383 // identifiers joined by ".".
379 func validPropertyName(name string) bool { 384 func validPropertyName(name string) bool {
380 if name == "" { 385 if name == "" {
381 return false 386 return false
382 } 387 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 if c.problem == errRecursiveStruct { 561 if c.problem == errRecursiveStruct {
557 c.problem = nil 562 c.problem = nil
558 } 563 }
559 return 564 return
560 } 565 }
561 566
562 func convertMeta(val string, t reflect.Type) (interface{}, error) { 567 func convertMeta(val string, t reflect.Type) (interface{}, error) {
563 switch t { 568 switch t {
564 case typeOfString: 569 case typeOfString:
565 return val, nil 570 return val, nil
571 case typeOfKey:
572 if val != "" {
573 return nil, fmt.Errorf("key field is not allowed to have a default: %q", val)
574 }
575 return nil, nil
566 case typeOfInt64: 576 case typeOfInt64:
567 if val == "" { 577 if val == "" {
568 return int64(0), nil 578 return int64(0), nil
569 } 579 }
570 return strconv.ParseInt(val, 10, 64) 580 return strconv.ParseInt(val, 10, 64)
571 case typeOfToggle: 581 case typeOfToggle:
572 switch val { 582 switch val {
573 case "on", "On", "true": 583 case "on", "On", "true":
574 return true, nil 584 return true, nil
575 case "off", "Off", "false": 585 case "off", "Off", "false":
576 return false, nil 586 return false, nil
577 } 587 }
578 return nil, fmt.Errorf("Toggle field has bad/missing default, go t %q", val) 588 return nil, fmt.Errorf("Toggle field has bad/missing default, go t %q", val)
579 } 589 }
580 return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t , val) 590 return nil, fmt.Errorf("helper: meta field with bad type/value %s/%q", t , val)
581 } 591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698