https://github.com/ollionorg/dbdriver-python-sample-app
https://github.com/ollionorg/dbdriver-python-sample-app
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ollionorg/dbdriver-python-sample-app
- Owner: ollionorg
- Created: 2021-02-19T10:03:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-25T07:41:01.000Z (about 2 years ago)
- Last Synced: 2025-04-12T23:47:04.321Z (6 months ago)
- Language: Python
- Size: 10.7 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
DynamoDB/Spanner sample RESTful API=========================
A demo app to showcase the `dynamodb` adapter
## URL mappings* **GET /user** - get user by partition key and sort key
* **POST /query/user** - query user by just partition key
* **POST /query/key/user** - query user by partition and sort key
* **POST /query/begins/user** - query users by partition key and where sort key begins with (prefix)
* **POST /query/index/users** - query users on partition key of secondary Index
* **POST /query/index/range** - query users on partition and sort key of secondary index, where sort key ranges between values
* **POST /update/user** - update user or put if not exists
* **POST /update/exists/user** - update user only if partition key exists
* **POST /update/condition/user** - update user on condition where value is greater than existing
* **POST /delete/user** - delete user
* **POST /batch/get** - batch get users
## User model
* **first_name** (_partitionKey_): **string**
* **last_name** : **string**
* **email** (_sortkey_): **string**
* **country** (_partitionKeyOfSecondaryIndex_): **string**
* **price** (_sortkeyOfSecondaryIndex_): **number**## Usage
The application can be executed to use `dynamodb` or `spanner` for CRUD operations
### 1. Run application with Dynamodb as the data source
The application uses `ap-southeast-1` as the default region.
To connect to any other region, run
```
export AWS_REGION="region"
```### 2. Run application with Spanner as the data source
We need to uncomment lines 17 & 18, in `app.py`
```py
os.environ["DYNAMO_LOCAL_HOST"] = "dynamodb-adapter-ip"; eg ('localhost')os.environ["DYNAMO_LOCAL_PORT"] = "9050"
```To run application, call:
```
pip install -r requirements.txt
python app.py
```