Flask-RESTive-Identifiers-0.0.3
توضیحات
Flask-RESTive extension to work with identifiers.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | Flask-RESTive-Identifiers-0.0.3 |
| نام | Flask-RESTive-Identifiers |
| نسخه کتابخانه | 0.0.3 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | left-join |
| ایمیل نویسنده | left-join@riseup.net |
| آدرس صفحه اصلی | https://github.com/left-join/flask-restive-identifiers |
| آدرس اینترنتی | https://pypi.org/project/Flask-RESTive-Identifiers/ |
| مجوز | MIT |
# flask-restive-identifiers
Flask-RESTive extension to work with identifiers.
[](https://travis-ci.org/left-join/flask-restive-identifiers)
[](https://coveralls.io/github/left-join/flask-restive-identifiers?branch=master)
[](https://landscape.io/github/left-join/flask-restive-identifiers/master)
[](https://pypi.python.org/pypi/Flask-RESTive-Identifiers)
## Installation
```bash
pip install flask-restive-identifiers
```
## How to use
The library based on postgresql sequences, so you should to configure your
application to use postgresql first:
```python
from flask import Flask
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://user:password@localhost:5432/database'
```
The library provides function generate_id that can be used as is:
```python
>>> from flask_restive_identifiers import generate_id
>>> generate_id(namespace='test')
>>> 1
>>> generate_id(namespace='test')
>>> 2
>>> generate_id(namespace='test')
>>> 3
>>> generate_id(namespace='new_space')
>>> 1
```
The library provides schema that automatically generates auto-increment id.
The sequence name can be changed with meta attribute identifier_namespace:
```python
from flask_restive import fields
from flask_restive_identifiers import IntegerIDSchema
class ScientistSchema(IntegerIDSchema):
first_name = fields.String(required=True)
last_name = fields.String(required=True)
class Meta(IntegerIDSchema.Meta):
identifier_namespace = 'scientists'
```
Each loading without id generates new auto-increment id:
```python
>>> schema = ScientistSchema()
>>> data, errors = schema.load({'first_name': 'Albert', 'last_name': 'Einstein'})
>>> data.id
1
>>> data, errors = schema.load({'first_name': 'Nicolaus', 'last_name': 'Copernicus'})
>>> data.id
2
```
نیازمندی
| مقدار | نام |
|---|---|
| >=0.0.2 | flask-restive |
| >=1.1.13 | sqlalchemy |
| >=0.32.12 | sqlalchemy-utils |
| >=2.7.3.1 | psycopg2 |
نحوه نصب
نصب پکیج whl Flask-RESTive-Identifiers-0.0.3:
pip install Flask-RESTive-Identifiers-0.0.3.whl
نصب پکیج tar.gz Flask-RESTive-Identifiers-0.0.3:
pip install Flask-RESTive-Identifiers-0.0.3.tar.gz