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.Version on the Python side. A NULL in the database will be treated as version 0.0.0.

Parameters:
  • *args – Arguments to the Column constructor.

  • make_version – Function that takes an arbitrary value (which will be a string or None value from the database) and returns a semantic_version.Version object (or None). A default function is supplied, but you can override this to use your own.

  • **kwargs – Arguments to the Column constructor.

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.Version from its input or raises ValueError. If the input is None, returns Version(“0.0.0”).

This is the default function to create a semantic_version.Version from a string (or NULL/None value) retrieved from the database.