--- /dev/null
+import os
+import sqlite3
+
+DATABASE_NAME = 'contacts.db'
+
+
+class SQLite:
+ def __init__(self, basedir):
+ self._path = os.path.join(basedir, DATABASE_NAME)
+ self.conn = None
+ if not os.path.exists(self._path):
+ self.new()
+ else:
+ self.conn = sqlite3.connect(self._path)
+
+ def new(self):
+ """Creates new databse."""
+
+ self.conn = sqlite3.connect(self._path)
+ self.conn.execute("""CREATE TABLE data (user_id int, field_id int, \
+ value str)""")
+ self.conn.execute("""CREATE TABLE field (field_id int, name str)""")
+ self.conn.execute("""CREATE TABLE relation (data_id int, \
+ struct_id int)""")
+ self.conn.execute("""CREATE TABLE struct (id int, name str, \
+ parent_id int)""")
+ self.conn.commit()
+
+ def close(self):
+ """Closes connection with database."""
+
+ self.conn.commit()
+ self.conn.close()
+
+
+if __name__ == "__main__":
+ db = SQLite('/tmp/')
+ db.close()
+
+