Code Monkey home page Code Monkey logo

bottle-sqlite's People

Contributors

abbbi avatar avelino avatar defnull avatar gumblex avatar iurisilvio avatar sc68cal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bottle-sqlite's Issues

Enable foreign keys when opening the database

Currently, the foreign key enforcement in SQLite is disabled by default, would it be possible to add an option that enable it automatically?

$ sqlite3 
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> pragma foreign_keys;
0

Test this plugin

This plugin was created just as an example, so it does not have tests.

People are using it, it is time to make it stable.

Fix README

I didn't read everything, but it has at least one reference to bottle-extras repository.

DeprecationWarning: Switch to Plugin API v2

I am using bottle v0.12.8 with bottle-sqlite and whenever I start the server I get a warrning:

/usr/local/lib/python2.7/dist-packages/bottle.py:527: DeprecationWarning: Switch to Plugin API v2 and access the Route object directly.
context = self if api > 1 else self._context

TypeError: 'Route' object is not subscriptable

Hello,
I have a problem with this version of bottle-sqlite.
Here is the log :

> ./jereve.py 
Bottle v0.13-dev server starting up (using WSGIRefServer())...
Listening on http://192.168.1.142:8080/
Hit Ctrl-C to quit.

Traceback (most recent call last):
  File "/srv/http/jereve/bottle.py", line 850, in _handle
    return route.call(**args)
  File "/srv/http/jereve/bottle.py", line 194, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/srv/http/jereve/bottle.py", line 491, in call
    return self._make_callback()
  File "/srv/http/jereve/bottle.py", line 518, in _make_callback
    callback = plugin.apply(callback, self)
  File "/srv/http/jereve/bottle_sqlite.py", line 66, in apply
    conf = context['config'].get('sqlite') or {}
TypeError: 'Route' object is not subscriptable
192.168.1.41 - - [26/Mar/2014 22:23:49] "GET / HTTP/1.1" 500 1618

The test script (bottle-sqlite as single bottle-sqlite.py file in the same folder) :

> cat jereve.py
#!/usr/bin/python3

import os
import sys

# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))
# Add the current directory to the sys.path to be able to import bottle etc...
sys.path.append(os.path.dirname(__file__))

# using "bottle" web framework
from bottle import get, install, template, run
import bottle_sqlite

plugin = bottle_sqlite.Plugin(dbfile='user_list.db')
install(plugin)

@get('/')
def index():
    return template('index', texts='text');

run(host='192.168.1.142', port=8080, debug=True, reloader=True)

bottle version : last from git
bottle-sqlite version : last from git, just modified to work with python 3 (here is the modified version (lines 89, 92 and 94) : https://github.com/Mageti/bottle-sqlite/blob/master/bottle_sqlite.py)
python version : 3.2.3
OS : Debian 7 i686

Plugin fails with decorated views ...

If you implement a decorator like:

@app.route('/secret/:item')
@valid_user()
def secret(item, db):
      ...

The valid_user() plugin will throw an error like

Traceback (most recent call last):
  File "/home/oznt/Software/bottlesession/bottle.py", line 998, in _handle
    out = route.call(**args)
  File "/home/oznt/Software/bottlesession/bottle.py", line 1999, in wrapper
    rv = callback(*a, **ka)
  File "/home/oznt/Software/bottlesession/bottlesession.py", line 48, in check_auth
    return handler(*a, **ka)
TypeError: secret() missing 1 required positional argument: 'db'

Which hides the fact that the check for the keyword db is failing, although, the callable does have
the keyword db.

The reason the check fails, is because _callback is no longer the original function. this is solved in python3.3 with

inspect.signature(callable, *, follow_wrapped=True)

In earlier versions of python you would have to use functools.wraps your original function and check if the callback has the attribute __wrapped__. This will only work for 1 level, if you do :

@app.route('/secret/:item')
@valid_user()
@has_permission()
def secret(item,db):
       ...

you would have to check for callback.__wrapped__.__wrapped__, or for each level of decoration add one __wrapped__.

The solution is to replace the check from:

argspec = inspect.getargspec(_callback)

To

params = inspect.signature(_callback).parameters

if keyword not in params:
    return callback

No support for detect_types

For some time, the sqlite module for Python3 has supported retrieving datetime fields from sqlite as datetime.datetime python objects.

If I do a call via a function direct to the database using the native sqlite module I am returned datetime.datetime objects.

If I do a call to the same function as part of a bottle view via bottle-sqlite, I'm returned strings in the format %Y-%m-%d %H:%M:%S.

It would be ideal if this module returned python datetime() rather than str(). This issue means that I currently have to have two near-identical functions - one that handles the string type and the other that handles the correct type.

syntax error near unexpected token `SQLitePlugin'

Hi guys!

Thank you very much for creating and sharing this project. I'm really excited about the possibilities.

I got the basics working, however I ran into a problem trying to connect to an sqlite3 database. I suspect my problem revolves around improper scope, naming, or something like that.

By the way, I really appreciate that you guys wrote the basic tutorial leaving out stuff like app.@route, etc. and introduce that later on. Personally I find the OO stuff just confusing, and unnecessarily complex for a small project.

Anyway, when trying to implement the sqlite plugin, the examples given all revolve around OO type naming. I tried to convert it, even looked at different examples, including the source, but I still could not get it to work. I keep getting variations of the error in the title.

I first tried this way (minimal example):

# app.py
from bottle import install, request, route, run, static_file, template
from bottle_sqlite import SQLitePlugin

install(SQLitePlugin(dbfile='database.sqlite3'))

Then I try this way:

# app.py
from bottle import install, request, route, run, static_file, template
from bottle.ext import sqlite

install(sqlite.Plugin(dbfile='database.sqlite3'))

But when I launch my app.py I just keep getting variation of:

from: too many arguments
from: too many arguments
./app.py: line 4: syntax error near unexpected token `SQLitePlugin'
./app.py: line 4: `install(SQLitePlugin(dbfile='database.sqlite3'))'

Feature Request: Ability to receive connection not in routes

I like the concept of this plugin, but I found I had to roll my own because I needed a way to get a database connection object (with all of the same settings) in function that do not originate as the route. For example, I had something along the lines of

@route('/special')
def special():
    do_something_special()
    return main()

@route('/')
def main(db):
    content = do_main_stuff_with_db()
    return content

That is just one example. Another one would be if there is something with the DB in the background (say, in a thread that checks the DB occasionally)

Just thought I would suggest this.

Thanks!

Use of route context within apply()

In bottle_sqlite.py, apply() makes use of the route context. It appears (http://bottlepy.org/docs/dev/plugindev.html#route-context) that config, callback, etc. are all attributes - it's not a dictionary as it seems it's being used in apply(). Indeed, If I change, e.g.,

conf = context.['config'].get('sqlite') or {}

to

conf = context.config.get('sqlite') or {}

then it "works". As written, I get: "TypeError: 'Route' object has no attribute 'getitem'"

Perhaps this was an older handling of the route context? I'd be happy to make the code alterations in a pull request, if that would be helpful, but I thought I'd raise the issue, first, in case backward-compatibility was an issue. We could check the type and decide from there. Or we could ask bottle to support this backwards.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.