【问题标题】:Write enum values to MySQL table using Node.js使用 Node.js 将枚举值写入 MySQL 表
【发布时间】:2022-02-18 05:13:39
【问题描述】:

我正在用 Node.js 编写一个 REST API 服务器。我在 MySQL 中有一个表,其中一个列定义为 Enum。 如何将我从 POST 请求中获得的值写入数据库作为枚举值

例如,我有一个用户表:

email - varchar(100)
relationshipStatus - ENUM('single','married','divorced','widow')

并且发布请求是:

{
  "email": "bla@gmail.com",
  "status": "single"
}

【问题讨论】:

    标签: mysql node.js enums


    【解决方案1】:

    您可以只使用字符串值作为您的枚举,如 MySQL 示例中所述:

    CREATE TABLE shirts (
        name VARCHAR(40),
        size ENUM('x-small', 'small', 'medium', 'large', 'x-large')
    );
    INSERT INTO shirts (name, size) VALUES ('dress shirt','large'), ('t-shirt','medium'),
      ('polo shirt','small');
    

    查看更多详情here

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多