This repository has been archived by the owner on Oct 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
README
66 lines (46 loc) · 1.5 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
=====================
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.