[SOLVED] 程序代写代做代考 database SQL Microsoft Word – Document5

30 $

File Name: 程序代写代做代考_database_SQL_Microsoft_Word_–_Document5.zip
File Size: 621.72 KB

SKU: 3799171953 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Microsoft Word – Document5

Exercise5
Inexercise4,youhopefullyrealizedhowcumbersomeitwas
writingyourownrawSQLqueriestointeractwithyourdata!
Forthisexercise,you’llmoveawayfromwritingSQLqueries
directly,andinsteadinteractwithyourdatabaseviaanORM.

LearningOutcome
Bytheendofthisexercise,youshouldbeveryfamiliarwith
howtointeractwithadatabaseprogrammaticallyusingan
ORMinnode.js.

Prerequisites
Inthisassignment,you’llbeusingtheSequelize.js(V3)library
tocreateandinteractwithyourDB(stillreading/writingtoan
SQLitedatabase).
Togetfamiliarwithhowtoprogrammaticallyinteractwiththe
SequelizeORM,checkoutthedemocodefromclass,and/or
checkoutthistutorial.
TheSequelizelibrarymakesheavyuseofPromises(the
solutiontocallbackhell).Ifyou’reunfamiliarwithPromises,I
suggestrunningthroughatutorialsuchasthisorthis.

Gettingstarted
Youshouldbuildontopofwhatyouhaveforexercise3(ifyou
haven’tcompletedexercise3,you’llneedtodoenoughofitto
satisfythisexercisesrequirements,butdoesnotneedtosatisfy
therequirementsofexercise4oranypriorexercise).
Thereasonwhyyou’rebuildingoffexercise3andnot4is
becauseyou’rerepeatingwhatyoudidinexercise4,exceptin
adifferentway.
Youwillneedtoloadtheexternalnode.jsdependenciesfor
Sequelize.Runthefollowinginyourterminal/command
prompt:
npminstall–savesequelize

(the–saveflagwillautomaticallyaddsequelizeasa
dependencyinyourpackage.jsonfile).

Task
YourobjectivewillbeforallofyourexistingGETAPIsto
interactwithyourdatabaseviatheSequelizeORM,ratherthan
theSQLitelibraryfromthepreviousexercise.Ihighly
recommendgettingstartedbyusingthedemocodefromclass,
orbyfollowingthisexamplecode.
WhenyouupdateyourGETrequeststoworkwiththe
database,yourMusicAppshouldcontinuetoworkasnormal
anypartsoftheUIthatusetheseAPIs.
Creatingyourmodels
Youwillbesettingupyourmodelstomatchthesameschema
youhadfromexercise4.
Inthedemocodefromclass,therewasjustamodelforSongs.
You’llhavetocreateaPlaylistmodel.
Note:youshouldnotneedtodefineyourid–amodelisgiven
anidasit’sprimarykeybydefaultinSequelize.
You’llalsohavetosetupassociationswithyourmodels.Fora
ManyToManyrelationship(whichisthecaseherebecause
songscanbelongtomanyplaylists,andplaylistscancontain
manysongs),you’llwanttousethe.belongsToManymethod
tosetupyourassociations.
Note:youdo*not*needtomanuallycreateaSongsPlaylists
model(unlikelastassignmentwhereyouhadtomanually
associatethedatawithatableyourself).Itwillautomatically
getcreatedforyouaslongasyousetupyourbelongsToMany
associations.(Hint:you’llwanttodothissimilarlytohowit
wasdoneinthisexampleexceptusingbelongsToMany
insteadofbelongsTo.Theclassdemoisbasedoffthislinked
example).
TofurtherunderstandassociationsinSequelize,readthough
this.

Creatingyourdatabase
Inyourpreviousassignment,yourdatabasewascreatedby
runningtheCREATETABLESQLquery.Thistime,youwon’t
interactwithyourdatabasedirectly–thedatabaseandit’s
tableswillbecreatedforyouautomaticallybasedonthe
modelsyoudefine.
Whenyourmodelsareallsetup,runningnode
populateDb.jsshouldcreateaSQLitedatabasedsaved
music.dbdatabasewithyourSong,Playlist,andSongsPlaylists
table,andthedatashouldbepopulatedbywhatisin
songs.jsonandplaylists.json.(inthesamplecode,thedatabase
anddatabasefileusedbySequelizeisspecifiedin
models/index.js).
You’llneedtocreateyoursongsandplaylistsvia
models.Song.createandmodels.Playlist.create.You’ll
needtouseplaylistInstance.addSongtoaddsongsto
yourplaylists.
Note:youdo*not*havetouseyourdatabasefromexercise4.
You’llbestartingfreshwithcreatinganewdatabaseusingthe
SequelizeORM.GettinganORMworkingwithanexisting
databaseisabitofapain.Butifyouareinterestedin
understandinghowtodoit,seethistutorial.
UpdatingyourAPIs
GET/API/SONGS
InsteadofloadingtheJSONfromdisk,youshouldbecrafting
theresponseyourselfbypullingthedatafromthedatabase
usingyourORMandcreatingaJSONobjectfromitthat
matchestheformalfromthepreviousassignment.
ThisshouldreturntheexactsameJSONresponseastheone
fromexercise3.
GET/API/PLAYLISTS
Sameasabove–thisshouldreturntheexactsameJSON
responseastheonefromexercise3.
Remember:thePlaylistmodelitselfdoesnotcontainthe

listsofsongs.Forthat,you’llneedtouse
playlistInstance.getSongs()(oranotherORMmethod
forgettingsongs–justmakesuretousetheORMandnot
directSQLcalls!).
POST/API/PLAYLISTS
Don’tworryaboutupdatingthePOSTrequestinthisexercise.
Thiswillcomeinafutureexercise.
Yes,thatmeansyourMusicAppwillnotbeabletoaddnew
playlists,oraddnewsongstoexistingplaylistsbecauseyour
POSTswillnotinteractwithyourdatabase.Wewillgettothat
inalaterexercise.

RequirementsChecklist
nodepopulateDb.jscreatesaSQLitedatabasecalled

music.db,populatedbythedatafromsongs.jsonand
playlists.jsonfromexercise3,usingonlyORMmethodsto
createtheentriesinthedatabases(norawSQLqueries
allowed).(3marks)

YourGET/api/playlistspullsdatafromthedatabase
viaORMmethodcalls(norawSQLqueriesallowed),and
returnsthesamedataasitdidinexercise3(matchingthe
contentinplaylists.json).(3marks)

YourGET/api/songspullsdatafromthedatabasevia
ORMmethodcalls(norawSQLqueriesallowed),and
returnsthesamedataasitdidinexercise3(matchingthe
contentinsongs.json).(3marks)

YourMusicAppworkswiththeseupdatedGETAPIs
(meaningsongs,playlists,andsongsinplaylistsare
successfullyloadedintoyourUImatchingthemocksfrom
thepreviousexercises).(1mark)

Total:10marks.

Importantnotes
Yournode.jsappmuststartbyrunning“npminstall

&&nodepopulateDb.js&&npmstart”.Using

differentfilenameswillresultinalossof3marks.Ifthis
commanddoesnotrunyourapplicationsuccessfully,we
willnotattempttofigureoutwhy,whichwillresultina
gradeofzero.Makesureyoudeclareyournode.js
dependenciesproperlyinyourpackage.jsonfile!Your
programmustalsoworkwithNode.js6.X.Specifyexactly
whatversionofnodeyouusedinaREADME.mdfile.

Youmayuseexpress.js(node.jsbackendframework)in
thisexercise.Usingexpress.jscanhelpcleanupyour
codebasesignificantly,soI’dhighlyrecommend
incorporatingitintoyourmusicapp!

Youdonothavetoworryaboutresponseefficiency.By
that,Imeandon’tworryifyournotusingstreamsto
respondtorequests–sendingbufferedresponsesisfine
fornow(althoughIhighlyencourageyoutocheckout
streams!).

TheuseofrawSQLqueriesinthisexercisewill
resultyouinagradeof0.Thegoalofthisexerciseistolearn
aboutORMs!

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 程序代写代做代考 database SQL Microsoft Word – Document5
30 $