type
How to create a user-defined type (UDT).
Synopsis
schema.type('*UDTName*'). [ ifNotExists(). ] [ property('*propertyName*', *propertyType*). ] [ create() | describe() | drop() ]
Description
A user-defined type (UDT) specifies a data type that can be used by vertex labels and edge labels in DataStax Graph (DSG). UDTs can also use other UDTs in their definition. For more basic information on UDTs, see the CQL documentation.
-
ifNotExists
Check for lack of current existence with
ifNotExists()
before creating a newuser-defined type. -
property
Properties can be defined for UDTs. Allowed characters for the name are alphabetical or underscore.
-
create
Create a UDT.
-
describe
Describe a UDT.
-
drop
Drop a UDT.
Examples
Create a user-defined type address
:
schema.type('address').
ifNotExists().
property('address1', Text).
property('address2', Text).
property('city_code', Text).
property('state_code', Text).
property('zip_code', Text).
create()
This UDT is created if it doesn’t already exist, and has several properties.
Create a user-defined type location_details
that uses the UDT address
:
schema.type('location_details').
ifNotExists().
property('loc_address', frozen(typeOf('address'))).
property('telephone', listOf(Text)).
create()
This UDT is created if it doesn’t already exist.
Notice typeOf
to use another UDT.
Get the schema for all UDTs using the describe()
command:
schema.types().describe()
The schema returned can be used to recreate the UDT.
Get the schema for a UDT using the describe()
command:
schema.type('address').describe()
Remove a UDT with the drop()
command:
schema.type('full_name').drop()