-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from vipyrsec/better-match-info
Better match info
- Loading branch information
Showing
8 changed files
with
156 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""better-match-information | ||
Revision ID: 587c186d91ee | ||
Revises: 6991bcb18f89 | ||
Create Date: 2024-07-27 19:51:33.408128 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "587c186d91ee" | ||
down_revision = "6991bcb18f89" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("scans", sa.Column("files", postgresql.JSONB(), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("scans", "files") | ||
# ### end Alembic commands ### |
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 |
---|---|---|
|
@@ -132,3 +132,4 @@ omit = [ | |
|
||
[tool.coverage.report] | ||
fail_under = 100 | ||
exclude_also = ["if TYPE_CHECKING:"] |
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 +1,27 @@ | ||
"""Database models.""" | ||
|
||
from typing import Optional, Any, Type | ||
from pydantic import BaseModel | ||
from sqlalchemy import Dialect, TypeDecorator | ||
from sqlalchemy.dialects.postgresql import JSONB | ||
|
||
|
||
class Pydantic[T: BaseModel](TypeDecorator[T]): | ||
"""TypeDecorator to convert between Pydantic models and JSONB.""" | ||
|
||
impl = JSONB | ||
cache_ok = True | ||
|
||
def __init__(self, pydantic_type: Type[T]): | ||
super().__init__() | ||
self.pydantic_type = pydantic_type | ||
|
||
def process_bind_param(self, value: Optional[T], dialect: Dialect) -> dict[str, Any]: | ||
if value: | ||
return value.model_dump() | ||
else: | ||
return {} | ||
|
||
def process_result_value(self, value: Any, dialect: Dialect) -> Optional[T]: | ||
if value: | ||
return self.pydantic_type.model_validate(value) |
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