@@ -33,7 +33,6 @@ type Context struct {
33
33
}
34
34
35
35
type ORM interface {
36
-
37
36
RegisterSchemaWithIndexName (t interface {}, indexName string ) error
38
37
39
38
GetIndexName (o interface {}) string
@@ -64,10 +63,11 @@ type ORMObjectBase struct {
64
63
Created * time.Time `json:"created,omitempty" elastic_mapping:"created: { type: date }"`
65
64
Updated * time.Time `json:"updated,omitempty" elastic_mapping:"updated: { type: date }"`
66
65
}
67
- func ( obj * ORMObjectBase ) GetID () string {
66
+
67
+ func (obj * ORMObjectBase ) GetID () string {
68
68
return obj .ID
69
69
}
70
- func ( obj * ORMObjectBase ) SetID ( ID string ){
70
+ func (obj * ORMObjectBase ) SetID (ID string ) {
71
71
obj .ID = ID
72
72
}
73
73
@@ -87,15 +87,21 @@ const ASC SortType = "asc"
87
87
const DESC SortType = "desc"
88
88
89
89
type Query struct {
90
- Sort * []Sort
91
- QueryArgs * []util.KV
92
- From int
93
- CollapseField string
94
- Size int
95
- Conds []* Cond
96
- RawQuery []byte
97
- WildcardIndex bool
98
- IndexName string
90
+ Sort * []Sort
91
+ QueryArgs * []util.KV
92
+ From int
93
+ CollapseField string
94
+ Size int
95
+ Conds []* Cond
96
+ RawQuery []byte
97
+ TemplatedQuery * TemplatedQuery
98
+ WildcardIndex bool
99
+ IndexName string
100
+ }
101
+
102
+ type TemplatedQuery struct {
103
+ TemplateID string `json:"id"`
104
+ Parameters map [string ]interface {} `json:"params"`
99
105
}
100
106
101
107
func (q * Query ) Collapse (field string ) * Query {
@@ -302,18 +308,18 @@ func getFieldStringValue(rValue reflect.Value, fieldName string) (bool, string)
302
308
return false , ""
303
309
}
304
310
305
- func existsNonNullField (rValue reflect.Value , fieldName string ) ( bool ) {
311
+ func existsNonNullField (rValue reflect.Value , fieldName string ) bool {
306
312
307
313
if rValue .Kind () == reflect .Ptr {
308
314
rValue = reflect .Indirect (rValue )
309
315
}
310
316
311
317
f := rValue .FieldByName (fieldName )
312
- if f .Kind ()== reflect .Ptr {
318
+ if f .Kind () == reflect .Ptr {
313
319
return ! f .IsNil ()
314
320
}
315
321
316
- if f .IsValid (){
322
+ if f .IsValid () {
317
323
return true
318
324
}
319
325
return false
@@ -382,10 +388,10 @@ func Save(ctx *Context, o interface{}) error {
382
388
return errors .New ("id was not found" )
383
389
}
384
390
385
- createdExists := existsNonNullField (rValue , "Created" )
391
+ createdExists := existsNonNullField (rValue , "Created" )
386
392
t := time .Now ()
387
393
setFieldValue (rValue , "Updated" , & t )
388
- if ! createdExists {
394
+ if ! createdExists {
389
395
setFieldValue (rValue , "Created" , & t )
390
396
}
391
397
@@ -437,24 +443,24 @@ func GroupBy(o interface{}, selectField, groupField, haveQuery string, haveValue
437
443
return getHandler ().GroupBy (o , selectField , groupField , haveQuery , haveValue )
438
444
}
439
445
440
- var registeredSchemas = []util.KeyValue {}
446
+ var registeredSchemas = []util.KeyValue {}
441
447
442
- func MustRegisterSchemaWithIndexName (t interface {}, index string ){
443
- err := RegisterSchemaWithIndexName (t ,index )
448
+ func MustRegisterSchemaWithIndexName (t interface {}, index string ) {
449
+ err := RegisterSchemaWithIndexName (t , index )
444
450
if err != nil {
445
451
panic (err )
446
452
}
447
453
}
448
454
449
455
func RegisterSchemaWithIndexName (t interface {}, index string ) error {
450
- registeredSchemas = append (registeredSchemas ,util.KeyValue {Key : index , Payload : t })
456
+ registeredSchemas = append (registeredSchemas , util.KeyValue {Key : index , Payload : t })
451
457
return nil
452
458
}
453
459
454
- func InitSchema () error {
455
- for _ ,v := range registeredSchemas {
456
- err := getHandler ().RegisterSchemaWithIndexName (v .Payload , v .Key )
457
- if err != nil {
460
+ func InitSchema () error {
461
+ for _ , v := range registeredSchemas {
462
+ err := getHandler ().RegisterSchemaWithIndexName (v .Payload , v .Key )
463
+ if err != nil {
458
464
return err
459
465
}
460
466
}
@@ -490,7 +496,9 @@ func Register(name string, h ORM) {
490
496
}
491
497
492
498
type ProtectedFilterKeyType string
499
+
493
500
const ProtectedFilterKey ProtectedFilterKeyType = "FILTER_PROTECTED"
501
+
494
502
//FilterFieldsByProtected filter struct fields by tag protected recursively,
495
503
//returns a filtered fields map
496
504
func FilterFieldsByProtected (obj interface {}, protected bool ) map [string ]interface {} {
@@ -523,13 +531,13 @@ func FilterFieldsByProtected(obj interface{}, protected bool) map[string]interfa
523
531
if strings .ToLower (tagVal ) != "true" && protected {
524
532
delete (mapObj , jsonName )
525
533
continue
526
- }else if strings .ToLower (tagVal ) == "true" && ! protected {
534
+ } else if strings .ToLower (tagVal ) == "true" && ! protected {
527
535
delete (mapObj , jsonName )
528
536
continue
529
537
}
530
- if fieldType .Type .Kind () == reflect .Struct || (fieldType .Type .Kind () == reflect .Ptr && fieldType .Type .Elem ().Kind () == reflect .Struct ){
538
+ if fieldType .Type .Kind () == reflect .Struct || (fieldType .Type .Kind () == reflect .Ptr && fieldType .Type .Elem ().Kind () == reflect .Struct ) {
531
539
mapObj [jsonName ] = FilterFieldsByProtected (v .Field (i ).Interface (), protected )
532
540
}
533
541
}
534
542
return mapObj
535
- }
543
+ }
0 commit comments