cardinal_pythonlib.sqlalchemy.semantic_version_coltype
Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).
This file is part of cardinal_pythonlib.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SQLAlchemy column type to hold semantic versions.
- class cardinal_pythonlib.sqlalchemy.semantic_version_coltype.SemanticVersionColType(*args, make_version: ~typing.Callable[[~typing.Any], ~semantic_version.base.Version | None] = <function make_semantic_version>, **kwargs)[source]
Stores semantic versions in the database. Uses
semantic_version.Versionon the Python side. A NULL in the database will be treated as version 0.0.0.- Parameters:
*args¶ – Arguments to the
Columnconstructor.make_version¶ – Function that takes an arbitrary value (which will be a string or
Nonevalue from the database) and returns asemantic_version.Versionobject (orNone). A default function is supplied, but you can override this to use your own.**kwargs¶ – Arguments to the
Columnconstructor.
- process_bind_param(value: Version | None, dialect: Dialect) str | None[source]
Convert parameters on the way from Python to the database.
- process_literal_param(value: Version | None, dialect: Dialect) str | None[source]
Convert literals on the way from Python to the database.
- process_result_value(value: str | None, dialect: Dialect) Version | None[source]
Convert things on the way from the database to Python.
- property python_type: type
The Python type of the object.
- cardinal_pythonlib.sqlalchemy.semantic_version_coltype.make_semantic_version(value: Any) Version | None[source]
Returns a
semantic_version.Versionfrom its input or raisesValueError. If the input isNone, returns Version(“0.0.0”).This is the default function to create a
semantic_version.Versionfrom a string (or NULL/Nonevalue) retrieved from the database.