GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sqlmodel/sqlmodel/sql/sqltypes.py at main · fastapi/sqlmodel

Expand file tree

/

sqltypes.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
61 lines (49 loc) · 1.97 KB
/

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)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.