class ImageTag(Table): id = Column(Integer, primary_key=True, autoincrement=True) tag_id = Column(Integer, foreign_key=ForeignKey(Tag.id)) image_id = Column(Integer, foreign_key=ForeignKey(Image.id)) tag = Relationship(tag_id, Tag.id, load="joined", use_iter=False)
async def test_create_table(db: DatabaseInterface): async with db.get_ddl_session() as sess: await sess.create_table( table_name, Column.with_name("id", Integer(), primary_key=True), Column.with_name("name", String(128)), Column.with_name("balance", Real())) async with db.get_session() as sess: assert await sess.fetch("select * from {}".format(table_name)) is None
class User(Table): id = Column(Integer, primary_key=True, autoincrement=True) joined_at = Column(Timestamp) username = Column(Text, nullable=False, unique=True) email = Column(Text, nullable=False, unique=True) password = Column(Text, nullable=False) posted_images = Relationship(id, "image.poster", load="joined") posted_comments = Relationship(id, "comment.poster", load="joined")
class Image(Table): id = Column(Integer, primary_key=True, autoincrement=True) posted_at = Column(Timestamp) author = Column(Text) source = Column(Text) poster_id = Column(Integer, foreign_key=ForeignKey(User.id)) poster = Relationship(poster_id, User.id, load="joined", use_iter=False) tags = Relationship(id, "imagetag.image_id", load="joined") comments = Relationship(id, "comment.image_id", load="joined")
class Guild(Table): # type: ignore id = Column(BigInt, primary_key=True) cog_blacklist = Column(Text, nullable=True) prefix = Column(Text, nullable=True) crosspost_enabled = Column(Boolean, nullable=True) crosspost_mode = Column(Integer, nullable=True) crosspost_max_pages = Column(Integer, nullable=True) reminder_channel = Column(BigInt, nullable=True)
class Reminder(Table): # type: ignore id = Column(Serial, primary_key=True) guild_id = Column(BigInt) channel_id = Column(BigInt) user_id = Column(BigInt) time = Column(Timestamp) topic = Column(Text)
class Channel(Table): # type: ignore id = Column(BigInt, primary_key=True) guild_id = Column(BigInt, primary_key=True) plonked = Column(Boolean, nullable=True)
class Member(Table): # type: ignore guild_id = Column(BigInt, primary_key=True) id = Column(BigInt, primary_key=True) plonked = Column(Boolean, nullable=True)
class Test(table_base()): id = Column(Integer(), primary_key=True) name = Column(String(64)) email = Column(String(64))
class Comment(Table): id = Column(Integer, primary_key=True, autoincrement=True) text = Column(Text) image_id = Column(Integer, foreign_key=ForeignKey(Image.id)) poster = Column(Integer, foreign_key=ForeignKey(User.id))
class Tag(Table): id = Column(Integer, primary_key=True, autoincrement=True) tag = Column(Text, unique=True) images = Relationship(id, "imagetag.tag_id")
async def test_add_column(db: DatabaseInterface): async with db.get_ddl_session() as sess: await sess.add_column(table_name, Column.with_name("age", Integer())) assert await get_num_columns(db) == 4