Commit 447da53a authored by aoh's avatar aoh
Browse files

Update db


Signed-off-by: aoh's avataraoh <aoh@lysator.liu.se>
parent 70f80800
......@@ -14,16 +14,26 @@ class DB():
def __exit__(self, type, value, traceback):
self.connection.close()
def get_user_ids(self):
def get_domain_ids(self):
with self.connection.cursor() as cursor:
cursor.execute('SELECT id FROM domain')
return [item.get("id") for item in cursor.fetchall()]
def get_domain_name(self, id):
with self.connection.cursor() as cursor:
cursor.execute('SELECT name FROM domain WHERE id = %s', id)
return cursor.fetchone().get("name")
def get_subdomain_ids(self, domainid):
with self.connection.cursor() as cursor:
cursor.execute('SELECT id FROM subdomain WHERE domainid = %s', domainid)
return [item.get("id") for item in cursor.fetchall()]
def get_subdomain_name(self, id):
with self.connection.cursor() as cursor:
cursor.execute('SELECT name FROM subdomain WHERE id = %s', id)
return cursor.fetchone().get("name")
def get_key(self, subid):
with self.connection.cursor() as cursor:
cursor.execute('SELECT secret FROM update_key WHERE subid = %s LIMIT 1', subid)
......
......@@ -33,8 +33,10 @@ finally:
print("dump db")
with DB() as d:
for id in d.get_user_ids():
for id in d.get_domain_ids():
print("domain id: ", id)
print("domain name: ", d.get_domain_name(id))
for sid in d.get_subdomain_ids(id):
print("subdomain id: ", sid)
print("domain name: ", d.get_subdomain_name(sid))
print("subdomain secret: ", d.get_key(sid))
Markdown is supported
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