MCPcopy Create free account
hub / github.com/datastax/astrapy / create_type

Method create_type

astrapy/data/database.py:4039–4125  ·  view source on GitHub ↗

Creates a user-defined type (UDT) on the database. A user-defined type is scoped to a keyspace: unless otherwise specified, the UDT creation targets the database's working keyspace. Args: name: the name of the type to create. This will be subsequently u

(
        self,
        name: str,
        *,
        definition: CreateTypeDefinition | dict[str, Any],
        keyspace: str | None = None,
        if_not_exists: bool | None = None,
        table_admin_timeout_ms: int | None = None,
        request_timeout_ms: int | None = None,
        timeout_ms: int | None = None,
    )

Source from the content-addressed store, hash-verified

4037 return lt_response["status"]["tables"] # type: ignore[no-any-return]
4038
4039 async def create_type(
4040 self,
4041 name: str,
4042 *,
4043 definition: CreateTypeDefinition | dict[str, Any],
4044 keyspace: str | None = None,
4045 if_not_exists: bool | None = None,
4046 table_admin_timeout_ms: int | None = None,
4047 request_timeout_ms: int | None = None,
4048 timeout_ms: int | None = None,
4049 ) -> None:
4050 """
4051 Creates a user-defined type (UDT) on the database.
4052
4053 A user-defined type is scoped to a keyspace: unless otherwise specified,
4054 the UDT creation targets the database's working keyspace.
4055
4056 Args:
4057 name: the name of the type to create. This will be subsequently used
4058 e.g. for defining UDT-valued columns when creating a table.
4059 definition: a complete type definition. This can be an
4060 instance of `CreateTypeDefinition` or an equivalent (nested) dictionary,
4061 in which case it will be parsed into a `CreateTypeDefinition`.
4062 See the `astrapy.info.CreateTypeDefinition` class for more details.
4063 keyspace: the keyspace where the type is to be created.
4064 If not specified, the general setting for this database is used.
4065 if_not_exists: if set to True, the command will succeed even if a type
4066 with the specified name already exists (in which case no actual
4067 creation takes place on the database). Defaults to False,
4068 i.e. an error is raised by the API in case of type-name collision.
4069 table_admin_timeout_ms: a timeout, in milliseconds, to impose on the
4070 underlying API request. If not provided, this object's defaults apply.
4071 (This method issues a single API request, hence all timeout parameters
4072 are treated the same.)
4073 request_timeout_ms: an alias for `table_admin_timeout_ms`.
4074 timeout_ms: an alias for `table_admin_timeout_ms`.
4075
4076 Example:
4077 >>> # NOTE: may require slight adaptation to an async context.
4078 >>>
4079 >>> from astrapy.info import CreateTypeDefinition
4080 >>> type_definition = CreateTypeDefinition.coerce(
4081 ... {"fields": {"genus": "text", "species": "text"}}
4082 ... )
4083 >>> await async_database.create_type("sci_name", definition=type_definition)
4084 """
4085 cty_options: dict[str, bool]
4086 if if_not_exists is not None:
4087 cty_options = {"ifNotExists": if_not_exists}
4088 else:
4089 cty_options = {}
4090 cty_definition: dict[str, Any] = CreateTypeDefinition.coerce(
4091 definition
4092 ).as_dict()
4093 _table_admin_timeout_ms, _ta_label = _select_singlereq_timeout_ta(
4094 timeout_options=self.api_options.timeout_options,
4095 table_admin_timeout_ms=table_admin_timeout_ms,
4096 request_timeout_ms=request_timeout_ms,

Callers

nothing calls this directly

Calls 8

_get_driver_commanderMethod · 0.95
_TimeoutContextClass · 0.90
async_requestMethod · 0.80
as_dictMethod · 0.45
coerceMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected