Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. const cassandra = require('cassandra-driver');
  2. //const Uuid = require('cassandra-driver').types.Uuid;
  3. const Integer = require('cassandra-driver').types.Integer;
  4.  
  5. const client = new cassandra.Client({ contactPoints: ['127.0.0.1'],
  6. keyspace: 'my_music', localDataCenter: 'datacenter1'});
  7. client.connect(function (err) {
  8. if (err) return console.error(err);
  9. console.log('Connected to cluster with %d host(s): %j',
  10. client.hosts.length, client.hosts.keys());
  11. });
  12.  
  13. function startTheSongs(user_email, album_id, lp)
  14. {
  15. var user_email, album_id, title, lp, artistSong, albumTitleSong;
  16. //const albumId = Uuid.fromString(album_id);
  17. console.log(album_id + ' To jest id z glownej funkcji');
  18. const Uuid = require('cassandra-driver').types.Uuid;
  19. const albumId = Uuid.fromString(album_id);
  20. const Integer = require('cassandra-driver').types.Integer;
  21. console.log(albumId instanceof Uuid);
  22. console.log(typeof(lp) + ' to jest ' + lp);
  23. const lpSong = Integer.fromNumber(lp);
  24. console.log(lpSong instanceof Integer);
  25.  
  26. // dane do sprawdzenia id_433fb540-848b-11e9-8d93-fb8cf387b215, lp = 9 == Brothers in Arms
  27. function getSongTitle(album_id, lp){
  28.  
  29. const queryGetTitleSong = 'SELECT title FROM songs WHERE album_id = ? AND lp = ?';
  30. const paramsGetTitleSong = [albumId, lpSong];
  31. console.log(lp instanceof Integer);
  32. console.log(album_id instanceof Uuid);
  33. console.log(typeof(album_id) + ' to jest ' + album_id);
  34. console.log(typeof(lp) + ' to jest ' + lp);
  35. return new Promise(function(resolve, reject){
  36. client.execute(queryGetTitleSong, paramsGetTitleSong, { prepare: true })
  37. .then((result) => result.rows[0])
  38. .catch(err => {
  39. console.log(err);
  40. return 'jest ok' // obsluguję blad
  41. });
  42. });
  43. }
  44. getSongTitle()
  45. .then(res => {
  46. console.log(res);
  47. })
  48. .catch(err => console.log(err));
  49. }
  50. //startTheSongs('oracle@example.com', '60485090-debc-11e8-a218-eda19fa33fe9', 1);
  51. startTheSongs('oracle@example.com','602908c0-debc-11e8-a218-eda19fa33fe9', 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement