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)
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')
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)
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)
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')
class Test: field1 = orm.PrimaryKey(mock.Mock) field2 = orm.PrimaryKey(mock.Mock) field3 = orm.Column(mock.Mock)
class Test: field = orm.Column(mock.Mock, immutable=True)
class Test: field = orm.Column(mock.Mock)
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')
class Table: id = orm.PrimaryKey(orm.Integer) name = orm.Column(orm.String) _password = orm.Column('password', orm.String)