On 07/04/2010 17:47, jmu wrote:

However, the extension is not released yet as I had some problems with
the sqlparse (http://code.google.com/p/python-sqlparse/) limitations
at the time.
Did you consider using SQLAlchemy (SA) instead of raw SQL?

Actually, I didn't.

My use case is about documenting the database from the raw DB creation
script file. But if the SQLAlchemy is able to parse the file as well
(with the nice addition of retrieving the info from actual DB as well)
then certainly I should consider it. Thanks for the tip.
While you can "feed" raw SQL to SA that would not be how one normally uses it.

Wouldn't it be better to document the database itself?

Here a very very very basic script to read the db (defined in dburl) and extract the table definition.

engine = db.sa.create_engine(dburl, encoding='utf8', echo=False)

meta = db.sa.MetaData()
meta.reflect(bind=engine)
for table in reversed(meta.sorted_tables):
    print table
    print 'primary key'
    for key in table.primary_key:
        print key
    print 'foreign keys'
    for key in table.foreign_keys:
        print key
    print 'columns'
    for col in table.columns:
        print col, col.type, col.description

Showing the result of just one table:
conseventit
primary key
conseventit.conseventitid
foreign keys
ForeignKey(u'bottag.bottagid')
ForeignKey(u'consumption.consumptionid')
ForeignKey(u'rating.ratingid')
ForeignKey(u'cbbottle.cbbottleid')
ForeignKey(u'consevent.conseventid')
columns
conseventit.conseventitid FBInteger() conseventitid
conseventit.tagno FBString(length=32, convert_unicode=False, assert_unicode=None) tagno
conseventit.fk_conseventid FBInteger() fk_conseventid
conseventit.fk_cbbottleid FBInteger() fk_cbbottleid
conseventit.fk_bottagid FBInteger() fk_bottagid
conseventit.fk_consumptionid FBInteger() fk_consumptionid
conseventit.created FBDate() created
conseventit.updated FBDate() updated
conseventit.fk_ratingid FBInteger() fk_ratingid

Werner

--
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to