Mercurial > hg > Feedworm
annotate Mapping.py @ 43:12ed8b5fa08c
first system preference: configure app to stat maximized.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 14 May 2010 08:31:46 +0200 |
parents | aaec263f07ca |
children | a8442c3487b5 |
rev | line source |
---|---|
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 from Feed import Feed |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
3 from FeedEntry import FeedEntry |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
4 from Preference import Preference |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 from sqlalchemy import Column |
5
bfd47f55d85b
add the updated date of the feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
4
diff
changeset
|
6 from sqlalchemy import DateTime |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
7 from sqlalchemy import ForeignKey |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 from sqlalchemy import Integer |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 from sqlalchemy import MetaData |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 from sqlalchemy import String |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 from sqlalchemy import Table |
30
ee1432a91141
map the potentially long columns as Text (CLOB) not as String (VARCHAR)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
29
diff
changeset
|
12 from sqlalchemy import Text |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 from sqlalchemy.orm import mapper |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
14 from sqlalchemy.orm import relation |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 |
34
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
16 mappingDefined = False |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
17 |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 def createMapping(engine): |
34
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
19 """ Make sure the mapping is defined only once. This is not really needed for the feed updater |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
20 or the GUI app but comes in handy when working interactively with the system. """ |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
21 global mappingDefined |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
22 if not mappingDefined: |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
23 _createMapping(engine) |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
24 mappingDefined = True |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
25 |
5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
30
diff
changeset
|
26 def _createMapping(engine): |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
27 metadata = MetaData(engine) |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
28 |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
29 feedTable = Table("feed", metadata, |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
30 Column("pk", Integer, primary_key=True), |
7 | 31 Column("title", String(255), nullable=False), |
35
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
32 Column("rss_url", String(255), nullable=False), |
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
33 Column("update_interval", Integer, nullable=False), |
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
34 Column("next_update", DateTime, nullable=False) |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
35 ) |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
36 |
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
37 feedEntryTable = Table("feed_entry", metadata, |
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
38 Column("pk", Integer, primary_key=True), |
6
87317ba41816
add a creation date for the feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
5
diff
changeset
|
39 Column("create_timestamp", DateTime, nullable=False), |
29
74481aa49974
add a read flag for feed entries so they can be marked read
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
7
diff
changeset
|
40 Column("read", Integer, nullable=False), |
6
87317ba41816
add a creation date for the feed entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
5
diff
changeset
|
41 |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
42 Column("id", String(255), nullable=False), |
5
bfd47f55d85b
add the updated date of the feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
4
diff
changeset
|
43 Column("link", String(255), nullable=False), |
30
ee1432a91141
map the potentially long columns as Text (CLOB) not as String (VARCHAR)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
29
diff
changeset
|
44 Column("title", Text, nullable=False), |
ee1432a91141
map the potentially long columns as Text (CLOB) not as String (VARCHAR)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
29
diff
changeset
|
45 Column("summary", Text, nullable=False), |
5
bfd47f55d85b
add the updated date of the feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
4
diff
changeset
|
46 Column("updated", DateTime), |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
47 Column("feed_id", Integer, ForeignKey("feed.pk")) |
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
48 ) |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
49 |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
50 preferencesTable = Table("preference", metadata, |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
51 Column("pk", Integer, primary_key=True), |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
52 Column("key", String(255), nullable=False), |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
53 Column("value", String(255), nullable=False) |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
54 ) |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
55 |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
56 metadata.create_all() |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
57 |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
58 mapper(FeedEntry, feedEntryTable) |
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
59 mapper(Feed, feedTable, |
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
60 properties = { |
35
aaec263f07ca
Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
34
diff
changeset
|
61 "entries" : relation(FeedEntry, backref="feed") |
4
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
62 } |
e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
2
diff
changeset
|
63 ) |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
35
diff
changeset
|
64 mapper(Preference, preferencesTable) |