openlp/openlp/plugins/alerts/lib/db.py

63 lines
2.8 KiB
Python
Raw Normal View History

2010-02-14 13:27:32 +00:00
# -*- coding: utf-8 -*-
2013-07-18 19:28:35 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
2010-02-14 13:27:32 +00:00
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2013-12-24 08:56:50 +00:00
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
2010-02-14 13:27:32 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
"""
2013-04-18 17:17:00 +00:00
The :mod:`db` module provides the database and schema that is the backend for the Alerts plugin.
"""
2010-02-14 13:27:32 +00:00
from sqlalchemy import Column, Table, types
from sqlalchemy.orm import mapper
from openlp.core.lib.db import BaseModel, init_db
2010-02-14 13:27:32 +00:00
2013-04-18 17:17:00 +00:00
2010-02-14 13:27:32 +00:00
class AlertItem(BaseModel):
"""
AlertItem model
2010-02-14 13:27:32 +00:00
"""
pass
2013-04-18 17:17:00 +00:00
def init_schema(url):
"""
Setup the alerts database connection and initialise the database schema
``url``
The database to setup
"""
session, metadata = init_db(url)
2013-08-31 18:17:38 +00:00
alerts_table = Table('alerts', metadata,
Column('id', types.Integer(), primary_key=True),
Column('text', types.UnicodeText, nullable=False))
mapper(AlertItem, alerts_table)
2010-06-12 02:14:18 +00:00
metadata.create_all(checkfirst=True)
return session