Beispiel #1
0
  >>> philosophy.courses['1'].__name__
  u'1'
  >>> philosophy.courses['1'].__parent__ is philosophy.courses
  True
  
"""

from megrok import rdb

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import relation

metadata = rdb.MetaData()

rdb.metadata(metadata)


class Courses(rdb.Container):
    pass


class Department(rdb.Model):
    id = Column('id', Integer, primary_key=True)
    name = Column('name', String(50))
    courses = relation('Course',
                       backref='department',
                       collection_class=Courses)


class Course(rdb.Model):
Beispiel #2
0
 class MyClass(rdb.Model):
     rdb.metadata(rdb.MetaData())
     rdb.tableargs(ForeignKeyConstraint(['id'], ['whah.id']),
                   schema='bar')
     id = Column(Integer, primary_key=True)
Beispiel #3
0
 class MyClass(rdb.Model):
     rdb.metadata(rdb.MetaData())
     rdb.tableargs(schema='bar')
     id = Column(Integer, primary_key=True)
Beispiel #4
0
 class MyClass(rdb.Model):
     rdb.metadata(rdb.MetaData())
     id = Column(Integer, primary_key=True)
Beispiel #5
0
  ...   print key, value.name, value.department.name
  1 Logic Philosophy
  2 Ethics Philosophy
  3 Metaphysics Philosophy
"""

import grok
from megrok import rdb

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import relation

metadata = rdb.MetaData()

rdb.metadata(metadata)


class Courses(rdb.Container):
    pass


class Department(rdb.Model):
    id = Column("id", Integer, primary_key=True)
    name = Column("name", String(50))
    courses = relation("Course", backref="department", collection_class=Courses)


class Course(rdb.Model):
    id = Column("id", Integer, primary_key=True)
    department_id = Column("department_id", Integer, ForeignKey("department.id"))
Beispiel #6
0
class User(rdb.Model):
    rdb.metadata(metadata)
    rdb.table(user_table)