不要怂,就是干,撸起袖子干!

basics.ejs 1.31 KB
// search for known ids
Project.find(123).on('success', 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.find({ where: {title: 'aProject'} }).on('succes', function(project) {
  // project will be the first entry of the Projects table with the title 'aProject' || null
})

// find multiple entries
Project.findAll().on('success', function(projects) {
  // projects will be an array of all Project instances
})

// also possible:
Project.all.on('success', function(projects) {
  // projects will be an array of all Project instances
})

// search for specific attributes - hash usage
Project.findAll({where: {name: 'A Project'}}).on('success', function(projects) {
  // projects will be an array of Project instances with the specified name
})

// search with string replacements
Project.findAll({where: ["id > ?", 25]}).on('success', function(projects) {
  // projects will be an array of Projects having a greater id than 25
})

// or
Project.findAll({where: "name = 'A Project'"}).on('success', function(projects) {
  // the difference between this and the usage of hashes (objects) is, that string usage
  // is not sql injection safe. so make sure you know what you are doing!
})