Skip to main content

torpeewee

Build Status

Tornado and asyncio asynchronous ORM by peewee

About

torpeewee - Tornado and asyncio asynchronous ORM by peewee.

Installation

pip install torpeewee

Examples

# -*- coding: utf-8 -*-
# 16/7/7
# create by: snower

import datetime
import asyncio
from torpeewee import *

db = MySQLDatabase("test", host="127.0.0.1", port=3306, user="root", passwd="123456")

class BaseModel(Model):
    class Meta:
        database = db

class Test(BaseModel):
    id = IntegerField(primary_key= True)
    data = CharField(max_length=64, null=False)
    count = IntegerField(default=0)
    created_at = DateTimeField()
    updated_at = DateTimeField()

@db.transaction()
async def run_transaction(transaction):
    async for i in Test.use(transaction).select().order_by(Test.id.desc()).limit(2):
        print(i.id, i.data)

    print("")
    t = await Test.use(transaction).create(data="test", created_at=datetime.datetime.now(),
                                           updated_at=datetime.datetime.now())
    print(t.id, t.data)

    async for i in Test.select().order_by(Test.id.desc()).limit(2):
        print(i.id, i.data)

    print("")
    for i in (await Test.use(transaction).select().order_by(Test.id.desc()).limit(2)):
        print(i.id, i.data)

async def run():
    t = await Test.select().where(Test.id == 5).first()
    print(t)

    c = await Test.select().where(Test.id > 5).count()
    print(c)

    c = await Test.select().where(Test.id > 5).group_by(Test.data).count()
    print(c)

    for i in (await Test.select().where(Test.id > 5).where(Test.id<=10)):
        print(i.id, i.data)

    async for i in Test.select().order_by(Test.id.desc()).limit(2):
        print(i.id, i.data)
    t = await Test.create(data = "test", created_at=datetime.datetime.now(), updated_at=datetime.datetime.now())
    print(t.id, t.data)
    async for i in Test.select().order_by(Test.id.desc()).limit(2):
        print(i.id, i.data)

    print("")
    print("")

    t = await Test.select().order_by(Test.id.desc()).limit(1)[0]
    print(t.id, t.data, t.count)
    t.count += 1
    await t.save()
    t = await Test.select().order_by(Test.id.desc()).limit(1)[0]
    print(t.id, t.data, t.count)

    print("")
    print("")

    async with await db.transaction() as transaction:
        t = await Test.use(transaction).select().order_by(Test.id.desc()).limit(1)[0]
        print(t.id, t.data, t.count)
        t.count += 1
        await t.use(transaction).save()

        async for i in Test.use(transaction).select().order_by(Test.id.desc()).limit(2):
            print(i.id, i.data)

        print("")
        t = await Test.use(transaction).create(data="test", created_at=datetime.datetime.now(), updated_at=datetime.datetime.now())
        print(t.id, t.data)

        async for i in Test.select().order_by(Test.id.desc()).limit(2):
            print(i.id, i.data)

        print("")
        for i in (await Test.use(transaction).select().order_by(Test.id.desc()).limit(2)):
            print(i.id, i.data)

    print("")
    print("")

    await run_transaction()

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

License

torpeewee uses the MIT license, see LICENSE file for the details.

Metadata

Release files for torpeewee 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torpeewee 1.0.2
File Size Uploaded Provenance
torpeewee-1.0.2.tar.gz 11.5 kB Without provenance Details

Release files / torpeewee-1.0.2.tar.gz

Download URL torpeewee-1.0.2.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3fd2ec13dcb11a89db59cf7881f58537117f4b1f5280e5eab557dc32e6002d39
BLAKE2b-256 checksum
How to use checksums
f693be5b650bb142363644f557d8f2265541cd6d6b084cd4ef45a4ec67913bcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Security for torpeewee 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page