view Mapping.py @ 28:72dfae865899

better logging when updating feeds, handle entries that have no id
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 29 Apr 2010 07:04:42 +0200
parents 215c34f61e95
children 74481aa49974
line wrap: on
line source


from Feed import Feed
from FeedEntry import FeedEntry
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relation

def createMapping(engine):
    metadata = MetaData(engine)
    
    feedTable = Table("feed", metadata,
        Column("pk", Integer, primary_key=True),
        Column("title", String(255), nullable=False),
        Column("rss_url", String(255), nullable=False)
    )
    
    feedEntryTable = Table("feed_entry", metadata,
        Column("pk", Integer, primary_key=True),
        Column("create_timestamp", DateTime, nullable=False),

        Column("id", String(255), nullable=False),
        Column("link", String(255), nullable=False),
        Column("title", String, nullable=False),
        Column("summary", String, nullable=False),
        Column("updated", DateTime),
        Column("feed_id", Integer, ForeignKey("feed.pk"))
    )

    metadata.create_all()

    mapper(FeedEntry, feedEntryTable)
    mapper(Feed, feedTable,
        properties = {
            "entries" : relation(FeedEntry, backref = "feed")
        }
    )