def post(database_connection: Connection) -> Post:
    insert = posts.insert().values(author_name='name',
                                   title='title',
                                   body='body').returning(literal_column('*'))
    cursor = database_connection.execute(insert)
    result = cursor.fetchone()
    return Post(**result)
示例#2
0
def post() -> Post:
    return Post(id=1,
                author_name='Alex',
                title='Test Post',
                body='A longer body for this post',
                created_at=datetime.now(),
                updated_at=datetime.now())
示例#3
0
def post(database_connection: Connection) -> Post:
    insert = posts.insert().values(author_name='name',
                                   title='title',
                                   body='body').returning(literal_column('*'))
    cursor = database_connection.execute(insert)
    row = cursor.fetchone()
    return Post(row['id'], row['author_name'], row['title'], row['body'],
                Timestamp.from_datetime(row['created_at']),
                Timestamp.from_datetime(row['updated_at']))
 def get_post(self, post_id: int) -> Union[Post, None]:
     query = posts.select().where(posts.c.id == post_id)
     cursor = self.__connection.execute(query)
     row = cursor.fetchone()
     if not row:
         return None
     print(Timestamp.from_datetime(row['updated_at']))
     return Post(row['id'], row['author_name'], row['title'], row['body'],
                 Timestamp.from_datetime(row['created_at']),
                 Timestamp.from_datetime(row['updated_at']))
示例#5
0
    def search_posts(self,
                     start_after: Optional[int] = None,
                     end_before: Optional[int] = None) -> List[Post]:
        query = posts.select()

        if start_after:
            query = query.where(posts.c.id > start_after)

        if end_before:
            query = query.where(posts.c.id < end_before)

        cursor = self.__connection.execute(query)
        rows = cursor.fetchall()
        return [Post(**row) for row in rows]
    def search_posts(self,
                     start_after: Optional[int] = None,
                     end_before: Optional[int] = None) -> List[Post]:
        query = posts.select()

        if start_after:
            query = query.where(posts.c.id > start_after)

        if end_before:
            query = query.where(posts.c.id < end_before)

        cursor = self.__connection.execute(query)
        rows = cursor.fetchall()
        return [
            Post(row['id'], row['author_name'], row['title'], row['body'],
                 Timestamp.from_datetime(row['created_at']),
                 Timestamp.from_datetime(row['updated_at'])) for row in rows
        ]
示例#7
0
 def get_post(self, post_id: int) -> Post:
     query = posts.select().where(posts.c.id == post_id)
     cursor = self.__connection.execute(query)
     row = cursor.fetchone()
     return Post(**row)