Node & SQL assignment

Story points 5
Tags node sql
Hard Prerequisites
  • PROJECTS: SQL
  • WORKSHOPS: [TODO] Introduction to Node and SQL
  • PROJECTS: Node & File IO

  • You are required to create a back-end service that will help capture basic information about prospective students who come to inquire here at Umuzi.

    database setup

    1. Set up a postgresql database on your computer. Please use Docker to do this. You can find more information here: TOPICS: Intro to Docker and Docker-compose
    2. Create a table inside the database and name it Visiters.
    3. The table must contain the following fields :
    • id: This should be automatically generated by SQL
    • visitor name
    • visitor’s age
    • date of visit
    • time of visit
    • name of the person who assisted the visitor
    • comments

    Helloworld

    Before you dive into anything too intense, let’s make sure that you can get node to connect to your database. Can you get this Node script to run:

    
    // npm install --save pg
    // find out more here: https://node-postgres.com/
    
    const Pool = require("pg").Pool;
    const pool = new Pool({
      user: "user",
      host: "localhost",
      database: "db",
      password: "pass",
      port: 5432
    });
    
    const helloWorld = () => {
      pool.query(
        "SELECT $1::text as message",
        ["Hello world!"],
        (error, results) => {
          if (error) {
            throw error;
          }
    
          console.log(results.rows);
        }
      );
    };
    
    helloWorld();
    
    

    Functionality

    Create a single index script with the following functions:

    • addNewVisitor. This should save the Visitor into the database
    • list all visitors. This should return an array of all the visitor names and ids
    • delete a visitor
    • update a visitor
    • view one visitor: given a visitor’s id, return all information about that visitor
    • delete all visitors

    NOTE

    You will be expected to properly test your code. You can use whatever testing framework you want. If you use something that isn’t taught at Umuzi please justify your choice (if you found something cool we might incorporate it into the syllabus)

    Resources


    RAW CONTENT URL