-
-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prs-fleshgolem-2070: feat: sqlalchemy 2.0 (#2096)
* upgrade sqlalchemy to 2.0 * rewrite all db models to sqla 2.0 mapping api * fix some importing and typing weirdness * fix types of a lot of nullable columns * remove get_ref methods * fix issues found by tests * rewrite all queries in repository_recipe to 2.0 style * rewrite all repository queries to 2.0 api * rewrite all remaining queries to 2.0 api * remove now-unneeded __allow_unmapped__ flag * remove and fix some unneeded cases of "# type: ignore" * fix formatting * bump black version * run black * can this please be the last one. okay. just. okay. * fix repository errors * remove return * drop open API validator --------- Co-authored-by: Sören Busch <[email protected]>
- Loading branch information
1 parent
91cd009
commit 9e77a9f
Showing
86 changed files
with
1,782 additions
and
1,578 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,7 +232,6 @@ def recipe_data(name: str, slug: str, id: str, userId: str, groupId: str) -> dic | |
|
||
|
||
def login(username="[email protected]", password="MyPassword"): | ||
|
||
payload = {"username": username, "password": password} | ||
r = requests.post("http://localhost:9000/api/auth/token", payload) | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .group import * | ||
from .labels import * | ||
from .recipe.recipe import * # type: ignore | ||
from .recipe import * | ||
from .server import * | ||
from .users import * |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
from datetime import datetime | ||
|
||
from sqlalchemy import Column, DateTime, Integer | ||
from sqlalchemy.ext.declarative import as_declarative | ||
from sqlalchemy.orm import declarative_base | ||
from sqlalchemy.orm.session import Session | ||
from sqlalchemy import DateTime, Integer | ||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column | ||
|
||
|
||
@as_declarative() | ||
class Base: | ||
id = Column(Integer, primary_key=True) | ||
created_at = Column(DateTime, default=datetime.now) | ||
update_at = Column(DateTime, default=datetime.now, onupdate=datetime.now) | ||
class SqlAlchemyBase(DeclarativeBase): | ||
id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
created_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.now) | ||
update_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.now, onupdate=datetime.now) | ||
|
||
|
||
class BaseMixins: | ||
""" | ||
`self.update` method which directly passing arguments to the `__init__` | ||
`cls.get_ref` method which will return the object from the database or none. Useful for many-to-many relationships. | ||
""" | ||
|
||
def update(self, *args, **kwarg): | ||
self.__init__(*args, **kwarg) | ||
|
||
@classmethod | ||
def get_ref(cls, match_value: str, match_attr: str | None = None, session: Session | None = None): | ||
match_attr = match_attr or cls.Config.get_attr # type: ignore | ||
|
||
if match_value is None or session is None: | ||
return None | ||
|
||
eff_ref = getattr(cls, match_attr) | ||
|
||
return session.query(cls).filter(eff_ref == match_value).one_or_none() | ||
|
||
|
||
SqlAlchemyBase = declarative_base(cls=Base, constructor=None) |
This file contains 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
This file contains 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
Oops, something went wrong.