Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Sequelize using javascript

// Include Sequelize module.
const Sequelize = require('sequelize')
  
// Import sequelize object, 
// Database connection pool managed by Sequelize.
const sequelize = require('../utils/database')
  
// Define method takes two arguments
// 1st - name of table
// 2nd - columns inside the table
const User = sequelize.define('user', {
  
    // Column-1, user_id is an object with 
    // properties like type, keys, 
    // validation of column.
    user_id:{
  
        // Sequelize module has INTEGER Data_Type.
        type:Sequelize.INTEGER,
  
        // To increment user_id automatically.
        autoIncrement:true,
  
        // user_id can not be null.
        allowNull:false,
  
        // For uniquely identify user.
        primaryKey:true
    },
  
    // Column-2, name
    name: { type: Sequelize.STRING, allowNull:false },
  
    // Column-3, email
    email: { type: Sequelize.STRING, allowNull:false },
  
    // Column-4, default values for
    // dates => current time
    myDate: { type: Sequelize.DATE, 
            defaultValue: Sequelize.NOW },
  
     // Timestamps
     createdAt: Sequelize.DATE,
     updatedAt: Sequelize.DATE,
})
  
// Exporting User, using this constant
// we can perform CRUD operations on
// 'user' table.
module.exports = User
Comment

sequelize with mysql nodejs

const express = require(“express”);
const bodyParser = require(“body-parser”);
const cors = require(“cors”);

const app = express();

Var corsOptons = {
	origin: “http://localhost:8080/”
		};
app.use (cors(corsOptions));

// parse requests of content-type - application/json

app.use (bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded

app.use (bodyParser.urlencoded({extended:true}));

//simple route
app.get (“/”, (req, res) => {
res.json({message: “Welcome to Turing.com”});
});

// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log (‘Server is running on port $(PORT).’ );
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native image border radius not working 
Javascript :: samoglasnici-vowels 
Javascript :: rename files in folder 
Javascript :: how we can set react select required 
Javascript :: Prerequisites before creating react-app 
Javascript :: + sign javascript 
Javascript :: using mongoose with node js 
Javascript :: javaScript throw statement 
Javascript :: terjemahan 
Javascript :: how to add a new line in template literal javascript 
Javascript :: how to pass functions as a props in react js 
Javascript :: datatable ajax reload 
Javascript :: how to write last element of array 
Javascript :: js 2d array includes 
Javascript :: js function definition 
Javascript :: build angular project 
Javascript :: array in js 
Javascript :: break in javascript 
Javascript :: get week number of month from date moment 
Javascript :: new function javascript 
Javascript :: rgba to hex 
Javascript :: javascript Prevent Object MutationPassed 
Javascript :: insert property in json file with bash 
Javascript :: javascript change get parameter without reload 
Javascript :: functions like once 
Javascript :: Biliothek 
Javascript :: javascript sensory errors 
Javascript :: how to push into an array javascript 
Javascript :: redux merge array of objects 
Javascript :: sum of array odd number javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =