AscSecTeam / knackered

Scoring Engine API Service
MIT License
0 stars 0 forks source link

add basic sqlite db connection/cursor #7

Closed brettlangdon closed 10 years ago

brettlangdon commented 10 years ago

here is an example of how we could setup sqlite in this application (or any db solution really).

this pull request should not be considered until ticket #6 is resolved and decided on and/or at the very least this code can be used as an example for implementing a different db solution in the future.

from knackered.db import Database

db = Database("example.db")
with db.cursor() as cursor:
    cursor.execute("select * from table")
    for row in cursor:
        print row

or from within flask

from flask import current_app, Blueprint

blueprint = Blueprint("blueprint", __name__)

@blueprint.route("/example")
def example():
    with current_app.config["db"].cursor() as cursor:
        cursor.execute("sql")
        for row in cursor:
            print row