I have some metadata on table and some of the columns and would like
to surface these as docstrings on the mapped class and columns.

If table foo has columns i, j, k with comments 'apple', 'banana',
'pear', respectively,  and the table is mapped via class Foo then I
would like the programmer to do a help(Foo) and see something like:

i()
apple

j()
banana

k()
pear

or whatever the common Python idiom is. I am looking for something
that will work well for interactive work with ipython. In our case,
the comments are MS_Description properties from the
sys.extended_properties table in SQL Server. I searched through the
list archives and see that there has already been some discussion
about providing support for comments in the DDL producerers. Although
I am more interested in the mapper side of things, I can see how
sp_addextendedproperty, sp_updateextendedproperty  could be used to
set the comments as part of the DDL generation.

Since I am code-generating all the alchemy models right now, it seems
reasonable to poke in the comment into the docstring of the class and
the the __doc__ attribute column properties after the mapper()
invocation. Or should one use some magic Python hook to get the value
of the docstring from elsewhere? For reference, I append the a
fragment of the code that retrieves the table and column
MS_Description properties that are widely used by a number of SQL
Server tools.

pjjH




        EXEC ( 'sp_MSforeachdb @command1=''
SELECT
      DB_NAME()                                       AS TABLE_CAT,
      OBJECT_SCHEMA_NAME(major_id)                    AS TABLE_SCHEM,
      OBJECT_NAME(major_id)                           AS TABLE_NAME,
      CASE
      WHEN minor_id = 0
           THEN NULL
      ELSE
           COL_NAME(major_id, minor_id)
      END                                             AS COLUMN_NAME,
      name                                            AS name,
      CONVERT(VARCHAR(max),value)                     AS value
FROM  ?.sys.extended_properties
WHERE name = ''''MS_Description'''''',
@precommand = ''use ?''
) AT FOO
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to