3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 """The Python datastore admin API for managing indices and schemas.
32 from google
.appengine
.api
import api_base_pb
33 from google
.appengine
.api
import apiproxy_stub_map
34 from google
.appengine
.api
import datastore
35 from google
.appengine
.api
import datastore_errors
36 from google
.appengine
.api
import datastore_types
37 from google
.appengine
.datastore
import datastore_index
38 from google
.appengine
.datastore
import datastore_pb
39 from google
.appengine
.runtime
import apiproxy_errors
41 def GetIndices(_app
=None):
42 """Fetches all composite indices in the datastore for this app.
45 list of entity_pb.CompositeIndex
48 req
= api_base_pb
.StringProto()
49 req
.set_value(datastore_types
.ResolveAppId(_app
))
50 resp
= datastore_pb
.CompositeIndices()
51 resp
= _Call('GetIndices', req
, resp
)
52 return resp
.index_list()
55 def CreateIndex(index
):
56 """Creates a new composite index in the datastore for this app.
59 index: entity_pb.CompositeIndex
62 int, the id allocated to the index
64 resp
= api_base_pb
.Integer64Proto()
65 resp
= _Call('CreateIndex', index
, resp
)
69 def UpdateIndex(index
):
70 """Updates an index's status. The entire index definition must be present.
73 index: entity_pb.CompositeIndex
75 _Call('UpdateIndex', index
, api_base_pb
.VoidProto())
78 def DeleteIndex(index
):
79 """Deletes an index. The entire index definition must be present.
82 index: entity_pb.CompositeIndex
84 _Call('DeleteIndex', index
, api_base_pb
.VoidProto())
87 def _Call(call
, req
, resp
):
88 """Generic method for making a datastore API call.
91 call: string, the name of the RPC call
92 req: the request PB. if the app_id field is not set, it defaults to the
96 if hasattr(req
, 'app_id'):
97 req
.set_app_id(datastore_types
.ResolveAppId(req
.app_id()))
100 result
= apiproxy_stub_map
.MakeSyncCall('datastore_v3', call
, req
, resp
)
104 except apiproxy_errors
.ApplicationError
, err
:
105 raise datastore
._ToDatastoreError
(err
)