Пример #1
0
def find_all_by_subcategory(category):
    if use_database:
        return get_session().query(Article).filter_by(subcategory=category)
    else:
        return list(
            filter(lambda article: article.subcategory == category,
                   read_from_csv_file()))
Пример #2
0
def save(article):
    if use_database:
        if not contains_article(article):
            get_session()
            get_session().add(article)
            get_session().commit()
    else:
        write_to_db_file([article])
Пример #3
0
def all_articles():
    if use_database:
        return get_session().query(Article).all()
    else:
        return read_from_csv_file()
Пример #4
0
def initialize_db():
    if use_database:
        Base.metadata.create_all(get_engine())
        get_engine()
        get_session()
Пример #5
0
def find_all_by_publication(publication):
    if use_database:
        return get_session().query(Article).filter_by(publication=publication)
    else:
        raise NotImplementedError
Пример #6
0
def find_by_name_and_publication(name, publication):
    if use_database:
        return get_session().query(Article).filter_by(
            name=name, publication=publication).first()
    else:
        raise NotImplementedError
Пример #7
0
def save_all(articles):
    if use_database:
        get_session().add_all(articles)
        get_session().commit()
    else:
        write_to_db_file(articles)
Пример #8
0
def find_all_by_category(category):
    return get_session().query(Article).filter_by(category=category)
Пример #9
0
def close():
    if use_database:
        get_session().close()
    else:
        clear_cache()
Пример #10
0
def all_articles():
    return get_session().query(Article).all()
Пример #11
0
def find_all_by_publication(publication):
    return get_session().query(Article).filter_by(publication=publication)
Пример #12
0
def find_by_name_and_publication(name, publication):
    return get_session().query(Article).filter_by(
        name=name, publication=publication).first()
Пример #13
0
def save_all(articles):
    get_session().add_all(articles)
    get_session().commit()
Пример #14
0
def save(article):
    get_session().add(article)
    get_session().commit()