Conversation
…schemas; remove legacy code; introducing sqlite db for now during development. will move to dockerized-postgres datastore instance later --@iamserda
#1: introducing a file-based RDMS via SQLite. Current model is extremely basic to get things working quickly. Will add both analytics data-table, and more columns to the current shortilink table. #2: streamlined database engine creation and improved error handling; #3L removed unused code and simplified main app initialization --@iamserda
…equest shorti based on its key, will implement just providing the short url and service redirect request using either 301 or 302 to the new resource permanent url. --@iamserda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a major refactor to the backend of the Shorties App, migrating persistent storage from in-memory dictionaries to a SQL database using SQLModel. It also streamlines the API models and endpoints, improves error handling, and updates the Makefile for better developer experience. The most important changes are grouped below:
Database Integration and Models
db_engine_factoryfunction indb.pyto create and manage the SQLModel database engine, with error handling and support for environment-based configuration. (src/app/db/db.py)ShortiLinkSQLModel for storing short links in the database, replacing the previous in-memory dictionary. (src/app/db/models/models.py)API Refactor and Persistence
main.pyto use the database via SQLModel sessions, including:display_allnow fetches all short links from the database.get_urlfetches a short link by key from the database and returns a standardized response model, with improved error handling.create_urlinserts new short links into the database, ensuring unique keys and returning the created record(s). (src/app/main.py) [1] [2] [3] [4]API Models and Schema Updates
URLRequestModel→NewUrlSubmissionModelUrlResponseModel→GetUrlResponseModelGetURLRequestModelfor key-based retrieval requests.src/models/schemas.pytosrc/app/schemas/schemas.py. (src/app/schemas/schemas.py) [1] [2]Makefile Improvements
Makefile) [1] [2]These changes lay the foundation for a more robust, persistent, and maintainable backend, and standardize API interactions for future development.