# Article


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

------------------------------------------------------------------------

<a
href="https://github.com/abdelkareemkobo/seo_rat/blob/main/seo_rat/article.py#L30"
target="_blank" style="float:right; font-size:smaller">source</a>

### insert_article

``` python

def insert_article(
    session:Session, # Active database session
    article:Article, # Article instance to insert
)->Article:

```

*Insert a new article into the database.*

------------------------------------------------------------------------

<a
href="https://github.com/abdelkareemkobo/seo_rat/blob/main/seo_rat/article.py#L41"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_article_by_id

``` python

def get_article_by_id(
    session:Session, # Active database session
    article_id:int, # Article primary key
)->__main__.Article | None:

```

*Get an article by its ID.*

------------------------------------------------------------------------

<a
href="https://github.com/abdelkareemkobo/seo_rat/blob/main/seo_rat/article.py#L49"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_article_by_path

``` python

def get_article_by_path(
    session:Session, # Active database session
    file_path:str, # File path to match
)->__main__.Article | None:

```

*Get an article by its file path.*

------------------------------------------------------------------------

<a
href="https://github.com/abdelkareemkobo/seo_rat/blob/main/seo_rat/article.py#L57"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_articles_by_website

``` python

def get_articles_by_website(
    session:Session, # Active database session
    website_id:int, # Parent website ID
)->list:

```

*Get all articles belonging to a website.*

------------------------------------------------------------------------

<a
href="https://github.com/abdelkareemkobo/seo_rat/blob/main/seo_rat/article.py#L65"
target="_blank" style="float:right; font-size:smaller">source</a>

### delete_article

``` python

def delete_article(
    session:Session, # Active database session
    article_id:int, # Article to delete
)->None:

```

*Delete an article by ID. Raises ValueError if not found.*

------------------------------------------------------------------------

<a
href="https://github.com/abdelkareemkobo/seo_rat/blob/main/seo_rat/article.py#L75"
target="_blank" style="float:right; font-size:smaller">source</a>

### update_article

``` python

def update_article(
    session:Session, # Active database session
    article_id:int, # Article to update
    focus_keyword:str | None=None, # New focus keyword
    secondary_keywords:list[str] | None=None, # New secondary keywords
    target_goal:str | None=None, # New target goal
    url:str | None=None, # New public URL
)->Article:

```

*Update article fields and set last_optimized to now. Raises ValueError
if not found.*

``` python
from fastcore.test import test_eq
from sqlmodel import create_engine, Session, SQLModel
from seo_rat.models import Website
from seo_rat.article import Article
```

``` python
# create a test session
session = get_session()

# insert
article = insert_article(session, Article(
    website_id=1,
    file_path="/tmp/test.md",
    focus_keyword="seo",
    url="https://example.com/test"
))
print("inserted:", article)

# get by id
print("by id:", get_article_by_id(session, article.id))

# get by path
print("by path:", get_article_by_path(session, "/tmp/test.md"))

# get by website
# print("by website:", get_articles_by_website(session, 1))

# update
updated = update_article(session, article.id, focus_keyword="seo tools", target_goal="rank #1")
print("updated:", updated)

# delete
delete_article(session, article.id)
print("deleted, verify gone:", get_article_by_id(session, article.id))
```

    inserted: focus_keyword='seo' id=213 target_goal=None created_at=datetime.datetime(2026, 4, 4, 10, 39, 16, 204615) website_id=1 file_path='/tmp/test.md' url='https://example.com/test' secondary_keywords=None last_optimized=None
    by id: focus_keyword='seo' id=213 target_goal=None created_at=datetime.datetime(2026, 4, 4, 10, 39, 16, 204615) website_id=1 file_path='/tmp/test.md' url='https://example.com/test' secondary_keywords=None last_optimized=None
    by path: focus_keyword='seo' id=213 target_goal=None created_at=datetime.datetime(2026, 4, 4, 10, 39, 16, 204615) website_id=1 file_path='/tmp/test.md' url='https://example.com/test' secondary_keywords=None last_optimized=None
    updated: focus_keyword='seo tools' id=213 target_goal='rank #1' created_at=datetime.datetime(2026, 4, 4, 10, 39, 16, 204615) website_id=1 file_path='/tmp/test.md' url='https://example.com/test' secondary_keywords=None last_optimized=datetime.datetime(2026, 4, 4, 10, 39, 16, 219366)
    deleted, verify gone: None
