ORM & Using Sequelize ORM with Express (Node.js)

Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages(WIKI).ORM converts data between type systems that cannot co-exist. Sequelize is a promise-based ORM (Object relation model) for Node.js. It supports the dialects PostgreSQL, MySQL, SQLite, MSSQL and features solid transaction support, relations, read replication and more. For creating sequelize connection in Express, use the following code. Here we create a connection to ‘user’ database

Now create a folder ‘model’ . For each table in the database we create a model file. In our example, we have a users model users.js

Now Create an index.js file inside the model folder

Now the above code in index.js file helps us use all model files inside our model folder. For understanding more about sequelize, refer  http://docs.sequelizejs.com/ How to  handle errors in sequelize query Consider the below example in which we do a CREATE which insert data into  a table





Binary Tree,Max Heap, Priority Queue and implementation using Javascript
programming concepts , Javascript / June 9, 2018

Binary tree is a tree in which every node can have maximum of 2 children.In a binary tree data structure , every parent node can have at most two child nodes.Below is an example of a binary tree. The node with value 100 is the root node.The value 50 and 20 are leaves. A max-heap is a complete binary tree (every node has two children apart from leaves) in which the value in each  node is greater than or equal to the values in the children of that node. It means that the value of the root node will be the maximum.For a min heap the value at the root node should be the minimum. Below you can find example of a max-heap. The array representation of the above binary heap is given below.We start indexing from 1 and leave the 0th index.

  As you can understand, for every node with index i ,the left child is having index 2i and the right child is having index 2i+1.The children are filled in from the left  . If we add another number 50 ,then it will be the child  of  14( 4th index).

So while on insertion , heap is…

Share this page in social media platforms