Trying to get around the problem of metadata not being bound to an engine.

bzr-revno: 289
This commit is contained in:
Raoul Snyman 2009-01-21 08:52:03 +00:00
parent 4efdc4e274
commit 4071118398
6 changed files with 53 additions and 20 deletions

View File

@ -148,7 +148,7 @@
</Others> </Others>
<MainScript>openlp.pyw</MainScript> <MainScript>openlp.pyw</MainScript>
<Vcs> <Vcs>
<VcsType>Subversion</VcsType> <VcsType>PySvn</VcsType>
<VcsOptions> <VcsOptions>
<dict> <dict>
<key> <key>
@ -220,7 +220,7 @@
</key> </key>
<value> <value>
<list> <list>
<string></string> <string></string>
</list> </list>
</value> </value>
<key> <key>

View File

@ -0,0 +1,33 @@
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley,
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
__all__ = ['session', 'metadata', 'engine']
# SQLAlchemy database engine. Updated by model.init_model()
engine = None
# SQLAlchemy session manager. Updated by model.init_model()
session = None
# Global metadata. If you have multiple databases with overlapping table
# names, you'll need a metadata for each database
metadata = MetaData()

View File

@ -20,22 +20,22 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation
from openlp.plugins.songs.lib.meta import session, metadata, engine
from openlp.plugins.songs.lib.tables import * from openlp.plugins.songs.lib.tables import *
from openlp.plugins.songs.lib.classes import * from openlp.plugins.songs.lib.classes import *
session = None
def init_models(url): def init_models(url):
engine = create_engine(url)
session = scoped_session(sessionmaker(autoflush=True, autocommit=False, session = scoped_session(sessionmaker(autoflush=True, autocommit=False,
bind=create_engine(url))) bind=engine))
metadata.bind = engine
mapper(Author, authors_table)
#mapper(Author, authors_table) mapper(Book, song_books_table)
#mapper(Book, song_books_table) mapper(Song, songs_table,
#mapper(Song, songs_table, properties={'authors': relation(Author, backref='songs',
# properties={'authors': relation(Author, backref='songs', secondary=authors_songs_table),
# secondary=authors_songs_table), 'book': relation(Book, backref='songs'),
# 'book': relation(Book, backref='songs'), 'topics': relation(Topic, backref='songs',
# 'topics': relation(Topic, backref='songs', secondary=songs_topics_table)})
# secondary=songs_topics_table)}) mapper(Topic, topics_table)
#mapper(Topic, topics_table)

View File

@ -17,9 +17,9 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from sqlalchemy import Column, Table, MetaData, ForeignKey, types from sqlalchemy import Column, Table, ForeignKey, types
metadata = MetaData() from openlp.plugins.songs.lib.meta import metadata
# Definition of the "authors" table # Definition of the "authors" table
authors_table = Table('authors', metadata, authors_table = Table('authors', metadata,