FieldSpec

class lsst.daf.butler.ddl.FieldSpec(name: str, dtype: type, length: int | None = None, nbytes: int | None = None, primaryKey: bool = False, autoincrement: bool = False, nullable: bool = True, default: Any = None, doc: str | None = None)

Bases: object

A data class for defining a column in a logical Registry table.

Attributes Summary

autoincrement

Whether the database should insert automatically incremented values when no value is provided in an INSERT.

default

A server-side default value for this field.

doc

Documentation for this field.

length

Length of the type in the database, for variable-length types.

nbytes

Natural length used for hash and encoded-region columns, to be converted into the post-encoding length.

nullable

Whether this field is allowed to be NULL.

primaryKey

Whether this field is (part of) its table's primary key.

Methods Summary

for_region([name, nullable, nbytes])

Create a FieldSpec for a spatial region column.

fromConfig(config, *args, **kwargs)

getPythonType()

Return the Python type associated with this field's (SQL) dtype.

getSizedColumnType()

Return a sized version of the column type.

isStringType()

Indicate that this is a sqlalchemy.String field spec.

Attributes Documentation

autoincrement: bool = False

Whether the database should insert automatically incremented values when no value is provided in an INSERT.

default: Any = None

A server-side default value for this field.

This is passed directly as the server_default argument to sqlalchemy.schema.Column. It does _not_ go through SQLAlchemy’s usual type conversion or quoting for Python literals, and should hence be used with care. See the SQLAlchemy documentation for more information.

doc: str | None = None

Documentation for this field.

length: int | None = None

Length of the type in the database, for variable-length types.

nbytes: int | None = None

Natural length used for hash and encoded-region columns, to be converted into the post-encoding length.

nullable: bool = True

Whether this field is allowed to be NULL. If primaryKey is True, during construction this value will be forced to False.

primaryKey: bool = False

Whether this field is (part of) its table’s primary key.

Methods Documentation

classmethod for_region(name: str = 'region', nullable: bool = True, nbytes: int = 2048) FieldSpec

Create a FieldSpec for a spatial region column.

Parameters:
namestr, optional

Name for the field.

nullablebool, optional

Whether NULL values are permitted.

nbytesint, optional

Maximum number of bytes for serialized regions. The actual column size will be larger to allow for base-64 encoding.

Returns:
specFieldSpec

Specification structure for a region column.

classmethod fromConfig(config: Config, *args: Any, **kwargs: Any) Any
getPythonType() type

Return the Python type associated with this field’s (SQL) dtype.

Returns:
typetype

Python type associated with this field’s (SQL) dtype.

getSizedColumnType() TypeEngine | type

Return a sized version of the column type.

Utilizes either (or neither) of self.length and self.nbytes.

Returns:
dtypesqlalchemy.types.TypeEngine

A SQLAlchemy column type object.

isStringType() bool

Indicate that this is a sqlalchemy.String field spec.

Returns:
isStringbool

The field refers to a sqlalchemy.String and not any other type. This can return False even if the object was created with a string type if it has been decided that it should be implemented as a sqlalchemy.Text type.