Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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 mysql node js tutorial

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

const app = express();

var corsOptions = {
  origin: "http://localhost:8081"
};

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 esparkinfo application." });
});

// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}.`);
});
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
Sql :: convert google analytics dathourminute to time stamp? sql 
Sql :: sql select data from one database and insert into a different database 
Sql :: backup table mssql 
Sql :: mysql extract days 
Sql :: Adding a new table psql 
Sql :: why do we need data structure in sql 
Sql :: mysql match in serialized data 
Sql :: IDE1006 (Naming rule violation) error problem 
Sql :: ffeathers express mysql application users login 
Sql :: mysql listing get a particu particular user firsdt 
Csharp :: c# get number of files in directory 
Csharp :: unity load scene 
Csharp :: open link c# 
Csharp :: unity check if space pressed 
Csharp :: c# find start and end of month from object date 
Csharp :: asp.net core multiple get methods 
Csharp :: how to run an external program with c# 
Csharp :: how to find object by ag unity 
Csharp :: unity createassetmenu 
Csharp :: how to download file from url using c# 
Csharp :: Animator.GotoState: State could not be found 
Csharp :: c# datagridview clear all rows 
Csharp :: c# get current date 
Csharp :: get hwid c# 
Csharp :: C#: convert array of integers to comma separated string 
Csharp :: system command in c# 
Csharp :: how to access gameobject name 
Csharp :: how to reference text mesh pro unity 
Csharp :: c# create array of number from number 
Csharp :: c sharp gun shooting 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =