Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: file object data type #291

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
- id: unasyncd
additional_dependencies: ["ruff"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.9.7"
rev: "v0.9.9"
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion advanced_alchemy/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing_extensions import runtime_checkable

try:
from pydantic import BaseModel # type: ignore # noqa: PGH003
from pydantic import BaseModel # type: ignore

PYDANTIC_INSTALLED = True
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion advanced_alchemy/alembic/templates/asyncio/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config: "AlembicCommandConfig" = context.config # type: ignore # noqa: PGH003
config: "AlembicCommandConfig" = context.config # type: ignore
writer = rewriter.Rewriter()


Expand Down
3 changes: 2 additions & 1 deletion advanced_alchemy/alembic/templates/asyncio/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from typing import TYPE_CHECKING

import sqlalchemy as sa
from alembic import op
from advanced_alchemy.types import EncryptedString, EncryptedText, GUID, ORA_JSONB, DateTimeUTC
from advanced_alchemy.types import EncryptedString, EncryptedText, GUID, ORA_JSONB, DateTimeUTC, ObjectStore
from sqlalchemy import Text # noqa: F401
${imports if imports else ""}
if TYPE_CHECKING:
Expand All @@ -25,6 +25,7 @@ sa.DateTimeUTC = DateTimeUTC
sa.ORA_JSONB = ORA_JSONB
sa.EncryptedString = EncryptedString
sa.EncryptedText = EncryptedText
as.ObjectStore = ObjectStore

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
Expand Down
2 changes: 1 addition & 1 deletion advanced_alchemy/alembic/templates/sync/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config: "AlembicCommandConfig" = context.config # type: ignore # noqa: PGH003
config: "AlembicCommandConfig" = context.config # type: ignore
writer = rewriter.Rewriter()


Expand Down
3 changes: 2 additions & 1 deletion advanced_alchemy/alembic/templates/sync/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from typing import TYPE_CHECKING

import sqlalchemy as sa
from alembic import op
from advanced_alchemy.types import EncryptedString, EncryptedText, GUID, ORA_JSONB, DateTimeUTC
from advanced_alchemy.types import EncryptedString, EncryptedText, GUID, ORA_JSONB, DateTimeUTC, ObjectStore
from sqlalchemy import Text # noqa: F401
${imports if imports else ""}
if TYPE_CHECKING:
Expand All @@ -25,6 +25,7 @@ sa.DateTimeUTC = DateTimeUTC
sa.ORA_JSONB = ORA_JSONB
sa.EncryptedString = EncryptedString
sa.EncryptedText = EncryptedText
as.ObjectStore = ObjectStore

# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
Expand Down
3 changes: 2 additions & 1 deletion advanced_alchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from advanced_alchemy.mixins import (
UUIDv7PrimaryKey as _UUIDv7PrimaryKey,
)
from advanced_alchemy.types import GUID, DateTimeUTC, JsonB
from advanced_alchemy.types import GUID, DateTimeUTC, JsonB, ObjectStore, StoredObject
from advanced_alchemy.utils.dataclass import DataclassProtocol
from advanced_alchemy.utils.deprecation import warn_deprecation

Expand Down Expand Up @@ -291,6 +291,7 @@ def create_registry(
dict[str, Any]: JsonB,
dict[str, str]: JsonB,
DataclassProtocol: JsonB,
StoredObject: ObjectStore,
}
with contextlib.suppress(ImportError):
from pydantic import AnyHttpUrl, AnyUrl, EmailStr, IPvAnyAddress, IPvAnyInterface, IPvAnyNetwork, Json
Expand Down
4 changes: 2 additions & 2 deletions advanced_alchemy/extensions/litestar/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def generate_field_definitions(cls, model_type: type[DeclarativeBase]) -> Genera
should_skip_descriptor = False
dto_field: Optional[DTOField] = None
if hasattr(orm_descriptor, "property"): # pyright: ignore[reportUnknownArgumentType]
dto_field = orm_descriptor.property.info.get(DTO_FIELD_META_KEY) # pyright: ignore # noqa: PGH003
dto_field = orm_descriptor.property.info.get(DTO_FIELD_META_KEY) # pyright: ignore

# Case 1
is_field_marked_not_private = dto_field and dto_field.mark is not Mark.PRIVATE # pyright: ignore[reportUnknownVariableType,reportUnknownMemberType]
Expand Down Expand Up @@ -358,7 +358,7 @@ def detect_nested_field(cls, field_definition: FieldDefinition) -> bool:

def _detect_defaults(elem: ElementType) -> tuple[Any, Any]:
default: Any = Empty
default_factory: Any = None # pyright:ignore # noqa: PGH003
default_factory: Any = None # pyright:ignore
if sqla_default := getattr(elem, "default", None):
if sqla_default.is_scalar:
default = sqla_default.arg
Expand Down
6 changes: 3 additions & 3 deletions advanced_alchemy/extensions/sanic/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
SANIC_INSTALLED = True
except ModuleNotFoundError: # pragma: no cover
SANIC_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
Extension = type("Extension", (), {}) # type: ignore # noqa: PGH003
Extend = type("Extend", (), {}) # type: ignore # noqa: PGH003
Default = type("Default", (), {}) # type: ignore # noqa: PGH003
Extension = type("Extension", (), {}) # type: ignore
Extend = type("Extend", (), {}) # type: ignore
Default = type("Default", (), {}) # type: ignore
_default = Default()

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions advanced_alchemy/repository/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ async def delete_where(
)
result = await self.session.execute(statement)
row_count = getattr(result, "rowcount", -2)
if sanity_check and row_count >= 0 and len(instances) != row_count: # pyright: ignore # noqa: PGH003
if sanity_check and row_count >= 0 and len(instances) != row_count: # pyright: ignore
# backends will return a -1 if they can't determine impacted rowcount
# only compare length of selected instances to results if it's >= 0
await self.session.rollback()
Expand Down Expand Up @@ -2172,7 +2172,7 @@ async def count(self, statement: Select[Any], **kwargs: Any) -> int:
)
statement = self._filter_statement_by_kwargs(statement, **kwargs)
results = await self.execute(statement)
return results.scalar_one() # type: ignore # noqa: PGH003
return results.scalar_one() # type: ignore

async def list_and_count(
self,
Expand Down
4 changes: 2 additions & 2 deletions advanced_alchemy/repository/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def delete_where(
)
result = self.session.execute(statement)
row_count = getattr(result, "rowcount", -2)
if sanity_check and row_count >= 0 and len(instances) != row_count: # pyright: ignore # noqa: PGH003
if sanity_check and row_count >= 0 and len(instances) != row_count: # pyright: ignore
# backends will return a -1 if they can't determine impacted rowcount
# only compare length of selected instances to results if it's >= 0
self.session.rollback()
Expand Down Expand Up @@ -2169,7 +2169,7 @@ def count(self, statement: Select[Any], **kwargs: Any) -> int:
)
statement = self._filter_statement_by_kwargs(statement, **kwargs)
results = self.execute(statement)
return results.scalar_one() # type: ignore # noqa: PGH003
return results.scalar_one() # type: ignore

def list_and_count(
self,
Expand Down
8 changes: 4 additions & 4 deletions advanced_alchemy/repository/memory/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ def _apply_filters(
)

elif isinstance(filter_, NotInCollectionFilter):
if filter_.values is not None: # pyright: ignore # noqa: PGH003
result = self._filter_not_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore # noqa: PGH003
if filter_.values is not None: # pyright: ignore
result = self._filter_not_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore
elif isinstance(filter_, CollectionFilter):
if filter_.values is not None: # pyright: ignore # noqa: PGH003
result = self._filter_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore # noqa: PGH003
if filter_.values is not None: # pyright: ignore
result = self._filter_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore
elif isinstance(filter_, OrderBy):
result = self._order_by(
result,
Expand Down
8 changes: 4 additions & 4 deletions advanced_alchemy/repository/memory/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ def _apply_filters(
)

elif isinstance(filter_, NotInCollectionFilter):
if filter_.values is not None: # pyright: ignore # noqa: PGH003
result = self._filter_not_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore # noqa: PGH003
if filter_.values is not None: # pyright: ignore
result = self._filter_not_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore
elif isinstance(filter_, CollectionFilter):
if filter_.values is not None: # pyright: ignore # noqa: PGH003
result = self._filter_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore # noqa: PGH003
if filter_.values is not None: # pyright: ignore
result = self._filter_in_collection(result, filter_.field_name, filter_.values) # pyright: ignore
elif isinstance(filter_, OrderBy):
result = self._order_by(
result,
Expand Down
5 changes: 5 additions & 0 deletions advanced_alchemy/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
FernetBackend,
PGCryptoBackend,
)
from advanced_alchemy.types.file_object import FSSPEC_INSTALLED, ObjectStore, StoredObject
from advanced_alchemy.types.guid import GUID, NANOID_INSTALLED, UUID_UTILS_INSTALLED
from advanced_alchemy.types.identity import BigIntIdentity
from advanced_alchemy.types.json import ORA_JSONB, JsonB

__all__ = (
"FSSPEC_INSTALLED",
"GUID",
"NANOID_INSTALLED",
"ORA_JSONB",
Expand All @@ -22,5 +24,8 @@
"EncryptionBackend",
"FernetBackend",
"JsonB",
"ObjectStore",
"ObjectStore",
"PGCryptoBackend",
"StoredObject",
)
Loading
Loading