国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Sequelize Model 使用

Sanchi / 1929人閱讀

數據檢索

查詢特定元素

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
    }
  }
})

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/87946.html

相關文章

  • Sequelize Model

    摘要:定義默認值和是否為空默認時間為創建時間設置為將會在數據表中添加列如果查詢時該列為數據庫會拋出錯誤如果你想在查詢前檢查該值是否為,看一下下面的驗證部分可以是或如果多個列是相同就會變成會創建索引也可以這么創建索引主鍵自動增量在可以有可以通過屬性 定義Model import sequelize from sequelize var Foo = sequelize.define(foo, ...

    andong777 評論0 收藏0
  • 使用TS+Sequelize實現更簡潔的CRUD

    摘要:哈哈,這又是為什么呢細心的同學可能會發現,的返回值是一個類型的,所以上邊并沒有屬性,的兩個屬性也是如此。我們通過在函數上邊添加一個范型的定義,并且添加限制保證傳入的范型類型一定是繼承自的,在返回值轉換其類型為,就可以實現功能了。 如果是經常使用Node來做服務端開發的童鞋,肯定不可避免的會操作數據庫,做一些增刪改查(CRUD,Create Read Update Delete)的操作,...

    JayChen 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<