成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Sequelize Model 使用

Sanchi / 1938人閱讀

數(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

相關(guān)文章

  • Sequelize Model

    摘要:定義默認(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, ...

    andong777 評(píng)論0 收藏0
  • 使用TS+Sequelize實(shí)現(xiàn)更簡(jiǎn)潔的CRUD

    摘要:哈哈,這又是為什么呢細(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)的操作,...

    JayChen 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<