Skip to content

Commit

Permalink
show functions
Browse files Browse the repository at this point in the history
Signed-off-by: Soldy <[email protected]>
  • Loading branch information
Soldy committed Aug 18, 2024
1 parent d903236 commit c0521bb
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
13 changes: 11 additions & 2 deletions src/openPanthera/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
short_commands = {
'b' : 'build',
'd' : 'directory',
'm' : 'migrate'
'm' : 'migrate',
's' : 'show'
}

short_directory_commands = {
Expand All @@ -65,10 +66,18 @@
'b' : 'backup'
}

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

short_specific_commands = {
'directory' : short_directory_commands,
'build' : short_types,
'migrate' : short_migrate_commands
'migrate' : short_migrate_commands,
'show' : short_show_commands
}

migrationTypeList = {
Expand Down
1 change: 0 additions & 1 deletion src/openPanthera/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
_log_active = True
_log = []

print(globals())

def _stamp()->int:
return (datetime.now() - datetime(1970, 1, 1)).total_seconds()
Expand Down
94 changes: 82 additions & 12 deletions src/openPanthera/mariadblib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
_config = {}
_inited = False
_conn = ''
_cur = 'hu'

_table_query = """
CREATE TABLE IF NOT EXISTS panthera_migration (
Expand Down Expand Up @@ -52,6 +51,7 @@ def __init__(self, ui, config, directory_):
sys.exit(1)
self._conn.autocommit = True
self._cur = self._conn.cursor()

def _buildScript(self, title_:str)->int:
scripts = self._directory.reader(title_)
utitle = title_[0].upper() + title_[1:]
Expand Down Expand Up @@ -83,15 +83,22 @@ def _buildScript(self, title_:str)->int:
self._p(utitle+' "'+str(script)+'" already done')
return 0

def build(self, name:str)->int:
print(name)
def build(self, name:str):
if name == "destroy":
self._destroyBuildScript()
return self._buildScript(name)

def initMigrationTable(self)->int:

def show(self, name:str):
shows = {
'table' : self._showTables,
'view' : self._showViews,
'procedure' : self._showProcedures,
'function' : self._showFunctions
}
shows[name]()

def initMigrationTable(self):
self._cur.execute(_table_query)
return 0

def _insertBuildScript(self, type_:str, file_name_:str, file_:str)->int:
self._cur.execute(
Expand All @@ -104,8 +111,8 @@ def _insertBuildScript(self, type_:str, file_name_:str, file_:str)->int:
)
)
self._conn.commit()
return 0
def checkExitBuildScript(self, type_, file_name_, file_):

def checkExitBuildScript(self, type_:str, file_name_:str, file_:str)->bool:
self._cur.execute(
"SELECT date FROM panthera_migration WHERE type=? AND file=? AND hash=? AND destroyed = 0",
(
Expand All @@ -118,7 +125,6 @@ def checkExitBuildScript(self, type_, file_name_, file_):
return True
return False


def _destroyBuildScript(self):
self._cur.execute(
"UPDATE panthera_migration SET destroyed = ? WHERE destroyed = ?",
Expand All @@ -128,9 +134,8 @@ def _destroyBuildScript(self):
)
)
self._conn.commit()
return 0

def _cleanBuildScript(self, type_, file_name_):
def _cleanBuildScript(self, type_:str, file_name_:str):
self._cur.execute(
"UPDATE panthera_migration SET destroyed = ? WHERE destroyed = ? AND type = ? AND file = ?",
(
Expand All @@ -141,5 +146,70 @@ def _cleanBuildScript(self, type_, file_name_):
)
)
self._conn.commit()
return 0

def _showProcedures(self):
self._cur.execute(
"SHOW PROCEDURE STATUS WHERE db = ?",
[
self._config.get('database')
]
)
for (
Db,
Name,
Type,
Definer,
Modified,
Created,
Security_type,
Comment,
character_set_client,
collation_connection,
coll
) in self._cur:
self._p(f"{Name}")


def _showFunctions(self):
self._cur.execute(
"SHOW FUNCTION STATUS WHERE db = ?",
[
self._config.get('database')
]
)
for (
Db,
Name,
Type,
Definer,
Modified,
Created,
Security_type,
Comment,
character_set_client,
collation_connection,
coll
) in self._cur:
self._p(f"{Name}")

def _showViews(self):
self._cur.execute(
"SHOW FULL TABLES WHERE Table_Type = 'VIEW'"
)
for (
Name,
Type
) in self._cur:
self._p(f"{Name}")

def _showTables(self):
self._cur.execute(
"SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'"
)
for (
Name,
Type
) in self._cur:
if Name != "panthera_migration":
self._p(f"{Name}")

3 changes: 2 additions & 1 deletion src/openPanthera/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ def __init__(self, schema:str, ui):
'migrate' : self._migrate.resolv,
'init' : self._init,
'build' : self._mariadb.build,
'directory': self._directory.resolv
'directory': self._directory.resolv,
'show' : self._mariadb.show
}

0 comments on commit c0521bb

Please sign in to comment.