Sunday, July 28, 2019

ER Diagram



  • 1976 proposed by Peter Chen
  • An ER diagram is widely used in database design
    • Represent the conceptual level of a database system
    • Describe things and their relationships at a high level
Basic Concepts
  • Entity set – an abstraction of similar things, 
    • E.g:- cars, students
  • An entity set contains many entities
    • Entities are represented by means of rectangles. 
    • Rectangles are named with the entity set they represent.
    • E.g:- Teacher, Student, Project.


  • Attributes: Common properties of the entities in an entity sets. Attributes are represented by means of ellipses. Every ellipse represents one attribute and is directly connected to its entity.


Attribute

  • Composite VS Simple Attributes
  • Single valued VS Multivalued Attributes
  • Stored VS Derived Attributes
  • Complex Attributes 

Relationship – specify the relations among entities from two or more entity sets
A relationship where two entities are participating is called a binary relationship. Cardinality is the number of instance of an entity from a relation that can be associated with the relation.

 One-to-one 

One-to-many

many-to-one

many-to-many


Keys

Key is an attribute or collection of attributes that uniquely identifies an entity among the entity set.

1.    Super Key − A set of attributes (one or more) that collectively identifies an entity in an entity set.
2.    Candidate Key − A minimal super key is called a candidate key. An entity set may have more than one candidate key.
3.    Primary Key − A primary key is one of the candidate keys chosen by the database designer to uniquely identify the entity set.













             








    Thursday, July 18, 2019

    Present Perfect Continuous Tense

    This tense express an action that started in past and continued to present or recently stopped. It is used to state an ongoing action that has started at a point in the past. A time-reference is also used in the sentence to show that when the action started in past or for how long the action continued.

    The specific words 'since' and 'for' are used in sentence to show the time of action. The word 'since' is used if the exact starting time of action is known or intended to be reflected in the sentence. The word 'for' is used to express the amount of time for which the action was continued.

    Structure of Sentence.

    Tuesday, July 16, 2019

    Node.js MongoDB



    • Node.js can be used in database applications.
    • One of the most popular NoSQL databases is MongoDB. 
     Creating a Database
    • To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct IP address and the name of the database you want to create.

    • MongoDB will create the database if it does not exist, and make a connection to it.
    Example :
     create a database called "my_data"

                     var MongoClient = require('mongodb').MongoClient;
                     var url = "mongodb://localhost:27017/my_data";

                     MongoClient.connect(url, function(err, db) {
                     if (err) throw err;
                     console.log("Database created!");
                     db.close();
                     });


    Creating a Collection
    • To create a collection in MongoDB, use the createCollection( ) method
    Example :
           Create a collection called "customers"

                       var MongoClient = require('mongodb').MongoClient;
                       var url = "mongodb://localhost:27017/";

                       MongoClient.connect(url, function(err, db) {
                             if (err) throw err;
                             var dbo = db.db("my_data");
                             dbo.createCollection("customers", function(err, res) {
                                 if (err) throw err;
                                 console.log("Collection created!");
                                 db.close();
                            });
                      });


    Insert into Collection 
    • To insert a record, or document as it is called in MongoDB, into a collection, we use the insertOne( ) method.
    • document in MongoDB is the same as a record in MySQL
    • The first parameter of the insertOne( ) a method is an object containing the name(s) and value(s) of each field in the document you want to insert.
    • It also takes a callback function where you can work with any errors or the result of the insertion:
    Example :
         Insert a document in the "customers" collection:
                  var MongoClient = require('mongodb').MongoClient;
          var url = "mongodb://localhost:27017/";

          MongoClient.connect(url, function(err, db) {
             if (err) throw err;
             var dbo = db.db("my_data");
             var myobj = { name: "Company Inc", address: "Highway 37" };
             dbo.collection("customers").insertOne(myobj, function(err, res) {
                if (err) throw err;
                console.log("1 document inserted");
                db.close();
             });
         });


    Insert Multiple Documents

    • To insert multiple documents into a collection in MongoDB, we use the insertMany( ) method.
    • The first parameter of the insertMany( ) a method is an array of objects, containing the data you want to insert.
    • It also takes a callback function where you can work with any errors or the result of the insertion:
    Example :
        Insert multiple documents in the "customers" collection:
        var MongoClient = require('mongodb').MongoClient;
        var url = "mongodb://localhost:27017/";

        MongoClient.connect(url, function(err, db) {
           if (err) throw err;
           var dbo = db.db("my_data");
           var myobj = [
             { name: 'John', address: 'Highway 71'},
             { name: 'Peter', address: 'Lowstreet 4'},
             { name: 'Amy'address: 'Apple st 652'},
             { name: 'Hannah', address: 'Mountain 21'},
             { name: 'Michael', address: 'Valley 345'},
             { name: 'Sandy', address: 'Ocean blvd 2'},
             { name: 'Betty', address: 'Green Grass 1'}
           ];
           dbo.collection("customers").insertMany(myobj, function(err, res) {
             if (err) throw err;
             console.log("Number of documents inserted: " +                       res.insertedCount);
             db.close();
           });
         });


    Node.js MongoDB Find
    •  In MongoDB we use the find and findOne methods to find data in a collection.
    •  Just like the SELECT statement is used to find data in a table in a MySQL database.
    Find One
    • To select data from a collection in MongoDB, we can use the findOne() method.

    • The findOne() method returns the first occurrence in the selection.

    • The first parameter of the findOne() method is a query object. In this example we use an empty query object, which selects all documents in a collection (but returns only the first document).
    Example :
     Find the first document in the customers collection:

    var MongoClient = require('mongodb').MongoClient;
    var url = "mongodb://localhost:27017/";

    MongoClient.connect(url, function(err, db) {
      if (err) throw err;
      var dbo = db.db("mydb");
      dbo.collection("customers").findOne({}, function(err, result) {
        if (err) throw err;
        console.log(result.name);
        db.close();
      });
    });


    Find All
                








    Present Perfect Tense

    Present Perfect Tense is used to express an action that occurred or completed at some point in past. This tense expresses an idea of completion or occurrence of an action in past without giving an idea about the exact time of its occurrence. Though, the time of the action is not exactly known, this tense is mostly used to refer to actions completed in the recent past (not a very long time ago).

    • Positive Sentences
                Subject + Auxiliary verb + Main verb + Object
                Subject + Have/Has + Past Participle (3rd form of verb) + An Object

    Examples :
    1. The guests have arrived.
    2. I have eaten my meal.
    3. You have done a nice job.
    4. He has received my letter.
    5. She has given me her books.
    6. They have helped us.
    • Negative Sentences
                 Subject + Auxiliary verb + Main verb + Object
                 Subject + Have/Has + NOT + Past Paticiple + Object
    Examples :
    1. You have not completed you work.
    2. She has not applied for a job.
    3. He has not brought the table.
    4. They have not enjoyed the party.
    5. They have not called us.
    6. He has not started a business.
    7. She has not come.
    • Interrogative Sentences
             Auxiliary verb + Subject + Main verb + Object
             Have/Has + Subject + Past Participle + Object
    Examples : 

    1. Have you prepared yourself for the exam?
    2. Has she brought her camera?
    3. Has he finished his work?
    4. Have they played a game?
    5. Have the kids eaten their food?
    6. Have I send you a mail?

    Sunday, July 7, 2019

    Present Continous Tense

    What Is Present Continuous Tense?

    Present continuous tense, otherwise known as the present progressive tense, is formed when the present tense of the 'to be' verb is connected with a present participle. A present participle is a verb that ends in '-ing'. The present continuous tense allows the speaker to talk about things that are and that are not happening now, temporarily, repeatedly, and in the near future. In this lesson, we will go over the uses of present continuous tense and look at examples to help you fully understand how to properly use this tense in a sentence.

    Present Continuous Tense Uses

    The present continuous tense cannot be used with non-continuous verbs or mixed verbs. A non-continuous verb is a verb that cannot be physically seen. For example, the verbs 'to love', 'to own', and 'to need' are examples of non-continuous verbs. A mixed verb is a verb that can have multiple meanings and behave like a normal or non-continuous verb. The verbs 'to have' and 'to miss' are examples of mixed verbs.
    Let's gain an understanding of the other rules for using present continuous tense by looking at a few examples, starting with talking about the present. The present continuous tense can be used to talk about the present when the speaker is referring to something that is happening in that moment or something that occurs before or after a certain time.
    If something is or is not happening at the moment, the speaker might say:
    • I'm running to the store; I'll be home later.
    • The baby is sleeping.
    • I am not eating doughnuts for breakfast.
    If something is happening before or after a certain time, the speaker might say:
    • At two in the afternoon, we are eating lunch.
    • When you come home, dinner is cooking in the oven.

    Thursday, July 4, 2019

    Node.js


    What is Node.js?



  • Node.js is an open source server environment
  • Node.js is free
  • Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • Node.js uses JavaScript on the server


    • Why Node.js?
      A common task for a web server can be to open a file on the server and return the content to the client.
      Here is how PHP or ASP handles a file request :
      1. Sends the task to the computer's file system.
      2. Waits while the file system opens and reads the file.
      3. Returns the content to the client.
      4. Ready to handle the next request.
      Here is how Node.js handles a file request :
      1. Sends the task to the computer's file system.
      2. Ready to handle the next request.
      3. When the file system has opened and read the file, the server returns the content to the client.
      Node.js eliminates the waiting, and simply continues with the next request.
      Node.js runs single-threaded, non-blocking, asynchronously programming, which is very memory efficient.

      What Can Node.js Do?







    • Node.js can generate dynamic page content
    • Node.js can create, open, read, write, delete, and close files on the server
    • Node.js can collect form data
    • Node.js can add, delete, modify data in your database

      • What is a Node.js File?

        • Node.js files contain tasks that will be executed on certain events
        • A typical event is someone trying to access a port on the server
        • Node.js files must be initiated on the server before having any effect
        • Node.js files have extension ".js"
        Install Node.js via NVM

        Step 01
                sudo apt-get update
        Step 02
                sudo apt-get install build-essential libssl-dev
        Step 03
                sudo curl https://raw.githubusercontent.com/creationix/num/v0.33.11/install.sh / bash
           If no curl
                    https://raw.githubusercontent.com/creationix/num/v0.33.11/install.sh / bash
        Step 04
                    source ~/.profile

        Step 05 

               nvm --version
        Step 06
               nvm install 6.16.0
        Step 07
               nvm ls
        Step 08      
                node --version
        Step 09
                npm --version


        What is a Module in Node.js?

        • Consider modules to be the same as JavaScript libraries.
        • A set of functions you want to include in your application.

        Include Modules

        • To include a module, use the require() function with the name of the module
         
        • Now your application has access to the HTTP module, and is able to create a server


        • Now you can include and use the module in any of your Node.js files.

        Node.js as a File Server

        Common use for the File System module:
        1. Read Files
        2. Create Files
        3. Update Files
        4. Delete Files
        5. Rename Files
        Read Files
        The fs.readFile( ) method is used to read files on your computer.

        Create Files
        The File System module has methods for creating new files:

        • fs.appendFile( )
                   The fs.appendFile( ) method appends specified content to a file. If the file does not               exist, the file will be created:
                   Example:

        • fs. open( )
                     The fs.open( ) method takes a "flag" as the second argument, if the flag is "w" for                  "writing", the specified file is opened for writing. If the file does not exist, an empty                  file is  created:
                    Example:

        • fs.writeFile( )
                    The fs.writeFile( ) method replaces the specified file and content if it exists. If the 
                     file does not exist, a new file, containing the specified content, will be created:
                    Example:
        Update Files
        The File System module has methods for updating files:
        • fs.appendFile( )
        • fs.writeFile( )
        Delete Files
        To delete a file with the File System module,  use the fs.unlink( ) method.
        • fs.unlink( )
        Rename Files
        To rename a file with the File System module,  use the fs.rename( ) method.
        • fs.rename( )
        Upload Files
        Step 1 : Create an Upload Form

        Example :

        var http = require('http');

        http.createServer(function (req, res) {
          res.writeHead(200, {'Content-Type''text/html'});
          res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
          res.write('<input type="file" name="filetoupload"><br>');
          res.write('<input type="submit">');
          res.write('</form>');
          return res.end();
        }).listen(8080);

        Step 2 : Parse the Uploaded File
        • Include the Formidable module to be able to parse the uploaded file once it reaches the server.
        • When the file is uploaded and parsed, it gets placed on a temporary folder on your computer.

        Example :


        var formidable = require('formidable');

        http.createServer(function (req, res) {
          if (req.url == '/fileupload') {
            var form = new formidable.IncomingForm();
            form.parse(req, function (err, fields, files) {
              res.write('File uploaded');
              res.end();
            });
          else {
            res.writeHead(200, {'Content-Type''text/html'});
            res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
            res.write('<input type="file" name="filetoupload"><br>');
            res.write('<input type="submit">');
            res.write('</form>');
            return res.end();
          }
        }).listen(8080);

        Step 3 : Save the File
        • When a file is successfully uploaded to the server, it is placed on a temporary folder.
        • The path to this directory can be found in the "files" object, passed as the third argument in the parse( ) method's callback function.
        • To move the file to the folder of your choice, use the File System module, and rename the file:
        Example :

        var http = require('http');
        var formidable = require('formidable');
        var fs = require('fs');
        http.createServer(function (req, res) {
          if (req.url == '/fileupload') {
            var form = new formidable.IncomingForm();
            form.parse(req, function (err, fields, files) {
              var oldpath = files.filetoupload.path;
              var newpath = 'C:/Users/Your Name/' + files.filetoupload.name;
              fs.rename(oldpath, newpath, function (err) {
                if (err) throw err;
                res.write('File uploaded and moved!');
                res.end();
              });
         });
          else {
            res.writeHead(200, {'Content-Type''text/html'});
            res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
            res.write('<input type="file" name="filetoupload"><br>');
            res.write('<input type="submit">');
            res.write('</form>');
            return res.end();
          }
        }).listen(8080);


        Express

        What is Express? Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develo...