class Book(SqlAlchemyObjectType):
        __model__ = BookRecord

        id = column_field(BookRecord.c_id)
        title = column_field(BookRecord.c_title)
        author_id_1 = column_field(BookRecord.c_author_id_1)
        author_id_2 = column_field(BookRecord.c_author_id_2)
class Author(SqlAlchemyObjectType):
    __model__ = AuthorRecord

    id = column_field(AuthorRecord.c_id)
    name = column_field(AuthorRecord.c_name)
    books = many(lambda: sql_join(Book))
    book_titles = extract(books, "title")
Exemple #3
0
    class Book(SqlAlchemyObjectType):
        __model__ = BookRecord

        id = column_field(BookRecord.id)
        title = column_field(BookRecord.title)
        genre = column_field(BookRecord.genre)
        author_id = column_field(BookRecord.author_id)
        author = single(lambda: sql_join(Author))
    class Author(SqlAlchemyObjectType):
        __model__ = AuthorRecord

        @staticmethod
        def __primary_key__():
            return [AuthorRecord.c_name]

        id = column_field(AuthorRecord.c_id, internal=True)
        name = column_field(AuthorRecord.c_name)
    class Author(SqlAlchemyObjectType):
        __model__ = AuthorRecord

        id_1 = column_field(AuthorRecord.c_id_1)
        id_2 = column_field(AuthorRecord.c_id_2)
        name = column_field(AuthorRecord.c_name)
        books = many(lambda: sql_join(Book,
                                      join={
                                          Author.id_1: Book.author_id_1,
                                          Author.id_2: Book.author_id_2,
                                      }))
    class Label(SqlAlchemyObjectType):
        __model__ = LabelRecord

        @classmethod
        def __select_all__(cls):
            return super(Label, cls).__select_all__() \
                .distinct(LabelRecord.c_label) \
                .order_by(LabelRecord.c_label, LabelRecord.c_id.desc())

        id = column_field(LabelRecord.c_id)
        label = column_field(LabelRecord.c_label)
class Book(SqlAlchemyObjectType):
    __model__ = BookRecord

    id = column_field(column=BookRecord.c_id)
    title = column_field(column=BookRecord.c_title)
    author_id = column_field(column=BookRecord.c_author_id)
    author = single(lambda: sql_join(Author))
    books_by_same_author = extract(author, "books")

    sales = single(
        lambda: sql_value_join(Sales, {Book.title: Sales.book_title}))
    class Label(SqlAlchemyObjectType):
        __model__ = LabelRecord

        @classmethod
        def __select_all__(cls):
            two_values = sqlalchemy.orm.Query(
                sqlalchemy.union(
                    sqlalchemy.select([1]),
                    sqlalchemy.select([2]),
                )).subquery()

            return super(Label, cls).__select_all__() \
                .join(two_values, sqlalchemy.literal(True))

        id = column_field(LabelRecord.c_id)
        label = column_field(LabelRecord.c_label)
    class Author(SqlAlchemyObjectType):
        __model__ = AuthorRecord

        id = column_field(AuthorRecord.c_id)
        name = column_field(AuthorRecord.c_name)

        @staticmethod
        def _author_to_books(author_query, book_query):
            authors = author_query.add_columns(AuthorRecord.c_id).subquery()
            return book_query \
                .join(authors, authors.c.c_id == BookRecord.c_author_id)

        books = many(lambda: select(
            Book,
            join_query=Author._author_to_books,
            join_fields={Author.id: Book.author_id},
        ))
        class Book(SqlAlchemyObjectType):
            __model__ = BookRecord

            id = column_field(BookRecord.c_id)
            author_id = column_field(BookRecord.c_author_id)
        class Author(SqlAlchemyObjectType):
            __model__ = AuthorRecord

            id = column_field(AuthorRecord.c_id)
            name = field(type=graphql.GraphQLString)
        class Book(SqlAlchemyObjectType):
            __model__ = BookRecord

            id = column_field(BookRecord.c_id)
            title = field(type=graphql.GraphQLString)
            author_id = column_field(BookRecord.c_author_id)
        class Author(SqlAlchemyObjectType):
            __model__ = AuthorRecord

            id = column_field(AuthorRecord.c_id)
    class Author(SqlAlchemyObjectType):
        __model__ = AuthorRecord

        id = column_field(AuthorRecord.c_id, internal=True)
        name = column_field(AuthorRecord.c_name)
    class Reader(SqlAlchemyObjectType):
        __model__ = ReaderRecord

        id = column_field(PersonRecord.c_id)