Skip to content

Commit

Permalink
Working it
Browse files Browse the repository at this point in the history
  • Loading branch information
horia141 committed Feb 18, 2024
1 parent cab7d82 commit 64e4b6a
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 74 deletions.
11 changes: 2 additions & 9 deletions src/core/jupiter/core/framework/base/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@value
@total_ordering
class Timestamp(AtomicValue[DateTime]):
class Timestamp(AtomicValue[datetime.datetime]):
"""A timestamp in the application."""

the_ts: DateTime
Expand Down Expand Up @@ -68,7 +68,7 @@ class TimestampDatabaseEncoder(RealmEncoder[Timestamp, DatabaseRealm]):
"""An encoder for timestamps in databases."""

def encode(self, value: Timestamp) -> RealmThing:
return value.value
return value.the_ts


class TimestampDatabaseDecoder(RealmDecoder[Timestamp, DatabaseRealm]):
Expand All @@ -80,13 +80,6 @@ def decode(self, value: RealmThing) -> Timestamp:
f"Expected value for {self.__class__} to be datetime or DateTime"
)

if not isinstance(
value, (str, datetime.date, datetime.datetime, Date, DateTime)
):
raise RealmDecodingError(
"Expected timestamp to be string or date or datetime"
)

if isinstance(value, DateTime):
return Timestamp.from_date_and_time(value)
elif isinstance(value, datetime.datetime):
Expand Down
2 changes: 1 addition & 1 deletion src/core/jupiter/core/framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pkgutil
from datetime import date, datetime
from types import ModuleType, UnionType
from typing import Any, TypeGuard, Union, get_args, get_origin
from typing import Any, TypeGuard, Union, get_args, get_origin, ForwardRef

from jupiter.core.framework.entity import Entity
from jupiter.core.framework.primitive import Primitive
Expand Down
6 changes: 6 additions & 0 deletions src/core/jupiter/core/repository/sqlite/connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""The SQLite connection."""
from dataclasses import dataclass
from datetime import datetime
import json
from pathlib import Path
from typing import Final

Expand All @@ -8,6 +10,7 @@
from alembic.config import Config
from jupiter.core.framework.storage import Connection, ConnectionPrepareError
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from pydantic.json import pydantic_encoder


class SqliteConnection(Connection):
Expand All @@ -30,6 +33,9 @@ def __init__(self, config: Config) -> None:
self._sql_engine = create_async_engine(
config.sqlite_db_url,
future=True,
json_serializer=lambda *a, **kw: json.dumps(
*a, **kw, default=pydantic_encoder
),
)

async def prepare(self) -> None:
Expand Down
Loading

0 comments on commit 64e4b6a

Please sign in to comment.