annotate backend/sqlalchemy/Database.py @ 124:a4b2077c9603 backend

editing a feed's properties is implemented through the backend now
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 11:02:53 +0200
parents 04a730f9d07d
children 5b131f82057d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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:
diff changeset
1
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 70
diff changeset
2 from sqlalchemy.engine import create_engine
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 70
diff changeset
3 from sqlalchemy.orm import sessionmaker
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:
diff changeset
4 import Mapping
37
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
5 import sys
57
254d5b89a6ca make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 37
diff changeset
6 import util
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:
diff changeset
7
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:
diff changeset
8 # Keep the connection to the database only once. The feed updater and the GUI app will
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:
diff changeset
9 # operate on a single engine/session but this comes in handy for interactive use
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:
diff changeset
10 engine = None
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:
diff changeset
11 SessionMaker = None
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:
diff changeset
12
70
842727971796 have the DB URL as parameter when creating a session and fall back to commandline arguments if no DB URL was passed in
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 57
diff changeset
13 def createSession(databaseUrl=None):
842727971796 have the DB URL as parameter when creating a session and fall back to commandline arguments if no DB URL was passed in
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 57
diff changeset
14 if databaseUrl is None:
842727971796 have the DB URL as parameter when creating a session and fall back to commandline arguments if no DB URL was passed in
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 57
diff changeset
15 databaseUrl = _getDatabaseUrl()
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:
diff changeset
16 initEngine(databaseUrl)
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:
diff changeset
17 Mapping.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:
diff changeset
18 initSessionMaker()
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:
diff changeset
19 return SessionMaker()
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:
diff changeset
20
37
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
21 def _getDatabaseUrl():
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
22 if len(sys.argv) < 2:
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
23 print("Usage: %s <database url>" % (sys.argv[0]))
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
24 sys.exit(1)
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
25 return sys.argv[1]
22214d79ed41 database URL must be given as commandline argument now, no need for creating complicated config files. Add a menu entry for opening the selected article in browser.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
26
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:
diff changeset
27 def initEngine(databaseUrl):
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:
diff changeset
28 global 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:
diff changeset
29 if engine is None:
57
254d5b89a6ca make sqlalchemy logging configurable through the --databaseLogging commandline parameter
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 37
diff changeset
30 verbose = util.databaseLoggingEnabled()
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 70
diff changeset
31 engine = create_engine(databaseUrl, echo=verbose)
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:
diff changeset
32
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:
diff changeset
33 def initSessionMaker():
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:
diff changeset
34 global SessionMaker
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:
diff changeset
35 if SessionMaker is None:
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 70
diff changeset
36 SessionMaker = sessionmaker(bind=engine)