Browse Source

less indentation

master
Julio Biason 11 years ago
parent
commit
9757f7b91f
  1. 51
      lyricsnode/routes/round.js

51
lyricsnode/routes/round.js

@ -34,30 +34,51 @@ function acronymize(phrase) {
*/ */
function getSong(res) { function getSong(res) {
var name = dbName(); var name = dbName();
console.log('Opening the database ' + name + '...'); var db = null;
db = new sqlite3.Database(name, sqlite3.OPEN_READWRITE, function (error) { var song = null;
if (error) { var artist = null;
throw error; var lyrics = null;
}
console.log('Pickling a song...'); function pickSong() {
db.get('SELECT * FROM songs WHERE done_in IS NULL ORDER BY random() LIMIT 1', function (err, song) { console.log('Picking song...');
db.get('SELECT * FROM songs WHERE done_in IS NULL ORDER BY random() LIMIT 1', function (err, selectSong) {
if (err) { if (err) {
throw err; throw err;
} }
song = selectSong;
console.log(song);
pickArtist();
});
}
function pickArtist() {
console.log('Retrieving artist for song...'); console.log('Retrieving artist for song...');
db.get('SELECT * FROM artists WHERE id = ' + song.artist, function (err, artist) { db.get('SELECT * FROM artists WHERE id = ' + song.artist, function (err, selectArtist) {
if (err) { if (err) {
throw err; throw err;
} }
artist = selectArtist;
console.log(artist);
pickLyrics();
});
}
function pickLyrics() {
console.log('Retrieving lyrics for song... '); console.log('Retrieving lyrics for song... ');
db.get('SELECT * FROM lyrics WHERE song = ' + song.id, function (err, lyrics) { db.get('SELECT * FROM lyrics WHERE song = ' + song.id, function (err, selectLyrics) {
if (err) { if (err) {
throw err; throw err;
} }
lyrics = selectLyrics;
console.log(lyrics);
answer();
});
}
function answer() {
var params = { var params = {
title: 'Round', title: 'Round',
lyrics: lyrics.lyrics, lyrics: lyrics.lyrics,
@ -68,9 +89,15 @@ function getSong(res) {
id: song.id id: song.id
}; };
res.render('index', params); res.render('index', params);
}); }
});
}); console.log('Opening the database ' + name + '...');
db = new sqlite3.Database(name, sqlite3.OPEN_READWRITE, function (error) {
if (error) {
throw error;
}
pickSong();
}); });
} }

Loading…
Cancel
Save