-- MODIFIED BY @hugoduar local string = require"string" function getModuleInfo() return { name= "Diccionario", -- put your module name here; must be a valid identifier unique among -- all other plugin names author= "@hugoduar", -- put your company name here version= "1.0", -- put module version string in form major.minor implements= "PluginInterface", -- don't change this functions= { "getPluginInfo:l:", -- 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= "Dic: Generar archivo", -- plugin textual description (will appear as menu item name) moduleName= "Diccionario", -- 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= "Dic: Copiar HTML", moduleName= "Diccionario", 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\nDiccionario v1.0\nAutor hugoduar"); end -- -- writeDBdocToClipboard definition -- @param object catalog -- function writeDBdocToClipboard(catalog) printVersion() local doc = generateDBdoc(catalog) Workbench:copyToClipboard(doc) print("\n > Copiado") 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("¿Quieres continuar?", "¿Quieres sobreescribir el archivo? "..catalog.customData["DBdocExportPath"].." ?") == 1) then DBdocExportPath = catalog.customData["DBdocExportPath"]; else DBdocExportPath = Workbench:input('Danos la ruta del archivo'); if (DBdocExportPath ~= "") then -- Try to save the filepath for the next time: catalog.customData["DBdocExportPath"] = DBdocExportPath; end end else DBdocExportPath = Workbench:input('Danos la ruta del archivo'); 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 > El diccionario fue exportado a ' .. DBdocExportPath); else print('\n > No se puede escribrir ' .. DBdocExportPath); end else print('\n > Hubo un error. El directorio es invalido.'); end return 0 end -- -- generate DBdoc class -- @param object column -- @return string -- function generateDBdoc(catalog) local result = ' \n' result = result .. ' \n' result = result .. ' \n' result = result .. ' \n' result = result .. 'Diccionario de datos \n' result = result .. ' \n' result = result .. ' \n' result = result .. ' \n' for i = 1, grtV.getn(catalog.schemata) do schema = catalog.schemata[i] result = result .. '

' .. schema.name .. ' - Diccionario de Datos

\n' for j = 1, grtV.getn(schema.tables) do table = schema.tables[j] result = result .. '

' .. table.name .. '

\n' result = result .. '

' .. table.comment .. '

\n' result = result .. ' \n' result = result .. ' \n' for k = 1, grtV.getn(table.columns) do col = table.columns[k] asteriscos = string.sub(col.comment, 0, 3) if string.sub(col.comment, 0, 3) == '***' then result = result .. ' \n' end result = result .. ' \n' result = result .. ' \n' for k = 1, grtV.getn(table.columns) do col = table.columns[k] if col.formattedType == "VARCHAR(45)" then result = result .. ' \n' elseif col.formattedType == "VARCHAR(60)" then result = result .. ' \n' elseif col.formattedType == "VARCHAR(20)" then result = result .. ' \n' elseif col.formattedType == "VARCHAR(20)" then result = result .. ' \n' elseif col.formattedType == "VARCHAR(200)" then result = result .. ' \n' elseif col.formattedType == "VARCHAR(10)" then result = result .. ' \n' elseif col.formattedType == "DATETIME" then result = result .. ' \n' elseif col.formattedType == "INT" then result = result .. ' \n' else result = result .. ' \n' end end result = result .. ' \n' result = result .. ' \n' result = result .. ' \n' result = result .. '
'.. string.sub(col.comment, 0, 3) ..'
\n' elseif string.sub(col.comment, 0, 2) == '**' then result = result .. '
'.. string.sub(col.comment, 0, 2) ..'
\n' elseif string.sub(col.comment, 0, 1) == '*' then result = result .. '
'.. string.sub(col.comment, 0, 1) ..'
\n' else result = result .. '
NE
\n' end result = result .. col.name .. '
C(45)C(60)C(20)C(20)C(200)C(10)DaI'.. col.formattedType ..'
\n' result = result .. ' \n' end end result = result .. ' \n' result = result .. '' return result end