@@ -21,7 +21,7 @@ instance through :meth:`.Cluster.register_user_type`:
2121 session = cluster.connect()
2222 session.set_keyspace(' mykeyspace' )
2323 session.execute(" CREATE TYPE address (street text, zipcode int)" )
24- session.execute(" CREATE TABLE users (id int PRIMARY KEY, location address)" )
24+ session.execute(" CREATE TABLE users (id int PRIMARY KEY, location frozen< address> )" )
2525
2626 # create a class to map to the "address" UDT
2727 class Address (object ):
@@ -58,7 +58,7 @@ for the UDT:
5858 session = cluster.connect()
5959 session.set_keyspace(' mykeyspace' )
6060 session.execute(" CREATE TYPE address (street text, zipcode int)" )
61- session.execute(" CREATE TABLE users (id int PRIMARY KEY, location address)" )
61+ session.execute(" CREATE TABLE users (id int PRIMARY KEY, location frozen< address> )" )
6262
6363 class Foo (object ):
6464
@@ -72,13 +72,13 @@ for the UDT:
7272 # since we're using a prepared statement, we don't *have* to register
7373 # a class to map to the UDT to insert data. The object just needs to have
7474 # "street" and "zipcode" attributes (which Foo does):
75- session.execute(insert_statement, [0 , Foo(" 123 Main St." , 78723 , " some other stuff" )]
75+ session.execute(insert_statement, [0 , Foo(" 123 Main St." , 78723 , " some other stuff" )])
7676
7777 # when we query data, UDT columns that don't have a class registered
7878 # will be returned as namedtuples:
7979 results = session.execute(" SELECT * FROM users" )
8080 first_row = results[0 ]
81- address = first_row.address
81+ address = first_row.location
8282 print address # prints "Address(street='123 Main St.', zipcode=78723)"
8383 street = address.street
8484 zipcode = address.street
0 commit comments