import sqlite3


def _connection(func):

	"""Decorator to open and close a database connection."""

	def wrapper(*args, **kwargs):

		self = args[0]

		self.conn = sqlite3.connect(self.db_file)
		self.conn.row_factory = sqlite3.Row
		self.cur = self.conn.cursor()

		result = func(*args, **kwargs)

		self.conn.commit()
		self.conn.close()
		self.conn = None
		self.cur = None

		return result

	return wrapper