Merge 89b15dd8b1
into f55aeb96ad
This commit is contained in:
commit
518fb6fd64
26
.travis.yml
26
.travis.yml
|
@ -1,5 +1,27 @@
|
||||||
|
os: linux
|
||||||
language: python
|
language: python
|
||||||
|
sudo: false # faster builds
|
||||||
|
|
||||||
before_install: pip install tox
|
matrix:
|
||||||
|
include:
|
||||||
|
- python: 3.6
|
||||||
|
env: TOXENV=py,devel
|
||||||
|
- python: 3.5
|
||||||
|
env: TOXENV=py,devel
|
||||||
|
- python: 3.4
|
||||||
|
env: TOXENV=py,devel
|
||||||
|
- python: 2.7
|
||||||
|
env: TOXENV=py,devel
|
||||||
|
|
||||||
script: tox
|
install:
|
||||||
|
- pip install tox
|
||||||
|
|
||||||
|
script:
|
||||||
|
- tox
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
=====================
|
|
||||||
Bottle-SQLite
|
Bottle-SQLite
|
||||||
=====================
|
=============
|
||||||
|
|
||||||
.. image:: https://travis-ci.org/bottlepy/bottle-sqlite.png?branch=master
|
[](https://travis-ci.com/alenmeister/bottle-sqlite)
|
||||||
:target: https://travis-ci.org/bottlepy/bottle-sqlite
|
|
||||||
:alt: Build Status - Travis CI
|
|
||||||
|
|
||||||
SQLite is a self-contained SQL database engine that runs locally and does not
|
SQLite is a self-contained SQL database engine that runs locally and does not
|
||||||
require any additional server software or setup. The sqlite3 module is part of the
|
require any additional server software or setup. The sqlite3 module is part of the
|
||||||
|
@ -17,25 +14,24 @@ Once installed, all you have to do is to add a ``db`` keyword argument
|
||||||
(configurable) to route callbacks that need a database connection.
|
(configurable) to route callbacks that need a database connection.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
===============
|
------------
|
||||||
|
|
||||||
Install with one of the following commands::
|
Install with one of the following commands:
|
||||||
|
|
||||||
$ pip install bottle-sqlite
|
$ pip install bottle-sqlite
|
||||||
$ easy_install bottle-sqlite
|
$ easy_install bottle-sqlite
|
||||||
|
|
||||||
or download the latest version from github::
|
or download the latest version from github:
|
||||||
|
|
||||||
$ git clone git://github.com/bottlepy/bottle-sqlite.git
|
$ git clone git://github.com/bottlepy/bottle-sqlite.git
|
||||||
$ cd bottle-sqlite
|
$ cd bottle-sqlite
|
||||||
$ python setup.py install
|
$ python setup.py install
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
===============
|
-----
|
||||||
|
|
||||||
Once installed to an application, the plugin passes an open
|
Once installed to an application, the plugin passes an open `sqlite3.Connection`
|
||||||
:class:`sqlite3.Connection` instance to all routes that require a ``db`` keyword
|
instance to all routes that require a ``db`` keyword argument:
|
||||||
argument::
|
|
||||||
|
|
||||||
import bottle
|
import bottle
|
||||||
|
|
||||||
|
@ -52,29 +48,29 @@ argument::
|
||||||
|
|
||||||
Routes that do not expect a ``db`` keyword argument are not affected.
|
Routes that do not expect a ``db`` keyword argument are not affected.
|
||||||
|
|
||||||
The connection handle is configured so that :class:`sqlite3.Row` objects can be
|
The connection handle is configured so that `sqlite3.Row` objects can be
|
||||||
accessed both by index (like tuples) and case-insensitively by name. At the end of
|
accessed both by index (like tuples) and case-insensitively by name. At the end of
|
||||||
the request cycle, outstanding transactions are committed and the connection is
|
the request cycle, outstanding transactions are committed and the connection is
|
||||||
closed automatically. If an error occurs, any changes to the database since the
|
closed automatically. If an error occurs, any changes to the database since the
|
||||||
last commit are rolled back to keep the database in a consistent state.
|
last commit are rolled back to keep the database in a consistent state.
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
-------------
|
||||||
|
|
||||||
The following configuration options exist for the plugin class:
|
The following configuration options exist for the plugin class:
|
||||||
|
|
||||||
* **dbfile**: Database filename (default: in-memory database).
|
* **dbfile**: Database filename (default: in-memory database)
|
||||||
* **keyword**: The keyword argument name that triggers the plugin (default: 'db').
|
* **keyword**: The keyword argument name that triggers the plugin (default: 'db')
|
||||||
* **autocommit**: Whether or not to commit outstanding transactions at the end of the request cycle (default: True).
|
* **autocommit**: Whether or not to commit outstanding transactions at the end of the request cycle (default: True)
|
||||||
* **dictrows**: Whether or not to support dict-like access to row objects (default: True).
|
* **dictrows**: Whether or not to support dict-like access to row objects (default: True)
|
||||||
|
|
||||||
You can override each of these values on a per-route basis::
|
You can override each of these values on a per-route basis:
|
||||||
|
|
||||||
@app.route('/cache/:item', sqlite={'dbfile': ':memory:'})
|
@app.route('/cache/:item', sqlite={'dbfile': ':memory:'})
|
||||||
def cache(item, db):
|
def cache(item, db):
|
||||||
...
|
...
|
||||||
|
|
||||||
or install two plugins with different ``keyword`` settings to the same application::
|
or install two plugins with different ``keyword`` settings to the same application:
|
||||||
|
|
||||||
app = bottle.Bottle()
|
app = bottle.Bottle()
|
||||||
test_db = bottle.ext.sqlite.Plugin(dbfile='/tmp/test.db')
|
test_db = bottle.ext.sqlite.Plugin(dbfile='/tmp/test.db')
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
'''
|
'''
|
||||||
Bottle-sqlite is a plugin that integrates SQLite3 with your Bottle
|
Bottle-sqlite is a plugin that integrates SQLite3 with your Bottle
|
||||||
application. It automatically connects to a database at the beginning of a
|
application. It automatically connects to a database at the beginning of a
|
||||||
|
@ -102,7 +104,7 @@ class SQLitePlugin(object):
|
||||||
|
|
||||||
# Test if the original callback accepts a 'db' keyword.
|
# Test if the original callback accepts a 'db' keyword.
|
||||||
# Ignore it if it does not need a database handle.
|
# Ignore it if it does not need a database handle.
|
||||||
argspec = inspect.getargspec(_callback)
|
argspec = inspect.getfullargspec(_callback)
|
||||||
if keyword not in argspec.args:
|
if keyword not in argspec.args:
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
|
|
24
tox.ini
24
tox.ini
|
@ -1,22 +1,10 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py27-bottledev,py27-bottle012,py27-bottle011,py27-bottle010,py27-bottle09,py26,py27,py32,py33,pypy
|
envlist =
|
||||||
|
py{36,35,34,27,py}
|
||||||
|
py{36,27}-devel
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps=bottle
|
deps =
|
||||||
commands={envpython} test.py
|
bottle
|
||||||
sitepackages=False
|
|
||||||
|
|
||||||
[testenv:py27-bottle09]
|
devel: https://github.com/bottlepy/bottle/archive/master.zip
|
||||||
deps=bottle>=0.9,<0.10
|
|
||||||
|
|
||||||
[testenv:py27-bottle010]
|
|
||||||
deps=bottle>=0.10,<0.11
|
|
||||||
|
|
||||||
[testenv:py27-bottle011]
|
|
||||||
deps=bottle>=0.11,<0.12
|
|
||||||
|
|
||||||
[testenv:py27-bottle012]
|
|
||||||
deps=bottle>=0.12,<0.13
|
|
||||||
|
|
||||||
[testenv:py27-bottledev]
|
|
||||||
deps=git+https://github.com/defnull/bottle.git#egg=bottle
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user