Skip to content

lwzm/pony-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pony-rest

A subset implementation of PostgREST.

You should read PostgREST and PonyORM first.

Install

pip install pony-rest

Example

Edit entities.py:

from pony.orm import *

db = Database()

class Person(db.Entity):
    name = Required(str)
    age = Required(int)
    cars = Set('Car')

class Car(db.Entity):
    make = Required(str)
    model = Required(str)
    owner = Required(Person)

then:

python -m pony_rest

or via wsgi:

gunicorn pony_rest

How to use this server to do CRUD

T=localhost:3333

# create new Person
curl -H 'content-type: application/json' -d '{"name": "foo", "age": 10}' $T/person

# read Person list
curl $T/person

# update Person where id is 1
curl -H 'content-type: application/json' -X PATCH -d '{"age": 10}' "$T/person?id=eq.1"

# delete Person where id is 1
curl -X DELETE "$T/person?id=eq.1"

Connect your database

Install module pyyaml, then create a configure file: database.yaml in your working directory, likes:

provider: sqlite
filename: ":memory:"
create_db: true
create_tables: true

...and see database.yaml in this repo to find more.

Note: only the first block configurations in yaml file is used for database, you could leave the old configurations in next blocks.

Lots TODO...

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages