Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Sep 5th, 2010 | Syntax: Python | Size: 1.13 KB | Hits: 25 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. #1 create database engine
  2.  
  3. from sqlalchemy import Column, Integer, String
  4. from arabtabs.db import Base
  5.  
  6. class User(Base):
  7.     __tablename__ = 'users'
  8.     id = Column(Integer, primary_key=True)
  9.     alias = Column(Unicode(50), unique=True, nullable = False)
  10.     email = Column(Unicode(120), unique=True, nullable = False)
  11.     pwd =  Column(Unicode(120), unique=True, nullable = False)
  12.  
  13. class Artist(base):
  14.   __tablename__ = 'artists'
  15.   id = Column(Integer, primary_key=True)
  16.   name = Column(UnicodeText, unique=True, nullable=False)
  17.  
  18. class Song(base):
  19.   __tablename__ = 'songs'
  20.   id = Column(Integer, primary_key=True)
  21.   title = Column(Unicode(50), unique=True, nullable=False)
  22.   artist_id = Column(Integer, ForeignKey('artists.id'))
  23.   artist = relationship(Artist, backref="songs")
  24.    
  25.  
  26. class Tab(base):
  27.   __tablename__ = 'tabs'
  28.   id = Column(Integer, primary_key=True)
  29.   text = Column(UnicodeText, unique=True, nullable=False)
  30.   user_id = Column(Integer, ForeignKey('users.id'))
  31.   song_id = Column(Integer, ForeignKey('songs.id'))
  32.   user = relationship(User, backref="tabs")
  33.   song = relationship(Song, backref="tabs")