Browse Source

less indentation

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

89
lyricsnode/routes/round.js

@ -34,43 +34,70 @@ function acronymize(phrase) {
*/
function getSong(res) {
var name = dbName();
console.log('Opening the database ' + name + '...');
db = new sqlite3.Database(name, sqlite3.OPEN_READWRITE, function (error) {
if (error) {
throw error;
}
var db = null;
var song = null;
var artist = null;
var lyrics = null;
function pickSong() {
console.log('Picking song...');
db.get('SELECT * FROM songs WHERE done_in IS NULL ORDER BY random() LIMIT 1', function (err, selectSong) {
if (err) {
throw err;
}
song = selectSong;
console.log(song);
pickArtist();
});
}
console.log('Pickling a song...');
db.get('SELECT * FROM songs WHERE done_in IS NULL ORDER BY random() LIMIT 1', function (err, song) {
function pickArtist() {
console.log('Retrieving artist for song...');
db.get('SELECT * FROM artists WHERE id = ' + song.artist, function (err, selectArtist) {
if (err) {
throw err;
}
console.log('Retrieving artist for song...');
db.get('SELECT * FROM artists WHERE id = ' + song.artist, function (err, artist) {
if (err) {
throw err;
}
console.log('Retrieving lyrics for song... ');
db.get('SELECT * FROM lyrics WHERE song = ' + song.id, function (err, lyrics) {
if (err) {
throw err;
}
var params = {
title: 'Round',
lyrics: lyrics.lyrics,
song_title: song.title,
song_artist: artist.name,
acronym_title: acronymize(song.title),
acronym_artist: acronymize(artist.name),
id: song.id
};
res.render('index', params);
});
});
artist = selectArtist;
console.log(artist);
pickLyrics();
});
}
function pickLyrics() {
console.log('Retrieving lyrics for song... ');
db.get('SELECT * FROM lyrics WHERE song = ' + song.id, function (err, selectLyrics) {
if (err) {
throw err;
}
lyrics = selectLyrics;
console.log(lyrics);
answer();
});
}
function answer() {
var params = {
title: 'Round',
lyrics: lyrics.lyrics,
song_title: song.title,
song_artist: artist.name,
acronym_title: acronymize(song.title),
acronym_artist: acronymize(artist.name),
id: song.id
};
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