Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/perdy/apistar-peewee-orm
Peewee integration for API Star
https://github.com/perdy/apistar-peewee-orm
api apistar orm peewee python
Last synced: about 1 month ago
JSON representation
Peewee integration for API Star
- Host: GitHub
- URL: https://github.com/perdy/apistar-peewee-orm
- Owner: perdy
- License: gpl-3.0
- Created: 2018-06-12T08:46:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T14:07:14.000Z (about 6 years ago)
- Last Synced: 2024-10-07T04:42:53.279Z (about 1 month ago)
- Topics: api, apistar, orm, peewee, python
- Language: Python
- Size: 60.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# API Star Peewee ORM
[![Build Status](https://travis-ci.org/PeRDy/apistar-peewee-orm.svg?branch=master)](https://travis-ci.org/PeRDy/apistar-peewee-orm)
[![codecov](https://codecov.io/gh/PeRDy/apistar-peewee-orm/branch/master/graph/badge.svg)](https://codecov.io/gh/PeRDy/apistar-peewee-orm)
[![PyPI version](https://badge.fury.io/py/apistar-peewee-orm.svg)](https://badge.fury.io/py/apistar-peewee-orm)* **Version:** 0.3.6
* **Status:** Production/Stable
* **Author:** José Antonio Perdiguero LópezPeewee integration for API Star.
## Features
This library provides:
* Event hooks to handle **connections** and **commit/rollback** behavior based on exceptions in your views.
* **Migrations** support with a command-line interface to interact with them.## Quick start
Install API Star Peewee ORM:```bash
pip install apistar-peewee-orm
```Create an API Star application adding components and event hooks:
```python
from apistar import App
from apistar_peewee_orm import PeeweeDatabaseComponent, PeeweeTransactionHookroutes = []
components = [
PeeweeDatabaseComponent(url='sqlite://'),
]event_hooks = [
PeeweeTransactionHook(),
]app = App(routes=routes, components=components, event_hooks=event_hooks)
```Your models now should inherit from a base model defined in this library:
```python
import peewee
from apistar_peewee_orm import Modelclass PuppyModel(Model):
name = peewee.CharField()
```## Full Example
```python
import typingimport peewee
from apistar import App, http, Route, types, validators
from apistar_peewee_orm import Model, PeeweeDatabaseComponent, PeeweeTransactionHookclass PuppyModel(Model):
name = peewee.CharField()class PuppyType(types.Type):
id = validators.Integer(allow_null=True, default=None)
name = validators.String()def list_puppies() -> typing.List[PuppyType]:
return [PuppyType(puppy) for puppy in PuppyModel.select()]def create_puppy(puppy: PuppyType, raise_exception: http.QueryParam) -> http.JSONResponse:
if raise_exception:
raise Exceptionmodel = PuppyModel.create(**puppy)
return http.JSONResponse(PuppyType(model), status_code=201)routes = [
Route('/puppy/', 'POST', create_puppy),
Route('/puppy/', 'GET', list_puppies),
]components = [
PeeweeDatabaseComponent(url='sqlite://'),
]event_hooks = [
PeeweeTransactionHook(),
]app = App(routes=routes, components=components, event_hooks=event_hooks)
```## CLI Application
An application will be installed along with this library to provide full support for migrations and some other features
of Peewee and API Star.```
$ apistar-peewee-orm --helpusage: apistar-peewee-orm [-h] [-s SETTINGS] [-q | -v] [--dry-run]
{status,upgrade,downgrade,merge,create} ... [app]positional arguments:
app API Star application path
(.:)optional arguments:
-h, --help show this help message and exit
-s SETTINGS, --settings SETTINGS
Module or object with Clinner settings in format
"package.module[:Object]"
-q, --quiet Quiet mode. No standard output other than executed
application
-v, --verbose Verbose level (This option is additive)
--dry-run Dry run. Skip commands execution, useful to check
which commands will be executed and execution orderCommands:
{status,upgrade,downgrade,merge,create}
status Database migrations and models status.
upgrade Run database migrations sequentially.
downgrade Rollback database migrations sequentially.
merge Merge all migrations into a single one.
create Create a new migration. If a module is provided then
the migration will be automatically generated,
otherwise the migration will be empty.
```