2022-07-18 23:59:14 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-06-19 13:20:22 +00:00
|
|
|
class database:
|
2023-03-04 16:12:29 +00:00
|
|
|
def __init__(self, conn, metadata=None):
|
|
|
|
# this is still named "conn" when it is the Session object, TODO: rename
|
2020-06-19 13:20:22 +00:00
|
|
|
self.conn = conn
|
2023-03-04 16:12:29 +00:00
|
|
|
self.metadata = metadata
|
|
|
|
self.credentials_table = metadata.tables["credentials"]
|
|
|
|
self.hosts_table = metadata.tables["hosts"]
|
2020-06-19 13:20:22 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def db_schema(db_conn):
|
|
|
|
db_conn.execute('''CREATE TABLE "credentials" (
|
|
|
|
"id" integer PRIMARY KEY,
|
|
|
|
"username" text,
|
|
|
|
"password" text
|
|
|
|
)''')
|
|
|
|
|
|
|
|
db_conn.execute('''CREATE TABLE "hosts" (
|
|
|
|
"id" integer PRIMARY KEY,
|
|
|
|
"ip" text,
|
|
|
|
"hostname" text,
|
|
|
|
"port" integer
|
|
|
|
)''')
|
2023-03-04 16:12:29 +00:00
|
|
|
|
|
|
|
def clear_database(self):
|
|
|
|
for table in self.metadata.tables:
|
|
|
|
self.conn.query(self.metadata.tables[table]).delete()
|
|
|
|
self.conn.commit()
|