comparison backend/sqlalchemy/Mapping.py @ 119:04a730f9d07d backend

move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 21 Aug 2011 03:55:16 +0200
parents Mapping.py@25fef7c29c5b
children bb3c851b18b1
comparison
equal deleted inserted replaced
118:0e73adb2dec4 119:04a730f9d07d
1
2 from Feed import Feed
3 from FeedEntry import FeedEntry
4 from Preference import Preference
5 from sqlalchemy import Boolean
6 from sqlalchemy import Column
7 from sqlalchemy import DateTime
8 from sqlalchemy import ForeignKey
9 from sqlalchemy import Integer
10 from sqlalchemy import MetaData
11 from sqlalchemy import String
12 from sqlalchemy import Table
13 from sqlalchemy import Text
14 from sqlalchemy.orm import mapper
15 from sqlalchemy.orm import relation
16
17 mappingDefined = False
18 feedEntryTable = None
19
20 def createMapping(engine):
21 """ Make sure the mapping is defined only once. This is not really needed for the feed updater
22 or the GUI app but comes in handy when working interactively with the system. """
23 global mappingDefined
24 if not mappingDefined:
25 _createMapping(engine)
26 mappingDefined = True
27
28 def _createMapping(engine):
29 metadata = MetaData(engine)
30 metadata.bind = engine
31
32 feedTable = Table("feed", metadata,
33 Column("pk", Integer, primary_key=True),
34 Column("title", String(255), nullable=False),
35 Column("rss_url", String(255), nullable=False),
36 # update interval is specified in minutes
37 Column("update_interval", Integer, nullable=False),
38 Column("next_update", DateTime, nullable=False),
39 # when displaying an entry of this feed, do not display the summary but rather load
40 # the link directly
41 Column("auto_load_entry_link", Boolean, nullable=False),
42 # this is actually a hack: when opening some sites in the QWebView it just crashes.
43 # This setting forces to open an entry's link in the external browser
44 Column("always_open_in_browser", Boolean, nullable=False)
45 )
46
47 global feedEntryTable
48 feedEntryTable = Table("feed_entry", metadata,
49 Column("pk", Integer, primary_key=True),
50 Column("create_timestamp", DateTime, nullable=False),
51 Column("read", Integer, nullable=False),
52
53 Column("id", String(512), nullable=False),
54 Column("link", String(512), nullable=False),
55 Column("title", Text, nullable=False),
56 Column("summary", Text, nullable=False),
57 Column("updated", DateTime),
58 Column("feed_id", Integer, ForeignKey("feed.pk"))
59 )
60
61 preferencesTable = Table("preference", metadata,
62 Column("pk", Integer, primary_key=True),
63 Column("key", String(255), nullable=False),
64 Column("value", String(255), nullable=False)
65 )
66
67 metadata.create_all()
68
69 mapper(FeedEntry, feedEntryTable)
70 mapper(Feed, feedTable,
71 properties = {
72 "entries" : relation(FeedEntry, backref="feed", lazy=True, cascade="delete, delete-orphan")
73 }
74 )
75 mapper(Preference, preferencesTable)