首页 > 解决方案 > 如何在 Cassandra 中存储自定义对象?

问题描述

我有以下需要存储在 Cassandra 中的对象。我需要使用 UDT 还是有其他方法来存储对象。我最终需要使用存储库方法从 spring-boot 应用程序中存储它。

{
    "name": "Krishna",
    "age" : 24,
    "address" : [
        {
            "attributes" : [
                {
                    "name": "",
                    "value" : ""
                }
            ],
            "contactnumbers" : [ "123123234", "123456"]
        }
    ],
    "devices" : [
        "android_pixel",
        "ios_6s"
    ]
}

标签: spring-bootcassandra

解决方案


我认为,您需要在这里使用 UDT。我可以想出这个。

CREATE TYPE attribute_info (
    name text,
    value text
);

CREATE TYPE address_info (
    attributes list<frozen<attribute_info>>,
    contactnumbers list<text> 
);

CREATE TYPE user_info (
    name text,
    age int,
    address list<frozen<address_info>>,
    devices list<text>
);

一旦你得到user_info你的key space,在创建或更改表格时将其用作列的类型。


推荐阅读