【问题标题】:Insert json data into MySQL database with slashdb rest api使用 slashdb rest api 将 json 数据插入 MySQL 数据库
【发布时间】:2020-11-23 14:19:27
【问题描述】:

我无法使用 slashdb rest 将数据插入 mysql 数据库。 我收到来自我的 iot 服务的发布请求,正文消息中包含 json 数据,来自此 erlang 代码的发布请求手杖:

    Method = post,
    URL = "http://xxxxxxx/api/v2/sensor_sql/_table/s1",
    Header = [{"X-DreamFactory-Api-Key", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}],
    Type = "application/json",
    Body = MessageStr,
    HTTPOptions = [],
    Options = [],
    R = httpc:request(Method, {URL, Header, Type, Body},HTTPOptions, Options),

身体是这样的:

{"温度":22.7,"湿度":99.9},"温度单位":"C"}

我需要使用 slashdb 将这些正文的数据插入到我的数据库中。 在 slashdb 查询中正确配置我的 sql 语句以执行此任务的方法是什么?

【问题讨论】:

    标签: mysql json rest erlang slashdb


    【解决方案1】:

    好的,我自己解决了。 要将 json 数据数组插入到您的 mysql 数据库中,您只需指定您的 rest htlm 地址(在 slashdb 中使用“数据发现”)并在您的 post 请求正文中传递所有 json 数据。 如果您需要更新多个字段,请针对资源端点(单个记录)发出请求,并将 JSON 对象作为有效负载发送。以下是同时更新同一记录的 BillingPostalCode 和 BillngCountry 字段的方法:

    curl https://demo.slashdb.com/db/Chinook/Invoice/InvoiceId/1 -XPUT -i -H 'Content-Type: application/json' -d '{"BillingPostalCode": "456" "BillingCountry": "Germany"}'
    

    【讨论】:

      猜你喜欢
      • 2018-11-09
      • 2013-03-25
      • 2023-02-02
      • 2023-04-01
      • 2018-11-18
      • 2019-04-01
      • 2018-05-09
      • 2022-08-14
      • 2014-04-26
      相关资源
      最近更新 更多