Hi all,

I'd like to investigate a possible "special" usage/abuse of comments on schema
objects, available for example under PostgreSQL.

In many applications, I use the "info" slot of table's columns to store visual
settings, mainly a "label" and an "hint", something like

    class Player(GloballyUnique, Base):
        """A single person."""

        __tablename__ = 'players'
        "Related table."

        ## Columns

        idplayer = Column(
            intid_t, Sequence('gen_idplayer', optional=True),
            primary_key=True,
            nullable=False,
            info=dict(label=N_('Player ID'),
                      hint=N_('Unique ID of the player.')))
        """Primary key."""

        firstname = Column(
            name_t,
            nullable=False,
            info=dict(label=N_('First name'),
                      hint=N_('First name of the player.')))
        """Player's first name."""

Those strings are then picked up (and possibly translated) by a library[*]
that exposes a SA selectable as a webservice, producing either a "meta
description" of its resultset (that a client app can use to configure a
grid/table/form to display/edit it), or effectively executing the query given
required parameters.

This morning I was asked "would it be possible to use PG `col_description()`
for that, storing the info slot as a JSON string in the database itself,
opening the way of using SA reflection capability instead of an explicit
declaration?". Uhm, what he said!

I spent some time inside SA code, to understand if/where I could hook an
extension to the reflection mechanism that would allow me to fetch such extra
information for each column. It seems that the `Inspector.get_columns()`
declares an "attrs" slot, carrying "optional column attributes", but no
dialect uses it AFAICT.

I could of course tweak/monkey patch the `PGDialect.get_columns()`, but I
wonder if there is a better way hidden somewhere (... it wouldn't be a great
surprise! :-).

What would you suggest?

Thanks for any hint,
ciao, lele.

[*] https://pypi.python.org/pypi/metapensiero.sqlalchemy.proxy
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  |                 -- Fortunato Depero, 1929.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to