Skip to main content

sqlalchemy and redis for tornado

Project description

tornado-models

sqlalchemy and redis for tornado

Installation

pip install tornado-models

Usage

sqlalchemy

from tornado.web import Application
from tornado_models.sqlalchemy import SQLAlchemy

from my_app.handlers import IndexHandler

app = Application(
    ((r'/', IndexHandler),),
    db=SQLAlchemy(database_url)
 )

##################################

from tornado_models.sqlalchemy import SQLAlchemy

db = SQLAlchemy(url=database_url)

class User(db.Model):
    id = Column(BigInteger, primary_key=True)
    username = Column(String(255), unique=True)

##################################

from tornado_models.sqlalchemy import SessionMixin
from tornado_models import as_future

class NativeCoroutineRequestHandler(SessionMixin, RequestHandler):
    async def get(self):
        with self.db_session() as session:
            count = await as_future(session.query(User).count())

        self.write('{} users so far!'.format(count))

redis

from tornado.web import Application
from tornado_models.redis import Redis

from my_app.handlers import IndexHandler

app = Application(
    ((r'/', IndexHandler),),
    redis=Redis(pool_options(dict(host='localhost', port=6379, db=0)))
 )

##################################

from tornado_models.redis import RedisMixin
from tornado_models import as_future

class NativeCoroutineRequestHandler(RedisMixin, RequestHandler):
    async def get(self):
        with self.redis_session() as session:
            value = await as_future(session.get('key'))

        self.write('redis value is {}!'.format(value))

Demo Project

https://tornado-sqlalchemy.readthedocs.io/en/stable/

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

tornado_models-0.1.3.tar.gz (10.0 kB view details)

Uploaded Source

File details

Details for the file tornado_models-0.1.3.tar.gz.

File metadata

  • Download URL: tornado_models-0.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for tornado_models-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1da7077b1e8fd0f42bd8d1c12cc9b6a7c8589b7976c03c2afdad97b05e26c249
MD5 ce421367a1743ad69ce6ca3f25db871c
BLAKE2b-256 85341d8af626a8b383a4fa9343956da61390acfbed7250727a7b3861ed3d8174

See more details on using hashes here.

Supported by

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