ahvn.utils.mdb.types module

MongoDB type definitions and conversion utilities for UKF models.

class ahvn.utils.mdb.types.BaseMongoType(**kwargs)[源代码]

基类:object

Base class for MongoDB field types with UKF conversion.

__init__(**kwargs)[源代码]
from_ukf(ukf_value)[源代码]

Convert UKF value to MongoDB value.

返回类型:

Any

参数:

ukf_value (Any)

to_ukf(mongo_value)[源代码]

Convert MongoDB value to UKF value.

返回类型:

Any

参数:

mongo_value (Any)

class ahvn.utils.mdb.types.MongoIdType(**kwargs)[源代码]

基类:BaseMongoType

ID type for MongoDB (_id field).

UKF IDs can be very large integers (beyond 64-bit). MongoDB only supports up to 64-bit integers (8 bytes). We store IDs as strings to avoid overflow.

from_ukf(ukf_value)[源代码]

Convert UKF ID to MongoDB _id (string).

返回类型:

Optional[str]

参数:

ukf_value (Any)

to_ukf(mongo_value)[源代码]

Convert MongoDB _id to UKF ID (integer).

返回类型:

Optional[int]

参数:

mongo_value (Any)

class ahvn.utils.mdb.types.MongoTextType(length=None, **kwargs)[源代码]

基类:BaseMongoType

Text type for MongoDB (string).

参数:

length (int | None)

__init__(length=None, **kwargs)[源代码]
参数:

length (int | None)

from_ukf(ukf_value)[源代码]

Convert UKF text to MongoDB string.

返回类型:

Optional[str]

参数:

ukf_value (Any)

to_ukf(mongo_value)[源代码]

Convert MongoDB string to UKF text.

返回类型:

Optional[str]

参数:

mongo_value (Any)

class ahvn.utils.mdb.types.MongoIntegerType(**kwargs)[源代码]

基类:BaseMongoType

Integer type for MongoDB.

from_ukf(ukf_value)[源代码]

Convert UKF integer to MongoDB integer.

返回类型:

Optional[int]

参数:

ukf_value (Any)

to_ukf(mongo_value)[源代码]

Convert MongoDB integer to UKF integer.

返回类型:

Optional[int]

参数:

mongo_value (Any)

class ahvn.utils.mdb.types.MongoBooleanType(**kwargs)[源代码]

基类:BaseMongoType

Boolean type for MongoDB.

from_ukf(ukf_value)[源代码]

Convert UKF boolean to MongoDB boolean.

返回类型:

Optional[bool]

参数:

ukf_value (Any)

to_ukf(mongo_value)[源代码]

Convert MongoDB boolean to UKF boolean.

返回类型:

Optional[bool]

参数:

mongo_value (Any)

class ahvn.utils.mdb.types.MongoDurationType(**kwargs)[源代码]

基类:BaseMongoType

Duration type for MongoDB (stored as integer seconds).

from_ukf(ukf_value)[源代码]

Convert UKF timedelta to MongoDB integer (seconds).

返回类型:

Optional[int]

参数:

ukf_value (timedelta | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB integer (seconds) to UKF timedelta.

返回类型:

Optional[timedelta]

参数:

mongo_value (int | None)

class ahvn.utils.mdb.types.MongoTimestampType(**kwargs)[源代码]

基类:BaseMongoType

Timestamp type for MongoDB (stored as integer or datetime).

from_ukf(ukf_value)[源代码]

Convert UKF datetime to MongoDB integer (Unix timestamp).

返回类型:

Optional[int]

参数:

ukf_value (datetime | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB integer (Unix timestamp) to UKF datetime.

返回类型:

Optional[datetime]

参数:

mongo_value (int | None)

class ahvn.utils.mdb.types.MongoJsonType(**kwargs)[源代码]

基类:BaseMongoType

JSON type for MongoDB (stored as embedded document).

from_ukf(ukf_value)[源代码]

Convert UKF JSON to MongoDB embedded document.

返回类型:

Optional[Dict[str, Any]]

参数:

ukf_value (Any)

to_ukf(mongo_value)[源代码]

Convert MongoDB embedded document to UKF JSON.

返回类型:

Any

参数:

mongo_value (Dict[str, Any] | None)

class ahvn.utils.mdb.types.MongoVectorType(**kwargs)[源代码]

基类:BaseMongoType

Vector type for MongoDB (stored as array of floats).

from_ukf(ukf_value)[源代码]

Convert UKF vector to MongoDB array.

返回类型:

Optional[List[float]]

参数:

ukf_value (List[float] | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB array to UKF vector.

返回类型:

Optional[List[float]]

参数:

mongo_value (List[float] | None)

class ahvn.utils.mdb.types.MongoTagsType(**kwargs)[源代码]

基类:BaseMongoType

Tags type for MongoDB (stored as array of {slot, value} subdocuments).

UKF tags are stored as strings like "[slot:value]". MongoDB stores them as subdocuments: [{"slot": "...", "value": "..."}, ...]

from_ukf(ukf_value)[源代码]

Convert UKF tags (set of "[slot:value]" strings) to MongoDB array.

返回类型:

Optional[List[Dict[str, str]]]

参数:

ukf_value (set | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB array to UKF tags (set of "[slot:value]" strings).

返回类型:

Optional[set]

参数:

mongo_value (List[Dict[str, str]] | None)

class ahvn.utils.mdb.types.MongoSynonymsType(**kwargs)[源代码]

基类:BaseMongoType

Synonyms type for MongoDB (stored as array of strings).

UKF synonyms are already a set of strings.

from_ukf(ukf_value)[源代码]

Convert UKF synonyms (set of strings) to MongoDB array.

返回类型:

Optional[List[str]]

参数:

ukf_value (set | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB array to UKF synonyms (set of strings).

返回类型:

Optional[set]

参数:

mongo_value (List[str] | None)

class ahvn.utils.mdb.types.MongoRelatedType(**kwargs)[源代码]

基类:BaseMongoType

Related type for MongoDB (stored as array of relation subdocuments).

UKF related are 5-element tuples: (subject_id: int, relation: str, object_id: int, relation_id: Optional[int], relation_resources: Optional[str])

The relation_resources is a JSON string that gets stored in MongoDB as-is.

from_ukf(ukf_value)[源代码]

Convert UKF related (set of 5-tuples) to MongoDB array.

返回类型:

Optional[List[Dict[str, Any]]]

参数:

ukf_value (set | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB array of subdocuments to UKF related (set of 5-tuples).

返回类型:

Optional[set]

参数:

mongo_value (List[Dict[str, Any]] | None)

class ahvn.utils.mdb.types.MongoAuthsType(**kwargs)[源代码]

基类:BaseMongoType

Authorities type for MongoDB (stored as array of subdocuments).

UKF stores auths as set of "[user:authority]" strings. We parse this into subdocuments with user and authority fields.

from_ukf(ukf_value)[源代码]

Convert UKF auths (set of "[user:authority]" strings) to MongoDB array.

返回类型:

Optional[List[Dict[str, str]]]

参数:

ukf_value (set | None)

to_ukf(mongo_value)[源代码]

Convert MongoDB array to UKF auths (set of "[user:authority]" strings).

返回类型:

Optional[set]

参数:

mongo_value (List[Dict[str, str]] | None)