coolqlite.to_sql¶
- class coolqlite.to_sql.ToSqlConfig(*, configure_datetime_fns: bool = True)¶
Configure the ToSqlFnRegistry.
- class coolqlite.to_sql.ToSqlFnRegistry(*, config: ToSqlConfig = ToSqlConfig(configure_datetime_fns=True))¶
Dispatch to serializers based on name or type.
Register type-based dispatch as you would a
functools.singledispatch():registry = ToSqlFnRegistry() @registry.register def _handle_int(x: int) -> str: return str(x)
Or register by name:
registry = ToSqlFnRegistry() @registry.add_named("reversed-int") def _reversed_int(x: int) -> str: return str(x).reverse() registry.add_named("upper", str.upper)
- class coolqlite.to_sql.UuidAs(*values)¶
How do you want to serialize a UUID?
Right now only strings are offered, this may be expanded.
- STRING = 'string'¶
coolqlite.to_sql.datetime_¶
Helpers to convert DateTimes to sqlite types.
Function Name |
Default Named Converter |
Accepts |
|---|---|---|
|
AwareDateTime, AwareTime if already UTC |
|
|
AwareDateTime, AwareTime |
|
|
NaiveDateTime, NaiveTime, Date |
|
|
Any of the above |
- coolqlite.to_sql.datetime_.any_temporal_as_iso(temporal: NaiveDateTime | AwareDateTime | Date | NaiveTime | AwareTime, /) str¶
- coolqlite.to_sql.datetime_.aware_as_zulu_string(temporal: AwareDateTime | AwareTime, /) str¶
Serialize an
datetype.AwareDateTimeby adjusting it to UTC, then serializing as an iso-format string with aZat the end.