Skip to content

Instantly share code, notes, and snippets.

@avandrevitor
Last active September 28, 2023 01:37
Show Gist options
  • Save avandrevitor/4e196363c4ec19b913aa to your computer and use it in GitHub Desktop.
Save avandrevitor/4e196363c4ec19b913aa to your computer and use it in GitHub Desktop.
Gerador de Dicionário de Dados para Mysql Workbench
--
-- CakeSchema Export
-- Based on DoctrinExport (http://code.google.com/p/mysql-workbench-doctrine-plugin/)
--
-- Testing
-- catalog= grtV.getGlobal("/wb/doc/physicalModels/0/catalog")
-- CakeSchema:writeToClipboard(catalog)
--
-- standard module/plugin functions
--
-- this function is called first by MySQL Workbench core to determine number of plugins in this module and basic plugin info
-- see the comments in the function body and adjust the parameters as appropriate
function getModuleInfo()
return {
name= "DBdoc",
author= "WebMachine Ltda.",
version= "2.0",
implements= "PluginInterface",
functions=
{
"getPluginInfo:l<o@app.Plugin>:", -- don't change this
"writeDBdocToFile:i:o@db.Catalog", -- list all your plugin function names and accepted argument types,
"writeDBdocToClipboard:i:o@db.Catalog" -- keeping the rest unchanged; in this example there's only one
-- function, function name is PluginFunctionName and argument type
-- is db.Catalog
}
}
end
-- helper function to create a descriptor for an argument of a specific type of object
-- you don't need to change here anything
function objectPluginInput(type)
return grtV.newObj("app.PluginObjectInput", {objectStructName= type})
end
-- this function is called by MySQL Workbench core after a successful call to getModuleInfo()
-- to gather information about the plugins in this module and the functions that the plugins expose;
-- a plugin should expose only one function that will handle a menu command for a class of objects
-- see the comments in the function body and adjust the parameters as appropriate
function getPluginInfo()
local l
local plugin
-- create the list of plugins that this module exports
l= grtV.newList("object", "app.Plugin")
-- create a new app.Plugin object for every plugin
plugin= grtV.newObj("app.Plugin", {
name= "wb.catalog.util.writeDBdocToFile", -- plugin namespace
caption= "DBdoc: Write to File", -- plugin textual description (will appear as menu item name)
moduleName= "DBdoc", -- this should be in sync with what you sepcified previously for module
-- name in getModuleInfo()
pluginType= "normal", -- don't change this
moduleFunctionName= "writeDBdocToFile", -- the function that this plugin exposes
inputValues= {objectPluginInput("db.Catalog")}, -- the type of object
rating= 100, -- don't change this
showProgress= 0, -- don't change this
groups= {"Catalog/Utilities", "Menu/Catalog"} -- use "Catalog/Utilities" to show the menu item on the overview page,
-- or "Model/Utilities" to show the menu item on the canvas;
-- the "Menu/*" entries control how the plugin will appear in main menu
-- the possible values for it are "Menu/Model", "Menu/Catalog", "Menu/Objects",
-- "Menu/Database", "Menu/Utilities"
})
-- fixup owner
plugin.inputValues[1].owner= plugin
-- add to the list of plugins
grtV.insert(l, plugin)
plugin= grtV.newObj("app.Plugin", {
name= "wb.catalog.util.writeDBdocToClipboard",
caption= "DBdoc: Copy to Clipboard",
moduleName= "DBdoc",
pluginType= "normal",
moduleFunctionName= "writeDBdocToClipboard",
inputValues= {objectPluginInput("db.Catalog")},
rating= 100,
showProgress= 0,
groups= {"Catalog/Utilities", "Menu/Catalog"}
})
-- fixup owner
plugin.inputValues[1].owner= plugin
-- add to the list of plugins
grtV.insert(l, plugin)
return l
end
-- Print some version information and copyright to the output window
function printVersion()
print("\n\n\nDBdoc v1.0\nCopyright (c) 2011 WebMachine Ltda.");
end
--
-- writeDBdocToClipboard definition
-- @param object catalog
--
function writeDBdocToClipboard(catalog)
printVersion()
local doc = generateDBdoc(catalog)
Workbench:copyToClipboard(doc)
print("\n > DBdoc copied to clipboard")
return 0
end
--
-- writeDBdocToFile definition
-- @param object catalog
--
function writeDBdocToFile(catalog)
printVersion()
local doc = generateDBdoc(catalog);
if (catalog.customData["DBdocExportPath"] ~= nil) then
if (Workbench:confirm("Proceed?", "Do you want to overwrite previously exported file "..catalog.customData["DBdocExportPath"].." ?") == 1) then
DBdocExportPath = catalog.customData["DBdocExportPath"];
else
DBdocExportPath = Workbench:input('Please enter the dictinary export path');
if (DBdocExportPath ~= "") then
-- Try to save the filepath for the next time:
catalog.customData["DBdocExportPath"] = DBdocExportPath;
end
end
else
DBdocExportPath = Workbench:input('Please enter the dictionary export path');
if (DBdocExportPath ~= "") then
-- Try to save the filepath for the next time:
catalog.customData["DBdocExportPath"] = DBdocExportPath;
end
end
if DBdocExportPath ~= '' then
f = io.open(DBdocExportPath, "w");
if (f ~= nil) then
doc = string.gsub(doc, "\r", "")
f.write(f, doc);
f.close(f);
print('\n > dictionary was exported to ' .. DBdocExportPath);
else
print('\n > Could not write file ' .. DBdocExportPath);
end
else
print('\n > dictionary was NOT exported. Path was invalid.');
end
return 0
end
--
-- generate DBdoc class
-- @param object column
-- @return string
--
function generateDBdoc(catalog)
local result = '<!DOCTYPE html>\n'
result = result .. '<html lang="en">\n'
result = result .. '<head> \n'
result = result .. '<meta charset="utf-8"> \n'
result = result .. '<meta http-equiv="X-UA-Compatible" content="IE=edge">\n'
result = result .. '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
result = result .. '<title>Dictionary by Mysql Workbench</title>\n'
result = result .. '<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">\n'
result = result .. "<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->\n"
result = result .. '<!--[if lt IE 9]><script src="http://getbootstrap.com/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->\n'
result = result .. "<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->\n"
result = result .. '<script src="http://getbootstrap.com/assets/js/ie10-viewpor t-bug-workaround.js"></script>\n'
result = result .. "<!-- HTML5 shim and Respond.js IE8 support of HTML5 element s and media queries -->\n"
result = result .. '<!--[if lt IE 9]>\n'
result = result .. '<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5s hiv.min.js"></script>\n'
result = result .. '<script src="https://oss.maxcdn.com/respond/1.4.2/res pond.min.js"></script>\n'
result = result .. '<![endif]-->\n'
result = result .. '</head> \n'
result = result .. '<body>\n'
result = result .. '<div role="navigation" class="navbar navbar-fixed-top navbar-inverse">\n'
result = result .. '<div class="container">\n'
result = result .. '<div class="navbar-header">\n'
result = result .. '<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">\n'
result = result .. '<span class="sr-only">Toggle navigation</span>\n'
result = result .. '<span class="icon-bar"></span>\n'
result = result .. '<span class="icon-bar"></span>\n'
result = result .. '<span class="icon-bar"></span>\n'
result = result .. '</button>\n'
result = result .. '<a class="navbar-brand" href="#">Dictionary</a>\n'
result = result .. '</div>\n'
result = result .. '</div>\n'
result = result .. '</div>\n'
result = result .. '<div class="container" style="margin-top:70px">\n'
result = result .. '<div class="row row-offcanvas row-offcanvas-right">\n'
result = result .. '<div class="col-xs-12 col-sm-9">\n'
result = result .. '<div class="jumbotron"><h2>Dictionary</h2> by Mysql Workbench</div>\n'
for i = 1, grtV.getn(catalog.schemata) do
schema = catalog.schemata[i]
for j = 1, grtV.getn(schema.tables) do
table = schema.tables[j]
result = result .. '<div class="panel panel-default">\n'
result = result .. '<div class="panel-heading"><h3>' .. table.name .. '</h3></div>\n'
result = result .. '<div class="panel-body"><p>' .. table.comment .. '</p></div>\n'
result = result .. '<table class="table table-hover table-bordered ">\n'
result = result .. '<thead><tr>\n'
result = result .. '<th>FIELD</th> \n'
result = result .. '<th>TYPE</th> \n'
result = result .. '<th>NULL</th> \n'
result = result .. '<th>EXTRA</th> \n'
result = result .. '<th>COMMENTS</th> \n'
result = result .. '</tr></thead> \n'
for k = 1, grtV.getn(table.columns) do
col = table.columns[k]
result = result .. '<tbody><tr> \n'
result = result .. ' <td>' .. col.name .. '</td> \n'
result = result .. ' <td>' .. col.formattedType .. '</td> \n'
if (col.isNotNull == 1) then
result = result .. '<td>' .. 'NO' .. '</td> \n'
else
result = result .. ' <td>' .. 'YES' .. '</td> \n'
end
if (col.autoIncrement == 1) then
result = result .. ' <td>' .. 'AUTO_INCREMENT' .. '</td> \n'
else
result = result .. ' <td>' .. ' - ' .. '</td> \n'
end
result = result .. ' <td>' .. col.comment .. '</td> \n'
result = result .. '</tr></tbody>\n'
end
result = result .. '</table>\n'
result = result .. '</div>\n'
end
end
result = result .. '</div>\n'
for i = 1, grtV.getn(catalog.schemata) do
schema = catalog.schemata[i]
result = result .. '<div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">\n'
result = result .. '<div class="list-group">\n'
for j = 1, grtV.getn(schema.tables) do
table = schema.tables[j]
result = result .. '<a href="#'..table.name .. '" class="list-group-item">'.. table.name ..'</a>\n'
end
result = result .. '</div>\n'
result = result .. '</div>\n'
end
result = result .. '</div>\n'
result = result .. '</div>\n'
result = result .. '</body> \n'
result = result .. '</html>'
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment