Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js and Code First

I've worked on Entity Framework with Code First approach. Now I am learning Node.js I wonder is there a way to make the same code first approach using Node.js and some libraly? I am thinking of using MySql as database.

like image 553
Daniel petrov Avatar asked Jan 26 '16 09:01

Daniel petrov


People also ask

Is Node JS good for startup?

Node. js is a great platform for startups because it enables them to build highly scalable systems without requiring any special expertise or knowledge on server-side programming like Java or . Net. A start-up can save time and money by using Node.

Is it worth learning node JS in 2021?

According to Stack Overflow Research, Node. js is widely used for back-end development and is the worldwide leader among frameworks. Many experts believe that whether or not node js is worth learning in 2021 relies on your own preferences.


1 Answers

You can look into Sequelize. Example of usage from the home page (I added comments to relate to Code First):

var Sequelize = require('sequelize');
// define your "context"
var sequelize = new Sequelize('database', 'username', 'password');

// define your "entities"
var User = sequelize.define('user', {
  username: Sequelize.STRING,
  birthday: Sequelize.DATE
});

// use them
sequelize.sync().then(function() {
  return User.create({
    username: 'janedoe',
    birthday: new Date(1980, 6, 20)
  });
}).then(function(jane) {
  console.log(jane.get({
    plain: true
  }));
});
like image 114
Shanoor Avatar answered Sep 19 '22 15:09

Shanoor