Exemple #1
0
class Preference(Table):

    id = orm.PrimaryKey(orm.Integer, autoincrement=True)
    created_at = orm.Column(orm.Timestamp, default=orm.utc_now())
    key = orm.Column(orm.String, length=50)
    type = orm.Column(orm.String, length=50)
    default = orm.Column(orm.Text)
Exemple #2
0
class UserPreference(Table):

    id = orm.PrimaryKey(orm.Integer, autoincrement=True)
    created_at = orm.Column(orm.Timestamp, default=orm.utc_now())
    user_id = orm.ForeignKey(User.id)
    preference_id = orm.ForeignKey(Preference.id)
    value = orm.Column(orm.Text)

    preference = orm.OneToOne(preference_id)
    user = orm.OneToOne('user_preference.user_id')
Exemple #3
0
 def test_column_simple(self):
     from aiorm import orm
     col = orm.Column(lambda: 'type')
     self.assertIsNone(col.model)
     self.assertIsNone(col.name)
     self.assertEqual(col.type, 'type')
     self.assertFalse(col.immutable)
     self.assertFalse(col.nullable)
     self.assertFalse(col.unique)
     self.assertIsNone(col.default_value)
Exemple #4
0
class User(Table):

    id = orm.PrimaryKey(orm.Integer, autoincrement=True)
    created_at = orm.Column(orm.Timestamp, default=orm.utc_now())
    login = orm.Column(orm.String, length=50, unique=True)
    password = orm.Column(orm.String, length=60)
    firstname = orm.Column(orm.String, length=255, nullable=True)
    lastname = orm.Column(orm.String, length=255, nullable=True)
    email = orm.Column(orm.String, length=255, unique=True)
    lang = orm.Column(orm.String, length=2)
    preferences = orm.OneToMany('user_preference.user_id')
    groups = orm.ManyToMany(Group, UserGroup)
Exemple #5
0
    def test_column_all_args(self):
        from aiorm import orm
        type = mock.Mock()

        col = orm.Column('name',
                         lambda: type,
                         immutable=True,
                         nullable=True,
                         unique=True,
                         default='x',
                         foo='bar')
        self.assertEqual(col.name, 'name')
        self.assertEqual(col.type, type)
        self.assertEqual(col.type.foo, 'bar')
        self.assertIsNone(col.model)
        self.assertTrue(col.immutable)
        self.assertTrue(col.nullable)
        self.assertTrue(col.unique)
        self.assertEqual(col.default_value, 'x')
Exemple #6
0
 class Test:
     field1 = orm.PrimaryKey(mock.Mock)
     field2 = orm.PrimaryKey(mock.Mock)
     field3 = orm.Column(mock.Mock)
Exemple #7
0
 class Test:
     field = orm.Column(mock.Mock, immutable=True)
Exemple #8
0
 class Test:
     field = orm.Column(mock.Mock)
Exemple #9
0
class Group(Table):

    id = orm.PrimaryKey(orm.Integer, autoincrement=True)
    created_at = orm.Column(orm.Timestamp, default=orm.utc_now())
    name = orm.Column(orm.String, length=255)
    users = orm.ManyToMany('user', 'user_group')
Exemple #10
0
 class Table:
     id = orm.PrimaryKey(orm.Integer)
     name = orm.Column(orm.String)
     _password = orm.Column('password', orm.String)