UNTANGLING THE WEB
FALL 2017 WEEK 8 – PROJECT 2, DEEPER INTO DATABASES, ASYNCHRONOUS
JAVASCRIPT, NOTES ABOUT NODE
AGENDA
• Project 2 presentations
• Asynchronous javascript
• Promises
• Async/await
• Databases – SQL vs. NoSQL
• Looking more at NodeJS
• Routes and views
• How to render to the client
• A more detailed look at Cloudant programming
• Getting ready for project 3
PROJECT 2 PRESENTATIONS
• Keep it under 5 minutes
• Show off all the functionality in your front end
• Talk about the business model, including value proposition (pains and gains)
• Make sure you have emailed me
• A link to github
• A link to the running website
• SEO, business model canvas, value proposition canvas links
REVIEW OF FUNCTIONS
• A block of named code able to be called from other places
• Variables in js are untyped, so they can hold function references
• Parameters to a function can also be functions
• Anonymous function – a function that is not given a name but is rather just passed to another function
A FEW UTILITY FUNCTIONS WE’LL RUN INTO TODAY
• setTimeout(function, delay in ms) – delay and then call a function
• Math.random – generate a random number
• Math.ceil – round up
ASYNCHRONOUS JAVASCRIPT
• What’s a callback? You’ve used them before! In the maps example
• What’s a promise?
• What’s a promise chain?
• Anyone come across async/await?
CALLBACK EXAMPLE
• https://jsfiddle.net/3cew460a/
• https://www.youtube.com/watch?v=QqiNn3GfTMc
PROMISE EXAMPLE
• https://jsfiddle.net/s3m4xv1o/
• https://www.youtube.com/watch?v=VmMDG6h-bVQ
PROMISE CHAINING EXAMPLE
• https://jsfiddle.net/8Lf4zof3/
• https://www.youtube.com/watch?v=a1cTkiNuEwM
ASYNC/AWAIT
• It is an ES7 feature, so will have to use babel as a transpiler if we want to use it
• https://www.youtube.com/watch?v=COKdtOgopWQ
DATABASES
• SQL versus noSQL
• Flavours of SQL and noSQL
• Why use a database at all?
• Advanced database topics
• Schema design
• Replication
• Transactions
SQL VERSUS NOSQL
• SQL – Structured Query Language
• Relational database
• Use when you need multiple tables and
when you need to construct queries that
span those tables
• More functional than flat databases, but
also slower and more complex
• Can exist in either client or server
flavours
 NoSQL databases – anything that isn’t relational!
 MongoDB is a popular server-based flavor
 Redis is a local memory-mapped flavor
 Cloudant, couchDB, etc. there are many, many
types
 All are good for rapid, flat table access
 Avoid the complexities of relational databases
while still preserving the benefits
LOCAL SQL EXAMPLE – CARS DATABASE
• https://jsfiddle.net/m5rh3a83/1/
• (for more details see here: https://www.tutorialspoint.com/html5/html5_web_sql.htm)
MORE REALISTIC SQL EXAMPLE
• http://sqlfiddle.com/#!9/1d643/23
• (video help here: https://www.youtube.com/watch?v=DDVOMRvyAS4)
SQLZOO
• http://sqlzoo.net/
• Go do some exercises!
• (https://www.sqlteaching.com is an alternative if you want some more exercises)
MULTIPLE TABLES
• You will usually have more than one table
• If you have only one table, it is time to consider a NoSQL database
• Look on SQLZoo for the JOINS sections and make sense of that
• http://sqlzoo.net/wiki/The_JOIN_operation
• If you want more complex examples on a real database you can play here:
• http://data.stackexchange.com/stackoverflow/queries
• More about joins
• https://blog.codinghorror.com/a-visual-explanation-of-sql-joins/
POSTGRESSQL ON BLUEMIX
• Here’s a decent started project: https://github.com/IBM-Bluemix/compose-postgresql-helloworld-
nodejs
FOR PROJECT 3
• You’ll have to decide whether to use a flat database, like the cloudant example we walked through last
week, or a relational database like postgresSQL
• How do you make that decision?
• Complexity of your data
• Performance requirements
• Development difficulty
NODEJS
• We’ll look through:
• Package.json (review)
• App.js (the webserver)
• Routes and views
CONCEPTS (ALSO TO BE COVERED IN MORE DETAIL
NEXT WEEK)
• JSON and how to parse it
• http get, put, post, delete, etc. (reminder about CRUD pattern)
• Nodejs
• Require statement
• App.js
HOMEWORK 8 (DUE START OF CLASS NOV 1ST)
• Submit a github link with a file containing the query and results for each question
• Using the stackoverflow database here: http://data.stackexchange.com/stackoverflow/queries
• List the oldest 10 Victoria, BC users and order them by age.
• List the top 10 highest reputation users in Victoria that have answered questions with the tag javascript.
• List the top 5 Victoria developers by accepted answer percentage
• List the top 10 Victoria developers by accepted answer percentage on questions with the tag javascript
PROJECT 3
• If anyone needs to change groups get it figured out this week
• You’ll need to implement a database backend for your project and a chatbot
• Database should have new item, search, and delete (optionally edit) from the ui
• You’ll need to host your project on bluemix
• You’ll need to show a working demo of project 2 hooked up to these backend services

Untangling - fall2017 - week 8

  • 1.
    UNTANGLING THE WEB FALL2017 WEEK 8 – PROJECT 2, DEEPER INTO DATABASES, ASYNCHRONOUS JAVASCRIPT, NOTES ABOUT NODE
  • 2.
    AGENDA • Project 2presentations • Asynchronous javascript • Promises • Async/await • Databases – SQL vs. NoSQL • Looking more at NodeJS • Routes and views • How to render to the client • A more detailed look at Cloudant programming • Getting ready for project 3
  • 3.
    PROJECT 2 PRESENTATIONS •Keep it under 5 minutes • Show off all the functionality in your front end • Talk about the business model, including value proposition (pains and gains) • Make sure you have emailed me • A link to github • A link to the running website • SEO, business model canvas, value proposition canvas links
  • 4.
    REVIEW OF FUNCTIONS •A block of named code able to be called from other places • Variables in js are untyped, so they can hold function references • Parameters to a function can also be functions • Anonymous function – a function that is not given a name but is rather just passed to another function
  • 5.
    A FEW UTILITYFUNCTIONS WE’LL RUN INTO TODAY • setTimeout(function, delay in ms) – delay and then call a function • Math.random – generate a random number • Math.ceil – round up
  • 6.
    ASYNCHRONOUS JAVASCRIPT • What’sa callback? You’ve used them before! In the maps example • What’s a promise? • What’s a promise chain? • Anyone come across async/await?
  • 7.
    CALLBACK EXAMPLE • https://jsfiddle.net/3cew460a/ •https://www.youtube.com/watch?v=QqiNn3GfTMc
  • 8.
    PROMISE EXAMPLE • https://jsfiddle.net/s3m4xv1o/ •https://www.youtube.com/watch?v=VmMDG6h-bVQ
  • 9.
    PROMISE CHAINING EXAMPLE •https://jsfiddle.net/8Lf4zof3/ • https://www.youtube.com/watch?v=a1cTkiNuEwM
  • 10.
    ASYNC/AWAIT • It isan ES7 feature, so will have to use babel as a transpiler if we want to use it • https://www.youtube.com/watch?v=COKdtOgopWQ
  • 11.
    DATABASES • SQL versusnoSQL • Flavours of SQL and noSQL • Why use a database at all? • Advanced database topics • Schema design • Replication • Transactions
  • 12.
    SQL VERSUS NOSQL •SQL – Structured Query Language • Relational database • Use when you need multiple tables and when you need to construct queries that span those tables • More functional than flat databases, but also slower and more complex • Can exist in either client or server flavours  NoSQL databases – anything that isn’t relational!  MongoDB is a popular server-based flavor  Redis is a local memory-mapped flavor  Cloudant, couchDB, etc. there are many, many types  All are good for rapid, flat table access  Avoid the complexities of relational databases while still preserving the benefits
  • 13.
    LOCAL SQL EXAMPLE– CARS DATABASE • https://jsfiddle.net/m5rh3a83/1/ • (for more details see here: https://www.tutorialspoint.com/html5/html5_web_sql.htm)
  • 14.
    MORE REALISTIC SQLEXAMPLE • http://sqlfiddle.com/#!9/1d643/23 • (video help here: https://www.youtube.com/watch?v=DDVOMRvyAS4)
  • 15.
    SQLZOO • http://sqlzoo.net/ • Godo some exercises! • (https://www.sqlteaching.com is an alternative if you want some more exercises)
  • 16.
    MULTIPLE TABLES • Youwill usually have more than one table • If you have only one table, it is time to consider a NoSQL database • Look on SQLZoo for the JOINS sections and make sense of that • http://sqlzoo.net/wiki/The_JOIN_operation • If you want more complex examples on a real database you can play here: • http://data.stackexchange.com/stackoverflow/queries • More about joins • https://blog.codinghorror.com/a-visual-explanation-of-sql-joins/
  • 17.
    POSTGRESSQL ON BLUEMIX •Here’s a decent started project: https://github.com/IBM-Bluemix/compose-postgresql-helloworld- nodejs
  • 18.
    FOR PROJECT 3 •You’ll have to decide whether to use a flat database, like the cloudant example we walked through last week, or a relational database like postgresSQL • How do you make that decision? • Complexity of your data • Performance requirements • Development difficulty
  • 19.
    NODEJS • We’ll lookthrough: • Package.json (review) • App.js (the webserver) • Routes and views
  • 20.
    CONCEPTS (ALSO TOBE COVERED IN MORE DETAIL NEXT WEEK) • JSON and how to parse it • http get, put, post, delete, etc. (reminder about CRUD pattern) • Nodejs • Require statement • App.js
  • 21.
    HOMEWORK 8 (DUESTART OF CLASS NOV 1ST) • Submit a github link with a file containing the query and results for each question • Using the stackoverflow database here: http://data.stackexchange.com/stackoverflow/queries • List the oldest 10 Victoria, BC users and order them by age. • List the top 10 highest reputation users in Victoria that have answered questions with the tag javascript. • List the top 5 Victoria developers by accepted answer percentage • List the top 10 Victoria developers by accepted answer percentage on questions with the tag javascript
  • 22.
    PROJECT 3 • Ifanyone needs to change groups get it figured out this week • You’ll need to implement a database backend for your project and a chatbot • Database should have new item, search, and delete (optionally edit) from the ui • You’ll need to host your project on bluemix • You’ll need to show a working demo of project 2 hooked up to these backend services