28 from google.appengine.datastore import datastore_index |
28 from google.appengine.datastore import datastore_index |
29 from google.appengine.datastore import datastore_pb |
29 from google.appengine.datastore import datastore_pb |
30 from google.appengine.runtime import apiproxy_errors |
30 from google.appengine.runtime import apiproxy_errors |
31 from google.appengine.datastore import entity_pb |
31 from google.appengine.datastore import entity_pb |
32 |
32 |
33 _LOCAL_APP_ID = datastore_types._LOCAL_APP_ID |
|
34 |
|
35 |
33 |
36 _DIRECTION_MAP = { |
34 _DIRECTION_MAP = { |
37 'asc': entity_pb.Index_Property.ASCENDING, |
35 'asc': entity_pb.Index_Property.ASCENDING, |
38 'ascending': entity_pb.Index_Property.ASCENDING, |
36 'ascending': entity_pb.Index_Property.ASCENDING, |
39 'desc': entity_pb.Index_Property.DESCENDING, |
37 'desc': entity_pb.Index_Property.DESCENDING, |
40 'descending': entity_pb.Index_Property.DESCENDING, |
38 'descending': entity_pb.Index_Property.DESCENDING, |
41 } |
39 } |
42 |
40 |
43 |
41 |
44 def GetSchema(_app=_LOCAL_APP_ID): |
42 def GetSchema(_app=None): |
45 """Infers an app's schema from the entities in the datastore. |
43 """Infers an app's schema from the entities in the datastore. |
46 |
44 |
47 Note that the PropertyValue PBs in the returned EntityProtos are empty |
45 Note that the PropertyValue PBs in the returned EntityProtos are empty |
48 placeholders, so they may cause problems if you try to convert them to |
46 placeholders, so they may cause problems if you try to convert them to |
49 python values with e.g. datastore_types. In particular, user values will |
47 python values with e.g. datastore_types. In particular, user values will |
52 |
50 |
53 Returns: |
51 Returns: |
54 list of entity_pb.EntityProto, with kind and property names and types |
52 list of entity_pb.EntityProto, with kind and property names and types |
55 """ |
53 """ |
56 req = api_base_pb.StringProto() |
54 req = api_base_pb.StringProto() |
57 req.set_value(_app) |
55 req.set_value(datastore_types.ResolveAppId(_app)) |
58 resp = datastore_pb.Schema() |
56 resp = datastore_pb.Schema() |
59 |
57 |
60 _Call('GetSchema', req, resp) |
58 _Call('GetSchema', req, resp) |
61 return resp.kind_list() |
59 return resp.kind_list() |
62 |
60 |
63 |
61 |
64 def GetIndices(_app=_LOCAL_APP_ID): |
62 def GetIndices(_app=None): |
65 """Fetches all composite indices in the datastore for this app. |
63 """Fetches all composite indices in the datastore for this app. |
66 |
64 |
67 Returns: |
65 Returns: |
68 list of entity_pb.CompositeIndex |
66 list of entity_pb.CompositeIndex |
69 """ |
67 """ |
70 req = api_base_pb.StringProto() |
68 req = api_base_pb.StringProto() |
71 req.set_value(_app) |
69 req.set_value(datastore_types.ResolveAppId(_app)) |
72 resp = datastore_pb.CompositeIndices() |
70 resp = datastore_pb.CompositeIndices() |
73 try: |
71 try: |
74 apiproxy_stub_map.MakeSyncCall('datastore_v3', 'GetIndices', req, resp) |
72 apiproxy_stub_map.MakeSyncCall('datastore_v3', 'GetIndices', req, resp) |
75 except apiproxy_errors.ApplicationError, err: |
73 except apiproxy_errors.ApplicationError, err: |
76 raise datastore._ToDatastoreError(err) |
74 raise datastore._ToDatastoreError(err) |
117 call: string, the name of the RPC call |
115 call: string, the name of the RPC call |
118 req: the request PB. if the app_id field is not set, it defaults to the |
116 req: the request PB. if the app_id field is not set, it defaults to the |
119 local app. |
117 local app. |
120 resp: the response PB |
118 resp: the response PB |
121 """ |
119 """ |
122 if hasattr(req, 'app_id') and not req.app_id(): |
120 if hasattr(req, 'app_id'): |
123 req.set_app_id(_LOCAL_APP_ID) |
121 req.set_app_id(datastore_types.ResolveAppId(req.app_id(), 'req.app_id()')) |
124 |
122 |
125 try: |
123 try: |
126 apiproxy_stub_map.MakeSyncCall('datastore_v3', call, req, resp) |
124 apiproxy_stub_map.MakeSyncCall('datastore_v3', call, req, resp) |
127 except apiproxy_errors.ApplicationError, err: |
125 except apiproxy_errors.ApplicationError, err: |
128 raise datastore._ToDatastoreError(err) |
126 raise datastore._ToDatastoreError(err) |