Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aiscenblue/datastore-mapper
Object Mapper for google datastore withour using appengine
https://github.com/aiscenblue/datastore-mapper
google google-datastore google-datastore-orm orm
Last synced: about 2 months ago
JSON representation
Object Mapper for google datastore withour using appengine
- Host: GitHub
- URL: https://github.com/aiscenblue/datastore-mapper
- Owner: aiscenblue
- License: mit
- Created: 2017-12-12T03:51:55.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-12T04:03:34.000Z (about 7 years ago)
- Last Synced: 2024-10-13T23:37:14.813Z (3 months ago)
- Topics: google, google-datastore, google-datastore-orm, orm
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**Requirements:**
```
Python 3.5 or higher
```**Install requirements**
`pip3 install datastore_mapper`# Set google application credentials
```
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/gcp-service-key.json"
```# Create Model
```
from datastore_mapper import Model, StringProperty, EmailProperty, UidPropertyclass Users(Model):
uid = UidProperty()
first_name = StringProperty()
last_name = StringProperty()
email = EmailProperty()__excluded_indexes__ = ['first_name', 'last_name', 'email']
```
> excluded_indexes is to unset properties that it not needed to be indexed.
datastore set all properties indexed as a default# Create
```
users = Users(first_name="John", last_name="Doe", email="[email protected]")
users.save()
```*** Save using ancestor ***
```
users = Users()
users.set_key(ancestor="generatedUID")
users.save()users_posts = UsersPosts()
users_posts.set_key(ancestor=users.key)
users_posts.save()
```# Update
```
users = Users(uid="exampleGeneratedUID", first_name="John", last_name="Doe", email="[email protected]")
users.update()
```# Delete
```
users = Users(uid="exampleGeneratedUID")
users.delete()
```
> delete is a logical deletion where the data
will be updated the deleted_at property which is a default property model to the current date# Search query
```
from datastore_mapper import ModelCollectionModelCollection(Users(), **kwargs).to_json()
```> **kwargs can be any query that you like example
uid="generatedUID" -> for finding the specific User Model in the datastore> order="-created_at" for descending order or order="created_at" for ascending order
> limit="15" to set limit per list. DEFAULT is 15
> filters=[('first_name', '=', "john"")]
> Users().find_by_iud("generatedUID")
# errors
```
users = Users(first_name="John", last_name="Doe", email="[email protected]")
users.errors
users.save() or update() or delete()
users.data
```
> errors are list or errors from the library. This implementation is to prevent try catch repetition
> data are lists of results from the query.