Exemple #1
0
class RelatedBook(db.Model):  # type: ignore
    # Properties
    id = db.Column(BigIntegerVariantType, primary_key=True,
                   autoincrement=True)  # noqa: E501
    related_book_uuid = db.Column(UUIDType, index=True,
                                  nullable=False)  # noqa: E501
    book1_id = db.Column(db.BigInteger,
                         db.ForeignKey('book.id'),
                         nullable=True)  # noqa: E501
    book2_id = db.Column(db.BigInteger,
                         db.ForeignKey('book.id'),
                         nullable=True)  # noqa: E501

    # Relationships
    book1 = db.relationship(
        'Book',
        lazy=False,
        uselist=False,
        foreign_keys=[book1_id],
    )
    book2 = db.relationship(
        'Book',
        lazy=False,
        uselist=False,
        foreign_keys=[book2_id],
    )

    __table_args__ = (UniqueConstraint('related_book_uuid', ), )
Exemple #2
0
class Author(db.Model):  # type: ignore
    # Properties
    id = db.Column(BigIntegerVariantType, primary_key=True,
                   autoincrement=True)  # noqa: E501
    author_id = db.Column(UUIDType, index=True, nullable=False)  # noqa: E501
    name = db.Column(db.String, index=True, nullable=False)  # noqa: E501
    favourite_author_id = db.Column(db.BigInteger,
                                    db.ForeignKey('author.id'),
                                    nullable=True)  # noqa: E501
    hated_author_id = db.Column(db.BigInteger,
                                db.ForeignKey('author.id'),
                                nullable=True)  # noqa: E501

    # Relationships
    books = db.relationship(
        'Book',
        lazy=False,
        uselist=True,
        foreign_keys='Book.author_id',
    )
    favourite_book = db.relationship(
        'Book',
        lazy=False,
        uselist=False,
        foreign_keys='Book.author_id',
    )
    collaborations = db.relationship(
        'Book',
        lazy=False,
        uselist=True,
        foreign_keys='Book.collaborator_id',
    )
    favourite_of = db.relationship(
        'Author',
        lazy=True,
        uselist=True,
        foreign_keys=[favourite_author_id],
    )
    favourite_author = db.relationship(
        'Author',
        lazy=True,
        uselist=False,
        primaryjoin=id == favourite_author_id,
        remote_side=[id],
    )
    hated_by = db.relationship(
        'Author',
        lazy=True,
        uselist=True,
        foreign_keys=[hated_author_id],
    )
    hated_author = db.relationship(
        'Author',
        lazy=True,
        uselist=False,
        primaryjoin=id == hated_author_id,
        remote_side=[id],
    )

    __table_args__ = (UniqueConstraint('author_id', ), )
Exemple #3
0
class Book(db.Model):  # type: ignore
    # Properties
    id = db.Column(BigIntegerVariantType, primary_key=True,
                   autoincrement=True)  # noqa: E501
    book_id = db.Column(UUIDType, index=True, nullable=False)  # noqa: E501
    name = db.Column(db.String, index=True, nullable=False)  # noqa: E501
    rating = db.Column(db.Float, index=True, nullable=False)  # noqa: E501
    author_id = db.Column(db.BigInteger,
                          db.ForeignKey('author.id'),
                          nullable=True)  # noqa: E501
    collaborator_id = db.Column(db.BigInteger,
                                db.ForeignKey('author.id'),
                                nullable=True)  # noqa: E501
    published = db.Column(db.Date, nullable=True)  # noqa: E501
    created = db.Column(db.DateTime,
                        server_default=text('CURRENT_TIMESTAMP'),
                        nullable=True)  # noqa: E501
    updated = db.Column(db.DateTime,
                        default=datetime.datetime.utcnow,
                        onupdate=datetime.datetime.utcnow,
                        nullable=True)  # noqa: E501

    # Relationships
    author = db.relationship(
        'Author',
        lazy=False,
        uselist=False,
        foreign_keys=[author_id],
    )
    collaborator = db.relationship(
        'Author',
        lazy=False,
        uselist=False,
        foreign_keys=[collaborator_id],
    )
    reviews = db.relationship(
        'Review',
        lazy=True,
        uselist=True,
    )
    genre = db.relationship(
        'Genre',
        lazy=False,
        uselist=False,
        secondary='book_genre',
    )
    related_books = db.relationship(
        'Book',
        lazy=True,
        uselist=True,
        secondary='related_book',
        primaryjoin='Book.id==RelatedBook.book1_id',
        secondaryjoin='Book.id==RelatedBook.book2_id',
    )

    __table_args__ = (UniqueConstraint('book_id', ), )
Exemple #4
0
class Genre(db.Model):  # type: ignore
    # Properties
    id = db.Column(BigIntegerVariantType, primary_key=True,
                   autoincrement=True)  # noqa: E501
    genre_id = db.Column(UUIDType, index=True, nullable=False)  # noqa: E501
    title = db.Column(db.String, nullable=True)  # noqa: E501

    # Relationships
    book = db.relationship(
        'Book',
        lazy=False,
        uselist=True,
        secondary='book_genre',
    )

    __table_args__ = (UniqueConstraint('genre_id', ), )
Exemple #5
0
class BookGenre(db.Model):  # type: ignore
    # Properties
    id =            db.Column(BigIntegerVariantType, primary_key=True, autoincrement=True)  # noqa: E501
    book_genre_id = db.Column(UUIDType, index=True, nullable=False)  # noqa: E501
    book_id =       db.Column(db.BigInteger, db.ForeignKey('book.id'), nullable=True)  # noqa: E501
    genre_id =      db.Column(db.BigInteger, db.ForeignKey('genre.id'), nullable=True)  # noqa: E501

    # Relationships
    book = db.relationship(
        'Book',
        lazy=False,
        uselist=False,
        order_by='Book.id',
        foreign_keys=[book_id],
    )
    genre = db.relationship(
        'Genre',
        lazy=False,
        uselist=False,
        order_by='Genre.id',
        foreign_keys=[genre_id],
    )

    __table_args__ = (UniqueConstraint('book_genre_id', ), )