Skip to content

Instantly share code, notes, and snippets.

@danneu
Last active July 27, 2016 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danneu/3a3075aa2ed41b4941e852abbe089e59 to your computer and use it in GitHub Desktop.
Save danneu/3a3075aa2ed41b4941e852abbe089e59 to your computer and use it in GitHub Desktop.
exports.getMovieFromId = function(id) {
return table_movies.select('*').where({ movie_id: id }).first().then((movie) =>
if (movie) return movie
return movies.insert(...).returning('*') // returns promise that resolves as the inserted movie
});
};
exports.getMovies = function() {
return Promise.all([
exports.getMovieFromId(1),
exports.getMovieFromId(2),
exports.getMovieFromId(3),
exports.getMovieFromId(4),
exports.getMovieFromId(5),
])
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment