to_type

Converts a thing into a typed thing.

Before a thing may be converted, all the properties of the thing must have an exact match with the properties defined by the Type. It you later want to change tome properties, the function mod_type can be used.

Since the root of a collection is also a thing, it is possible to use this function to make the collection strict.

It is not possible to convert a thing into a Type with relations. Relations can be made after the conversion.

Although it is possible to convert a typed thing to a non-typed thing using the to_thing function, this only works if the type is not dependent of any other type (including self dependencies). This is because ThingsDB is not able to tell if it is allowed to convert back to a non-typed thing when it might be required by a parent of the typed thing.

This function generates a change.

Function

thing.to_type(type)

Arguments

Argument Type Description
type str Name of the Type to convert the thing into.

Return value

Returns nil when successful.

Example

This code converts a collection into a Type using the to_type() function:

// Create a type `Root`
set_type('Root', {
    name: 'str'
});

// Create a name property so the collection will match with type `Root`
.name = 'Example';

// Convert the collection into type `Root`
.to_type('Root');

Return value in JSON format

null