comparison Mapping.py @ 4:e0199f383442

retrieve a feed for the given URL, store entries as feed_entry rows into the database
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 26 Apr 2010 19:33:07 +0200
parents 8a624ee48a74
children bfd47f55d85b
comparison
equal deleted inserted replaced
3:2ac144a98370 4:e0199f383442
1 1
2 from Feed import Feed 2 from Feed import Feed
3 from FeedEntry import FeedEntry
3 from sqlalchemy import Column 4 from sqlalchemy import Column
5 from sqlalchemy import ForeignKey
4 from sqlalchemy import Integer 6 from sqlalchemy import Integer
5 from sqlalchemy import MetaData 7 from sqlalchemy import MetaData
6 from sqlalchemy import String 8 from sqlalchemy import String
7 from sqlalchemy import Table 9 from sqlalchemy import Table
8 from sqlalchemy.orm import mapper 10 from sqlalchemy.orm import mapper
11 from sqlalchemy.orm import relation
9 12
10 def createMapping(engine): 13 def createMapping(engine):
11 metadata = MetaData(engine) 14 metadata = MetaData(engine)
12 15
13 feedTable = Table("feed", metadata, 16 feedTable = Table("feed", metadata,
14 Column("pk", Integer, primary_key=True), 17 Column("pk", Integer, primary_key=True),
15 Column("name", String(255), nullable=False), 18 Column("name", String(255), nullable=False),
16 Column("url", String(255), nullable=False) 19 Column("url", String(255), nullable=False)
17 ) 20 )
21
22 feedEntryTable = Table("feed_entry", metadata,
23 Column("pk", Integer, primary_key=True),
24 Column("id", String(255), nullable=False),
25 Column("url", String(255), nullable=False),
26 Column("title", String, nullable=False),
27 Column("summary", String, nullable=False),
28 Column("feed_id", Integer, ForeignKey("feed.pk"))
29 )
18 30
19 metadata.create_all() 31 metadata.create_all()
20 32
21 mapper(Feed, feedTable) 33 mapper(FeedEntry, feedEntryTable)
34 mapper(Feed, feedTable,
35 properties = {
36 "entries" : relation(FeedEntry, backref = "feed")
37 }
38 )