摘要:最近在公司接觸到了的框架,研究了一下官方文檔,做了以下整理其他定義方法字段類型是否允許為字段是否自定義表名是否需要增加字段不需要字段將字段改個名將字段改名同時需要設(shè)置為此種模式下,刪除數(shù)據(jù)時不會進(jìn)行物理刪除,而是設(shè)置為當(dāng)前時間
最近在公司接觸到了sequelize(Nodejs的ORM框架),研究了一下官方文檔,做了以下整理
Models Definitionlet DeviceInterface = Sequelize.define("DeviceInterface", { name: { type: Sequelize.STRING, allowNull: false }, createBy: { type: Sequelize.INTEGER, defaultValue: "-1" }, image: { type: Sequelize.STRING }, desc: { type: Sequelize.STRING } }, { tableName: "DeviceInterface" });Data types
Sequelize.STRING // VARCHAR(255) Sequelize.STRING(1234) // VARCHAR(1234) Sequelize.STRING.BINARY // VARCHAR BINARY Sequelize.TEXT // TEXT Sequelize.TEXT("tiny") // TINYTEXT Sequelize.INTEGER // INTEGER Sequelize.BIGINT // BIGINT Sequelize.BIGINT(11) // BIGINT(11) Sequelize.FLOAT // FLOAT Sequelize.FLOAT(11) // FLOAT(11) Sequelize.FLOAT(11, 12) // FLOAT(11,12) Sequelize.REAL // REAL PostgreSQL only. Sequelize.REAL(11) // REAL(11) PostgreSQL only. Sequelize.REAL(11, 12) // REAL(11,12) PostgreSQL only. Sequelize.DOUBLE // DOUBLE Sequelize.DOUBLE(11) // DOUBLE(11) Sequelize.DOUBLE(11, 12) // DOUBLE(11,12) Sequelize.DECIMAL // DECIMAL Sequelize.DECIMAL(10, 2) // DECIMAL(10,2) Sequelize.DATE // DATETIME for mysql / sqlite, TIMESTAMP WITH TIME ZONE for postgres Sequelize.DATE(6) // DATETIME(6) for mysql 5.6.4+. Fractional seconds support with up to 6 digits of precision Sequelize.DATEONLY // DATE without time. Sequelize.BOOLEAN // TINYINT(1) Sequelize.ENUM("value 1", "value 2") // An ENUM with allowed values "value 1" and "value 2" Sequelize.ARRAY(Sequelize.TEXT) // Defines an array. PostgreSQL only. Sequelize.JSON // JSON column. PostgreSQL only. Sequelize.JSONB // JSONB column. PostgreSQL only. Sequelize.BLOB // BLOB (bytea for PostgreSQL) Sequelize.BLOB("tiny") // TINYBLOB (bytea for PostgreSQL. Other options are medium and long) Sequelize.UUID // UUID datatype for PostgreSQL and SQLite, CHAR(36) BINARY for MySQL (use defaultValue: Sequelize.UUIDV1 or Sequelize.UUIDV4 to make sequelize generate the ids automatically) Sequelize.RANGE(Sequelize.INTEGER) // Defines int4range range. PostgreSQL only. Sequelize.RANGE(Sequelize.BIGINT) // Defined int8range range. PostgreSQL only. Sequelize.RANGE(Sequelize.DATE) // Defines tstzrange range. PostgreSQL only. Sequelize.RANGE(Sequelize.DATEONLY) // Defines daterange range. PostgreSQL only. Sequelize.RANGE(Sequelize.DECIMAL) // Defines numrange range. PostgreSQL only. Sequelize.ARRAY(Sequelize.RANGE(Sequelize.DATE)) // Defines array of tstzrange ranges. PostgreSQL only. Sequelize.GEOMETRY // Spatial column. PostgreSQL (with PostGIS) or MySQL only. Sequelize.GEOMETRY("POINT") // Spatial column with geometry type. PostgreSQL (with PostGIS) or MySQL only. Sequelize.GEOMETRY("POINT", 4326) // Spatial column with geometry type and SRID. PostgreSQL (with PostGIS) or MySQL only.其他定義方法
var User = sequelize.define( "user", { "emp_id": { "type": Sequelize.CHAR(10), // 字段類型 "allowNull": false, // 是否允許為NULL "unique": true // 字段是否UNIQUE }, "nick": { "type": Sequelize.CHAR(10), "allowNull": false }, "department": { "type": Sequelize.STRING(64), "allowNull": true } }, { // 自定義表名 "freezeTableName": true, "tableName": "xyz_users", // 是否需要增加createdAt、updatedAt、deletedAt字段 "timestamps": true, // 不需要createdAt字段 "createdAt": false, // 將updatedAt字段改個名 "updatedAt": "utime" // 將deletedAt字段改名 // 同時需要設(shè)置paranoid為true(此種模式下,刪除數(shù)據(jù)時不會進(jìn)行物理刪除,而是設(shè)置deletedAt為當(dāng)前時間 "deletedAt": "dtime", "paranoid": true } );CRUD
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/91325.html
摘要:入門在使用來關(guān)系型操作數(shù)據(jù)庫時,為了方便,通常都會選擇一個合適的框架。類似這樣加,會先刪掉表后再建表。通過模型的類方法可以獲取模型對象比如等。增加小明技術(shù)部修改小白白更新成功刪除刪除成功查詢 sequelize入門 在使用NodeJS來關(guān)系型操作數(shù)據(jù)庫時,為了方便,通常都會選擇一個合適的ORM(Object Relationship Model)框架。畢竟直接操作SQL比較繁瑣,通過O...
摘要:菜鳥教程框架中文手冊入門目標(biāo)使用搭建通過對數(shù)據(jù)增刪查改沒了純粹占行用的拜 后端API入門學(xué)習(xí)指北 了解一下一下概念. RESTful API標(biāo)準(zhǔn)] 所有的API都遵循[RESTful API標(biāo)準(zhǔn)]. 建議大家都簡單了解一下HTTP協(xié)議和RESTful API相關(guān)資料. 阮一峰:理解RESTful架構(gòu) 阮一峰:RESTful API 設(shè)計指南 RESTful API指南 依賴注入 D...
摘要:菜鳥教程框架中文手冊入門目標(biāo)使用搭建通過對數(shù)據(jù)增刪查改沒了純粹占行用的拜 后端API入門學(xué)習(xí)指北 了解一下一下概念. RESTful API標(biāo)準(zhǔn)] 所有的API都遵循[RESTful API標(biāo)準(zhǔn)]. 建議大家都簡單了解一下HTTP協(xié)議和RESTful API相關(guān)資料. 阮一峰:理解RESTful架構(gòu) 阮一峰:RESTful API 設(shè)計指南 RESTful API指南 依賴注入 D...
摘要:菜鳥教程框架中文手冊入門目標(biāo)使用搭建通過對數(shù)據(jù)增刪查改沒了純粹占行用的拜 后端API入門學(xué)習(xí)指北 了解一下一下概念. RESTful API標(biāo)準(zhǔn)] 所有的API都遵循[RESTful API標(biāo)準(zhǔn)]. 建議大家都簡單了解一下HTTP協(xié)議和RESTful API相關(guān)資料. 阮一峰:理解RESTful架構(gòu) 阮一峰:RESTful API 設(shè)計指南 RESTful API指南 依賴注入 D...
閱讀 1291·2021-09-22 15:00
閱讀 3309·2019-08-30 14:00
閱讀 1220·2019-08-29 17:27
閱讀 1220·2019-08-29 16:35
閱讀 689·2019-08-29 16:14
閱讀 2042·2019-08-26 13:43
閱讀 2117·2019-08-26 11:35
閱讀 2309·2019-08-23 15:34