OLD | NEW |
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 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "time" | 10 "time" |
11 | 11 |
12 ds "github.com/luci/gae/service/datastore" | 12 ds "github.com/luci/gae/service/datastore" |
13 "github.com/luci/luci-go/common/cmpbin" | 13 "github.com/luci/luci-go/common/cmpbin" |
14 ) | 14 ) |
15 | 15 |
16 type kv struct{ k, v []byte } | 16 type kv struct{ k, v []byte } |
17 | 17 |
18 func indx(kind string, orders ...string) *qIndex { | 18 func indx(kind string, orders ...string) *ds.IndexDefinition { |
19 ancestor := false | 19 ancestor := false |
20 if kind[len(kind)-1] == '!' { | 20 if kind[len(kind)-1] == '!' { |
21 ancestor = true | 21 ancestor = true |
22 kind = kind[:len(kind)-1] | 22 kind = kind[:len(kind)-1] |
23 } | 23 } |
24 » ret := &qIndex{kind, ancestor, nil} | 24 » ret := &ds.IndexDefinition{Kind: kind, Ancestor: ancestor} |
25 for _, o := range orders { | 25 for _, o := range orders { |
26 » » dir := qASC | 26 » » dir := ds.ASCENDING |
27 if o[0] == '-' { | 27 if o[0] == '-' { |
28 » » » dir = qDEC | 28 » » » dir = ds.DESCENDING |
29 o = o[1:] | 29 o = o[1:] |
30 } | 30 } |
31 » » ret.sortby = append(ret.sortby, qSortBy{o, dir}) | 31 » » ret.SortBy = append(ret.SortBy, ds.IndexColumn{Property: o, Dire
ction: dir}) |
32 } | 32 } |
33 return ret | 33 return ret |
34 } | 34 } |
35 | 35 |
36 var ( | 36 var ( |
37 prop = ds.MkProperty | 37 prop = ds.MkProperty |
38 propNI = ds.MkPropertyNI | 38 propNI = ds.MkPropertyNI |
39 ) | 39 ) |
40 | 40 |
41 func key(kind string, id interface{}, parent ...ds.Key) ds.Key { | 41 func key(kind string, id interface{}, parent ...ds.Key) ds.Key { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 case ds.PropertyType: | 74 case ds.PropertyType: |
75 buf.WriteByte(byte(x)) | 75 buf.WriteByte(byte(x)) |
76 case string: | 76 case string: |
77 cmpbin.WriteString(buf, x) | 77 cmpbin.WriteString(buf, x) |
78 case []byte: | 78 case []byte: |
79 buf.Write(x) | 79 buf.Write(x) |
80 case time.Time: | 80 case time.Time: |
81 ds.WriteTime(buf, x) | 81 ds.WriteTime(buf, x) |
82 case ds.Key: | 82 case ds.Key: |
83 ds.WriteKey(buf, ds.WithoutContext, x) | 83 ds.WriteKey(buf, ds.WithoutContext, x) |
84 » » case *qIndex: | 84 » » case *ds.IndexDefinition: |
85 » » » x.WriteBinary(buf) | 85 » » » x.Write(buf) |
86 default: | 86 default: |
87 panic(fmt.Errorf("I don't know how to deal with %T: %#v"
, thing, thing)) | 87 panic(fmt.Errorf("I don't know how to deal with %T: %#v"
, thing, thing)) |
88 } | 88 } |
89 } | 89 } |
90 ret := buf.Bytes() | 90 ret := buf.Bytes() |
91 if ret == nil { | 91 if ret == nil { |
92 ret = []byte{} | 92 ret = []byte{} |
93 } | 93 } |
94 return ret | 94 return ret |
95 } | 95 } |
96 | 96 |
97 func icat(bytethings ...interface{}) []byte { | 97 func icat(bytethings ...interface{}) []byte { |
98 ret := cat(bytethings...) | 98 ret := cat(bytethings...) |
99 for i := range ret { | 99 for i := range ret { |
100 ret[i] ^= 0xFF | 100 ret[i] ^= 0xFF |
101 } | 101 } |
102 return ret | 102 return ret |
103 } | 103 } |
104 | 104 |
105 func sat(bytethings ...interface{}) string { | 105 func sat(bytethings ...interface{}) string { |
106 return string(cat(bytethings...)) | 106 return string(cat(bytethings...)) |
107 } | 107 } |
OLD | NEW |