how to define a save method in ruby for sql databases

Solutions on MaxInterview for how to define a save method in ruby for sql databases by the best coders in the world

showing results for - "how to define a save method in ruby for sql databases"
Cecilia
07 Jan 2017
1def save
2    sql = <<-SQL
3      INSERT INTO songs (name, album) 
4      VALUES (?, ?)
5    SQL
6 
7    DB[:conn].execute(sql, self.name, self.album)
8 
9    @id = DB[:conn].execute("SELECT last_insert_rowid() FROM songs")[0][0]
10 
11  end