Un metodo DAO save()
imposta l'id / pk dell'istanza che deve essere salvata e restituisce il istanza o dovrebbe solo restituire il PK?
// Example A: Return the instance
studentDAO = {
save: function(student) {
const id = db.query('INSERT INTO 'students'...');
student.setId(id);
return student;
}
}
// Example B: return the save id and it's up to me to set it
// outside of the DAO
studentDAO = {
save: function() {
const id = db.query('INSERT INTO 'students'...');
return id;
}
}
E uso di quanto sopra:
// Example A
student = new Student();
student = studentDao.save(student);
// Example B
student = new Student();
idStudent = studentDao.save(student);
student.setId(idStudent);