summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'database.py')
-rw-r--r--database.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/database.py b/database.py
new file mode 100644
index 0000000..5202876
--- /dev/null
+++ b/database.py
@@ -0,0 +1,22 @@
+from contextlib import closing
+import MySQLdb
+
+class DatabaseConnection:
+ def __init__(self, conn):
+ self.conn = conn
+
+ def insert_file(self, path, group_id):
+ with closing(self.conn.cursor()) as c:
+ c.execute("insert into `files` (`path`, `group_id`) values (%s, %s)", (path, group_id))
+ self.conn.commit()
+ return c.lastrowid
+
+ def insert_group(self, name, provider, date):
+ with closing(self.conn.cursor()) as c:
+ c.execute("insert into `groups` (`name`, `provider`, `date`) values (%s, %s, %s)", (name, provider, date))
+ self.conn.commit()
+ return c.lastrowid
+
+def get_connection(user, passwd, db):
+ conn = MySQLdb.connect(user=user, passwd=passwd, db=db)
+ return DatabaseConnection(conn)