Skip to content

Commit

Permalink
added Cache to models
Browse files Browse the repository at this point in the history
  • Loading branch information
redimp committed Jan 18, 2025
1 parent c843274 commit ac25d26
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion otterwiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from otterwiki.server import db
from datetime import datetime, UTC

__all__ = ['Preferences', 'Drafts']
__all__ = ['Preferences', 'Drafts', 'User', 'Cache']


class TimeStamp(db.types.TypeDecorator):
# thanks to https://mike.depalatis.net/blog/sqlalchemy-timestamps.html
impl = db.types.DateTime
LOCAL_TIMEZONE = datetime.now(UTC).astimezone().tzinfo
cache_ok = True

def process_bind_param(self, value: datetime, dialect):
if value.tzinfo is None:
Expand Down Expand Up @@ -70,3 +71,10 @@ def __repr__(self):
if self.is_admin:
permissions += "A"
return f"<User {self.id} '{self.name} <{self.email}>' {permissions}>"


class Cache(db.Model):
__tablename__ = "cache"
key = db.Column(db.String(64), primary_key=True)
value = db.Column(db.Text)
datetime = db.Column(TimeStamp())

0 comments on commit ac25d26

Please sign in to comment.