Database interface#
- class shorty.db.URL(**kwargs)#
Database table to store shortened URLs
- classmethod add(url: str, user_ip: str, force: bool = False) URL #
Adds a stem -> URL mapping
- Parameters:
url – Full URL
user_ip – Creating user’s IP address
force – Add a new mapping even if one exists for the given URL
- Returns:
Added or existing mapping for a given URL
- classmethod find(url: str) URL | None #
Finds a stem for a given URL, if one exists
- Parameters:
url – Full URL
- Returns:
URL if found, None otherwise
- classmethod get(stem: str) URL | None #
Returns saved URL for a given stem
- Parameters:
stem – Shortened URL stem
- Returns:
URL if found
- classmethod hit(stem: str) bool #
Adds an extra hit to the counter for a given URL
- Parameters:
stem – Shortened URL stem
- Returns:
Operation success status