14

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);
x29a
  • 1,761
  • 1
  • 24
  • 43
Safwan Ull Karim
  • 652
  • 5
  • 10
  • 20
  • check this: http://blog.ragingflame.co.za/2014/7/21/using-nodejs-with-mysql – malyy Dec 02 '15 at 09:53
  • One thing I don't really understand: why are you using **Mongoose**? If you enter [**Mongoose's site**](http://mongoosejs.com/index.html) it clearly says: `mongoose: elegant mongodb object modeling for node.js` – charliebrownie Dec 02 '15 at 10:14
  • @charliebrownie i was following a tutorial series where he used this code. But I like mysql better so thats why i was looking for an alternative. – Safwan Ull Karim Dec 02 '15 at 12:36
  • Oh, all right, I thought you were trying to use mongoose on a MySQL database. In this case, you will have to use a **MySQL driver** like [this one (node-mysql)](https://github.com/felixge/node-mysql). – charliebrownie Dec 02 '15 at 13:00
  • any luck with that? did you find any solution? – Keyur Shah Sep 30 '16 at 07:47

1 Answers1

9

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

MAN
  • 425
  • 1
  • 4
  • 11