Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
facebook
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mautrix
facebook
Commits
db257579
Commit
db257579
authored
4 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'erdnaxeli/fix_sqlite_timezone'
parents
d6157c84
14e48050
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mautrix_facebook/db/message.py
+4
-2
4 additions, 2 deletions
mautrix_facebook/db/message.py
mautrix_facebook/db/types/__init__.py
+30
-0
30 additions, 0 deletions
mautrix_facebook/db/types/__init__.py
with
34 additions
and
2 deletions
mautrix_facebook/db/message.py
+
4
−
2
View file @
db257579
...
@@ -16,11 +16,13 @@
...
@@ -16,11 +16,13 @@
from
typing
import
Optional
,
Iterable
,
List
from
typing
import
Optional
,
Iterable
,
List
from
datetime
import
datetime
from
datetime
import
datetime
from
sqlalchemy
import
Column
,
String
,
DateTime
,
SmallInteger
,
UniqueConstraint
,
and_
from
sqlalchemy
import
Column
,
String
,
SmallInteger
,
UniqueConstraint
,
and_
from
mautrix.types
import
RoomID
,
EventID
from
mautrix.types
import
RoomID
,
EventID
from
mautrix.util.db
import
Base
from
mautrix.util.db
import
Base
from
.types
import
UTCDateTime
class
Message
(
Base
):
class
Message
(
Base
):
__tablename__
=
"
message
"
__tablename__
=
"
message
"
...
@@ -31,7 +33,7 @@ class Message(Base):
...
@@ -31,7 +33,7 @@ class Message(Base):
fb_chat
:
str
=
Column
(
String
(
127
),
nullable
=
True
)
fb_chat
:
str
=
Column
(
String
(
127
),
nullable
=
True
)
fb_receiver
:
str
=
Column
(
String
(
127
),
primary_key
=
True
)
fb_receiver
:
str
=
Column
(
String
(
127
),
primary_key
=
True
)
index
:
int
=
Column
(
SmallInteger
,
primary_key
=
True
,
default
=
0
)
index
:
int
=
Column
(
SmallInteger
,
primary_key
=
True
,
default
=
0
)
date
:
Optional
[
datetime
]
=
Column
(
DateTime
(
timezone
=
True
),
nullable
=
True
)
date
:
Optional
[
datetime
]
=
Column
(
UTC
DateTime
(
timezone
=
True
),
nullable
=
True
)
__table_args__
=
(
UniqueConstraint
(
"
mxid
"
,
"
mx_room
"
,
name
=
"
_mx_id_room
"
),)
__table_args__
=
(
UniqueConstraint
(
"
mxid
"
,
"
mx_room
"
,
name
=
"
_mx_id_room
"
),)
...
...
This diff is collapsed.
Click to expand it.
mautrix_facebook/db/types/__init__.py
0 → 100644
+
30
−
0
View file @
db257579
from
datetime
import
timezone
import
sqlalchemy.types
as
types
class
UTCDateTime
(
types
.
TypeDecorator
):
"""
Decorates the SQLAlchemy DateTime type to work with UTC datetimes.
It supposes we only manipulate UTC datetime. If the timezone is not set when saving or reading
a value, the UTC timezone is set. If a timezone is set, it ensures the datetime is converted to
UTC before saving it.
This is useful when working with SQLite as the SQLalchemy DateTime type loses the timezone
information when saving a datetime on this database.
"""
impl
=
types
.
DateTime
def
process_bind_param
(
self
,
value
,
dialect
):
if
value
is
not
None
:
if
value
.
tzinfo
is
None
:
value
=
value
.
replace
(
tzinfo
=
timezone
.
utc
)
elif
value
.
tzinfo
!=
timezone
.
utc
:
value
=
value
.
astimezone
(
timezone
.
utc
)
return
value
def
process_result_value
(
self
,
value
,
dialect
):
if
value
is
not
None
and
value
.
tzinfo
is
None
:
return
value
.
replace
(
tzinfo
=
timezone
.
utc
)
else
:
return
value
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment