how to define a save method in ruby for sqlite3 databases

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

showing results for - "how to define a save method in ruby for sqlite3 databases"
Miranda
06 Oct 2019
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