Written by

Developer - Internal Applications at InterSystems
Question Pravin Barton · Apr 3, 2019

Best way to document a SQL view

I use Documatic a lot to generate class documentation from comments embedded in the code. Is there a good way to create documentation for SQL views as well? Ideally I want to document each column in the view with HTML markup similar to how I document each method of a class with Documatic.

Comments

Vitaliy Serdtsev · Apr 4, 2019

There are two ways to define views, so I'll give you both options:

  1. <FONT COLOR="#000080">/// bla-bla-bla:<ul>
    /// <li>Name - Person's name;</li>
    /// <li>SSN - Person's Social Security number. This is validated using pattern match;</li>
    /// <li>DOB - Person's Date of Birth.</li></ul>
    Class view.Person </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">ClassType </FONT><FONT COLOR="#000000">= view, </FONT><FONT COLOR="#000080">CompileAfter </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#000080">Sample.Person</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">DdlAllowed</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">Not ProcedureBlock</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">ViewQuery </FONT><FONT COLOR="#000000">= { </FONT><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">Name</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">SSN</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">DOB </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">Sample</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Person</FONT><FONT COLOR="#000000">} ]
    {
    

    }</FONT>

  2. /// This sample persistent class represents a person.
    /// <p>Maintenance note: This class is used by some of the bindings samples.
    Class Sample.Person Extends (%Persistent%Populate%XML.Adaptor)
    {
    

    ...

    </FONT><FONT COLOR="#000080">/// bla-bla-bla:<ul> /// <li>Name - Person's name;</li> /// <li>SSN - Person's Social Security number. This is validated using pattern match;</li> /// <li>DOB - Person's Date of Birth.</li></ul> Query </FONT><FONT COLOR="#000000">viewPerson() </FONT><FONT COLOR="#000080">As %SQLQuery </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">SqlView</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#000080">SqlViewName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">viewPerson </FONT><FONT COLOR="#000000">] { </FONT><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">Name</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">SSN</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">DOB </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">Sample</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">Person </FONT><FONT COLOR="#000000">}

    ...

    }</FONT>

Now take a look at these classes from Documatic.
0