Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.
/ bbtornado Public archive
forked from bakkenbaeck/bbtornado

B&B's Tornado+SQLAlchemy convenience.

License

Notifications You must be signed in to change notification settings

Kron-AS/bbtornado

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI

A collection of utilities for writing REST backends with Tornado and SQLAlchemy

This is all tailored to work with Bakken & Bæcks internal frameworks, it will not all make sense outside of it.

This code should work for both python 2.7 and 3.6.

Example

import bbtornado.main

from bbtornado.web import Application
from bbtornado.models import Base, BaseModel
from bbtornado.handlers import BaseHandler

from sqlalchemy import Column, types

class User(Base, BaseModel):
    __tablename__ = 'users'
    id = Column(types.Integer, primary_key=True, autoincrement=True)
    visits = Column(types.Integer, default=0)

class MainHandler(BaseHandler):
    def get(self):
        if self.current_user == None:
            user = User()
            self.db.add(user)
            self.db.commit()
            print('created user', user.id)
            self.current_user = user.id
        else:
            user = self.db.query(User).get(self.current_user)
        self.write("Hello %s!  You've been here %s times before!" % (user.id, user.visits))
        user.visits += 1
        self.db.add(user)
        self.db.commit()
        self.finish()

if __name__ == '__main__':
    bbtornado.main.setup()
    app = Application([
        (r"/", MainHandler)
    ])
    bbtornado.main.main(app)

About

B&B's Tornado+SQLAlchemy convenience.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%