Skip to main content

A rest query request args parser for peewee orm.

Project description

A rest query request args parser for peewee orm. like no-sql select style.(/?select=id,name,author{*}&id=gte.20&order=id.desc).

Installing

pip install peewee-rest-query

Test

python setup.py test

Usage

Usage:

> from peewee_rest_query import PeeweeQueryBuilder, PeeweeSerializer
> class School(Model):
    id = PrimaryKeyField()
    name = CharField(max_length=100)

> class Author(Model):
    id = PrimaryKeyField()
    name = CharField(max_length=50)
    age = IntegerField(default=0)
    school = ForeignKeyField(School)

> class Book(Model):
    id = PrimaryKeyField()
    name = CharField(max_length=255)
    author = ForeignKeyField(Author)

> args = {
        'select': 'id,name,author{id,name,school{*}}',
        'id': 'gte.20',
        'author.id': 'in.10,20,30,40,50',
        'order': 'id.desc',
        'page': 1,
        'limit': 5
    }
> builder = PeeweeQueryBuilder(Book, args)
> builder.select
[<class '__main__.School'>, <peewee.PrimaryKeyField object>, <peewee.CharField object>, <peewee.PrimaryKeyField object>, <peewee.CharField object>]
> build.where
[<peewee.Expression object>, <peewee.Expression object>]
> builder.order
[<peewee.PrimaryKeyField object>]
> builder.paginate
(1, 5)
> builder.build()
<class '__main__.Book'> SELECT "t3"."id", "t3"."name", "t2"."id", "t2"."name", "t1"."id", "t1"."name" FROM "book" AS t1 INNER JOIN "author" AS t2 ON ("t1"."author_id" = "t2"."id") INNER JOIN "school" AS t3 ON ("t2"."school_id" = "t3"."id") WHERE (("t1"."id" >= ?) AND ("t2"."id" IN (?, ?, ?, ?, ?))) ORDER BY "t1"."id" DESC LIMIT 5 OFFSET 0 [20, 10, 20, 30, 40, 50]

License

MIT

Contacts

Email: huiquanxiong@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peewee-rest-query-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file peewee-rest-query-0.1.0.tar.gz.

File metadata

File hashes

Hashes for peewee-rest-query-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b876d5e32d7b45a6def3f2e5fccfe6544677ac750c054ebfe2292b4da5b6f0c
MD5 c19f4f70c3e9e84fcfd84a72dfa484c0
BLAKE2b-256 01cb05d5f3b43309bf99d94908072440be43abe1716b292a0806a81031178bc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page