FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmodel/sqlmodel/sql/sqltypes.py at codex/ruff-markdown · fastapi/sqlmodel · GitHub
fastapi
sqlmodel
Repository navigation
Code
Issues
1
(1)
Pull requests
52
(52)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmodel
/
sqlmodel
/
sql
/
sqltypes.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (49 loc) · 1.97 KB
Breadcrumbs
sqlmodel
/
sqlmodel
/
sql
/
sqltypes.py
Copy path
File metadata and controls
61 lines (49 loc) · 1.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from
datetime
import
datetime
,
timedelta
,
timezone
from
typing
import
Any
,
cast
from
sqlalchemy
import
types
from
sqlalchemy
.
engine
.
interfaces
import
Dialect
from
sqlalchemy
.
sql
.
operators
import
OperatorType
class
UTCDateTime
(
types
.
TypeDecorator
[
datetime
]):
"""Store aware datetimes and return them in UTC."""
impl
=
types
.
DateTime
cache_ok
=
True
def
__init__
(
self
)
->
None
:
super
().
__init__
(
timezone
=
True
)
def
__repr__
(
self
)
->
str
:
return
"UTCDateTime()"
def
coerce_compared_value
(
self
,
op
:
OperatorType
|
None
,
value
:
Any
)
->
types
.
TypeEngine
[
Any
]:
if
isinstance
(
value
,
timedelta
):
return
types
.
Interval
()
return
self
def
process_bind_param
(
self
,
value
:
datetime
|
None
,
dialect
:
Dialect
)
->
datetime
|
None
:
if
value
is
None
:
return
None
if
value
.
utcoffset
()
is
None
:
raise
ValueError
(
"Datetime values must have timezone information. "
"Use datetime.now(timezone.utc), or annotate the field with "
"NaiveDatetime for naive storage."
)
return
value
.
astimezone
(
timezone
.
utc
)
def
process_result_value
(
self
,
value
:
datetime
|
None
,
dialect
:
Dialect
)
->
datetime
|
None
:
if
value
is
None
:
return
None
if
value
.
utcoffset
()
is
None
:
# Databases without timezone support store UTC without an offset.
return
value
.
replace
(
tzinfo
=
timezone
.
utc
)
return
value
.
astimezone
(
timezone
.
utc
)
class
AutoString
(
types
.
TypeDecorator
):
impl
=
types
.
String
cache_ok
=
True
mysql_default_length
=
255
def
load_dialect_impl
(
self
,
dialect
:
Dialect
)
->
"types.TypeEngine[Any]"
:
impl
=
cast
(
types
.
String
,
self
.
impl
)
if
impl
.
length
is
None
and
dialect
.
name
in
{
"mysql"
,
"mariadb"
}:
return
dialect
.
type_descriptor
(
types
.
String
(
self
.
mysql_default_length
))
return
super
().
load_dialect_impl
(
dialect
)
Back
|
FazBrowse Home
|
New Git URL