<commit_before># torpeewee

[![Build Status](https://travis-ci.org/snower/torpeewee.svg?branch=master)](https://travis-ci.org/snower/torpeewee)

Tornado asynchronous ORM by peewee

# About

torpeewee - Tornado asynchronous ORM by peewee.

# Installation

    pip install torpeewee

# Examples

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

import datetime
from tornado import gen
from tornado.ioloop import IOLoop
from torpeewee import *

db = MySQLDatabase("test", host="127.0.0.1", port=3306, user="root", passwd="<PASSWORD>")

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()

ioloop = IOLoop.instance()

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

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

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

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

@gen.coroutine
def run():
    t = yield Test.select().where(Test.id == 5).first()
    print t

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

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

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

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

    print ""
    print ""

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

    print ""
    print ""

    with (yield db.transaction()) as transaction:
        for i in (yield Test.use(transaction).select().order_by(Test.id.desc()).limit(2)):
            print i.id, i.data

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

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

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

    print ""
    print ""

    yield run_transaction()

ioloop.run_sync(run)
```

# License

torpeewee uses the MIT license, see LICENSE file for the details.
<commit_msg>change readme<commit_after># torpeewee

[![Build Status](https://travis-ci.org/snower/torpeewee.svg?branch=master)](https://travis-ci.org/snower/torpeewee)

Tornado asynchronous ORM by peewee

# About

torpeewee - Tornado asynchronous ORM by peewee.

# Installation

    pip install torpeewee

# Examples

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

import datetime
from tornado.ioloop import IOLoop
from torpeewee import *

db = MySQLDatabase("test", host="127.0.0.1", port=3306, user="root", passwd="<PASSWORD>")

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()

ioloop = IOLoop.instance()

@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()

ioloop.run_sync(run)
```

# License

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

{'fraction_non_alphanumeric': 0.16473988439306358, 'fraction_numerical': 0.011712808031639793, 'mean_word_length': 2.9442111577684464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6213077', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2234, 'n_words': 471}