Commit baf8a220 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

git-interface: Support SQLite as database backend

In addition to MySQL, add support for SQLite to the database abstraction
layer. Also, add a new configuration option to select the DBMS.
Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <>
parent f2a6bd20
[database] [database]
dsn_prefix = mysql backend = mysql
host = localhost host = localhost
socket = /var/run/mysqld/mysqld.sock socket = /var/run/mysqld/mysqld.sock
name = AUR name = AUR
import mysql.connector import mysql.connector
import sqlite3
import config import config
class Connection: class Connection:
_conn = None _conn = None
_paramstyle = None
def __init__(self): def __init__(self):
aur_db_host = config.get('database', 'host') aur_db_backend = config.get('database', 'backend')
aur_db_name = config.get('database', 'name')
aur_db_user = config.get('database', 'user') if aur_db_backend == 'mysql':
aur_db_pass = config.get('database', 'password') aur_db_host = config.get('database', 'host')
aur_db_socket = config.get('database', 'socket') aur_db_name = config.get('database', 'name')
aur_db_user = config.get('database', 'user')
self._conn = mysql.connector.connect(host=aur_db_host, aur_db_pass = config.get('database', 'password')
user=aur_db_user, aur_db_socket = config.get('database', 'socket')
passwd=aur_db_pass, self._conn = mysql.connector.connect(host=aur_db_host,
db=aur_db_name, user=aur_db_user,
unix_socket=aur_db_socket, passwd=aur_db_pass,
buffered=True) db=aur_db_name,
self._paramstyle = mysql.connector.paramstyle
elif aur_db_backend == 'sqlite':
aur_db_name = config.get('database', 'name')
self._conn = sqlite3.connect(aur_db_name)
self._paramstyle = sqlite3.paramstyle
raise ValueError('unsupported database backend')
def execute(self, query, params=()): def execute(self, query, params=()):
query = query.replace('%', '%%').replace('?', '%s') if self._paramstyle == 'format':
query = query.replace('%', '%%').replace('?', '%s')
elif self._paramstyle == 'qmark':
raise ValueError('unsupported paramstyle')
cur = self._conn.cursor() cur = self._conn.cursor()
cur.execute(query, params) cur.execute(query, params)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment