數(shù)據(jù)檢索
查詢特定元素
findOne
findById
// search for known ids Project.findById(123).then(function(project) { // project will be an instance of Project and stores the content of the table entry // with id 123. if such an entry is not defined you will get null }) // search for attributes Project.findOne({ where: {title: "aProject"} }).then(function(project) { // project will be the first entry of the Projects table with the title "aProject" || null }) Project.findOne({ where: {title: "aProject"}, attributes: ["id", ["name", "title"]] }).then(function(project) { // project will be the first entry of the Projects table with the title "aProject" || null // project.title will contain the name of the project })
findOrCreate
findAndCountAll
findAll
// find multiple entries Project.findAll().then(function(projects) { // projects will be an array of all Project instances }) // also possible: Project.all().then(function(projects) { // projects will be an array of all Project instances }) // search for specific attributes - hash usage Project.findAll({ where: { name: "A Project" } }).then(function(projects) { // projects will be an array of Project instances with the specified name }) // search with string replacements Project.findAll({ where: ["id > ?", 25] }).then(function(projects) { // projects will be an array of Projects having a greater id than 25 }) // search within a specific range Project.findAll({ where: { id: [1,2,3] } }).then(function(projects) { // projects will be an array of Projects having the id 1, 2 or 3 // this is actually doing an IN query }) Project.findAll({ where: { id: { $and: {a: 5} // AND (a = 5) $or: [{a: 5}, {a: 6}] // (a = 5 OR a = 6) $gt: 6, // id > 6 $gte: 6, // id >= 6 $lt: 10, // id < 10 $lte: 10, // id <= 10 $ne: 20, // id != 20 $between: [6, 10], // BETWEEN 6 AND 10 $notBetween: [11, 15], // NOT BETWEEN 11 AND 15 $in: [1, 2], // IN [1, 2] $notIn: [1, 2], // NOT IN [1, 2] $like: "%hat", // LIKE "%hat" $notLike: "%hat" // NOT LIKE "%hat" $iLike: "%hat" // ILIKE "%hat" (case insensitive) (PG only) $notILike: "%hat" // NOT ILIKE "%hat" (PG only) $overlap: [1, 2] // && [1, 2] (PG array overlap operator) $contains: [1, 2] // @> [1, 2] (PG array contains operator) $contained: [1, 2] // <@ [1, 2] (PG array contained by operator) $any: [2,3] // ANY ARRAY[2, 3]::INTEGER (PG only) }, status: { $not: false, // status NOT FALSE } } })
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/87946.html
摘要:定義默認(rèn)值和是否為空默認(rèn)時(shí)間為創(chuàng)建時(shí)間設(shè)置為將會(huì)在數(shù)據(jù)表中添加列如果查詢時(shí)該列為數(shù)據(jù)庫(kù)會(huì)拋出錯(cuò)誤如果你想在查詢前檢查該值是否為,看一下下面的驗(yàn)證部分可以是或如果多個(gè)列是相同就會(huì)變成會(huì)創(chuàng)建索引也可以這么創(chuàng)建索引主鍵自動(dòng)增量在可以有可以通過(guò)屬性 定義Model import sequelize from sequelize var Foo = sequelize.define(foo, ...
摘要:哈哈,這又是為什么呢細(xì)心的同學(xué)可能會(huì)發(fā)現(xiàn),的返回值是一個(gè)類型的,所以上邊并沒(méi)有屬性,的兩個(gè)屬性也是如此。我們通過(guò)在函數(shù)上邊添加一個(gè)范型的定義,并且添加限制保證傳入的范型類型一定是繼承自的,在返回值轉(zhuǎn)換其類型為,就可以實(shí)現(xiàn)功能了。 如果是經(jīng)常使用Node來(lái)做服務(wù)端開(kāi)發(fā)的童鞋,肯定不可避免的會(huì)操作數(shù)據(jù)庫(kù),做一些增刪改查(CRUD,Create Read Update Delete)的操作,...
閱讀 2172·2023-04-25 20:45
閱讀 1087·2021-09-22 15:13
閱讀 3653·2021-09-04 16:48
閱讀 2589·2019-08-30 15:53
閱讀 941·2019-08-30 15:44
閱讀 957·2019-08-30 15:43
閱讀 1014·2019-08-29 16:33
閱讀 3443·2019-08-29 13:08