fulvia/db.py

31 lines
707 B
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
The bot's database connection class.
"""
import os
import sqlite3
class FulviaDB(object):
"""
Defines a basic interface and some convenience functionsfor the bot's
database.
"""
def __init__(self, config):
path = config.core.db_filename
self.filename = path
def connect(self):
"""Return a raw database connection object."""
return sqlite3.connect(self.filename, timeout=10)
def execute(self, *args, **kwargs):
"""
Execute an arbitrary SQL query against the database.
Returns a cursor object, on which things like `.fetchall()` can be
called per PEP 249.
"""
with self.connect() as conn:
cur = conn.cursor()
return cur.execute(*args, **kwargs)