【问题标题】:Save property type int google datastore保存属性类型 int google 数据存储
【发布时间】:2020-01-27 07:14:18
【问题描述】:

当我使用 PHP 将记录保存到 Google Datastore 时,如何定义属性类型?

版本应该是类型:整数

颜色应该是类型:字符串

描述应该是类型:文本(我想在那里保存长文本)

created 应该是类型:日期和时间

并且 cardatas 应该是 Array 或 Text 类型,

什么是最适合 JSON 数据的?:数组或文本

 $datastore = new DatastoreClient();
    $key = 'protCarDatas';
    $time = date(DATE_RFC3339);
    $savedata = $datastore->entity(
        $key,
           [
             'version' => $version,
             'color' => $color,
             'description' => $desc,
             'created' => $time,
             'cardatas' => $fullCardDataJsonString
           ],
           ['excludeFromIndexes' => ['cardatas']]
    );

    $datastore->insert($savedata); 

感谢您的帮助!

【问题讨论】:

    标签: php google-cloud-datastore


    【解决方案1】:

    Datastore 支持的类型如下 (from the Documentation):

    • 整数
    • 浮点数
    • 字符串
    • 日期
    • 二进制数据

    所以我会将变量转换为:

    版本:整数

    颜色:字符串

    描述:字符串

    创建:日期

    卡片数据:字符串

    【讨论】:

    • 我找不到样本,如何将变量设置为整数或字符串,...
    • 您使用已转换的变量创建数据存储条目,仅此而已。我建议阅读Storing data section
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    • 2017-05-19
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多