Skip to content

Commit

Permalink
clean command
Browse files Browse the repository at this point in the history
Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com>
  • Loading branch information
Soldy committed Aug 30, 2024
1 parent cd7f312 commit bb4eeda
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/openPanthera/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@

short_commands = {
'b' : 'build',
'c' : 'clean',
'd' : 'directory',
'm' : 'migrate',
's' : 'show'
}

short_clean_commands = {
'f' : 'function',
'p' : 'procedure',
't' : 'table',
'v' : 'view'
}

short_directory_commands = {
'i' : 'init',
'c' : 'check',
Expand All @@ -75,6 +83,7 @@

short_specific_commands = {
'directory' : short_directory_commands,
'clean' : short_clean_commands,
'build' : short_types,
'migrate' : short_migrate_commands,
'show' : short_show_commands
Expand Down
93 changes: 84 additions & 9 deletions src/openPanthera/mariadblib.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ def show(self, name:str):
'function' : self._showFunctions
}
shows[name]()

def clean(self, name:str):
cleans = {
'function' : self._deleteAllFunctions,
'procedure' : self._deleteAllProcedures,
'table' : self._deleteAllTables,
'view' : self._deleteAllViews
}
cleans[name]()
def initMigrationTable(self):
self._cur.execute(_table_query)

Expand Down Expand Up @@ -147,7 +154,8 @@ def _cleanBuildScript(self, type_:str, file_name_:str):
)
self._conn.commit()

def _showProcedures(self):
def _listProcedures(self):
lista = []
self._cur.execute(
"SHOW PROCEDURE STATUS WHERE db = ?",
[
Expand All @@ -167,10 +175,26 @@ def _showProcedures(self):
collation_connection,
coll
) in self._cur:
lista.append(Name)
return lista
def _showProcedures(self):
for (
Name
) in self._listProcedures():
self._p(f"{Name}")


def _showFunctions(self):
def _deleteProcedure(self, procedure:str):
self._cur.execute(
f"DROP PROCEDURE `{procedure}`;"
)
self._p(f"Delete procedure {procedure}")
self._conn.commit()
def _deleteAllProcedures(self):
for (
Name
) in self._listProcedures():
self._deleteProcedure(Name)
def _listFunctions(self):
lista = []
self._cur.execute(
"SHOW FUNCTION STATUS WHERE db = ?",
[
Expand All @@ -190,19 +214,53 @@ def _showFunctions(self):
collation_connection,
coll
) in self._cur:
lista.append(Name)
return lista
def _showFunctions(self):
for (
Name
) in self._listFunctions():
self._p(f"{Name}")

def _showViews(self):
def _deleteFunction(self, function:str):
self._cur.execute(
f"DROP FUNCTION `{function}`;"
)
self._p(f"Delete function {function}")
self._conn.commit()
def _deleteAllFunctions(self):
for (
Name
) in self._listFunctions():
self._deleteFunction(Name)
def _listViews(self):
lista = []
self._cur.execute(
"SHOW FULL TABLES WHERE Table_Type = 'VIEW'"
)
for (
Name,
Type
) in self._cur:
lista.append(Name)
return lista
def _showViews(self):
for (
Name
) in self._listViews():
self._p(f"{Name}")

def _showTables(self):
def _deleteView(self, table:str):
self._cur.execute(
f"DROP VIEW IF EXISTS `{table}`;",
)
self._p(f"Delete table {table}")
self._conn.commit()
def _deleteAllViews(self):
for (
Name
) in self._listViews():
self._deleteView(Name)
def _listTables(self):
lista = []
self._cur.execute(
"SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'"
)
Expand All @@ -211,5 +269,22 @@ def _showTables(self):
Type
) in self._cur:
if Name != "panthera_migration":
lista.append(Name)
return lista
def _showTables(self):
for (
Name
) in self._listTables():
self._p(f"{Name}")
def _deleteTable(self, table:str):
self._cur.execute(
f"DROP TABLES IF EXISTS `{table}`;",
)
self._p(f"Delete table {table}")
self._conn.commit()
def _deleteAllTables(self):
for (
Name
) in self._listTables():
self._deleteTable(Name)

1 change: 1 addition & 0 deletions src/openPanthera/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, schema:str, ui):
'migrate' : self._migrate.resolv,
'init' : self._init,
'build' : self._mariadb.build,
'clean' : self._mariadb.clean,
'directory': self._directory.resolv,
'show' : self._mariadb.show
}

0 comments on commit bb4eeda

Please sign in to comment.