Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create mysql schema in nodejs

I am using nodejs, express framework and mysql for my database. I would like to know how can I replicate this mongoose code using mysql. I cannot find a way to write my sql schema in a nodejs file. Do I have to use workbench for this? Thanks!

var mongoose = require('mongoose');

var userSchema = mongoose.Schema({
    local: {
            username: String,
            password: String
         }
 });

module.exports = mongoose.model('User', userSchema);
like image 382
Safwan Ull Karim Avatar asked Dec 02 '15 09:12

Safwan Ull Karim


People also ask

How do I create a database schema in MySQL?

Steps to create a schema in MySQLOpen the MySQL Workbench. Click the Create Schema option. Provide a schema name. Click apply to create the MySQL scheme.

How do I create a schema in MySQL script?

Open the MySQL Workbench as an administrator (Right-click, Run as Admin). Right-click on the list of existing Schemas and select Create Schema... to create the database schema. Enter a name for the schema and for collation choose 'utf - utf8_bin'. Then click Apply.


1 Answers

you can use any of:
bookshelf
knex
objection
orm
sequelize

see compare between that:

https://npmcompare.com/compare/bookshelf,knex,objection,orm,sequelize

This tutorial maybe help you to use of "sequelize": Creating a Role-Based User Authentication System with Angular, Express and MySQL

like image 80
MAN Avatar answered Sep 24 '22 19:09

MAN