Skip to content
This repository has been archived by the owner on Oct 13, 2018. It is now read-only.

coderbuzz/bottle-peewee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

=====================
Bottle-Peewee
=====================

This plugin simplifies the use of Peewee ORM in your Bottle applications. 
Once installed, all you have to do is to add a ``db`` keyword argument 
(configurable) to route callbacks that need a database connection.

Installation
===============

Install with one of the following commands::

    $ pip install bottle-peewee
    $ easy_install bottle-peewee

or download the latest version from github::

    $ git clone git://github.com/bottlepy/bottle-extras.git
    $ cd bottle-extras/peewee
    $ python setup.py install

Usage
===============

Once installed to an application, the plugin passes an open 
Peewee Database instance to all routes that require a ``db`` keyword 
argument::

	import bottle
	import peewee
	from peewee import *
	from bottle_peewee import Database, Plugin

	app = bottle.Bottle()

	db = Database('db/sample.db', 'peewee.SqliteDatabase', autocommit=False)

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

	class User(BaseModel):
		name = CharField()

	User.create_table(fail_silently=True)

	User.create(name='A')
	User.create(name='B')
	User.create(name='C')

	plugin = Plugin(db)
	app.install(plugin)

	@app.route('/')
	def index(db):
		users = User.select()
		result = "".join(["<li>%s</li>" % user.name for user in users])
		return "Here is:<br><ul>%s</ul>" % result


	if __name__ == '__main__':
	    bottle.debug(True)
	    bottle.run(app, reloader=True)

Routes that do not expect a ``db`` keyword argument are not affected.

About

Bottle-Peewee

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages