Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js doesn't have a good ORM for managing MySQL schema/migrations...so can I use SQLAlchemy to manage it?

I need to use Node.js, but it doesn't have a good ORM for MySQL. So I'm planning on using SQLAlchemy to define my schema. And then use node-mysql to do low-level queries (of course, I wouldn't be able to use SQLAlchemy's query language coz it's in python.)

What do you guys think?

sequelize seems to be the best one...but it doesn't seem that many people are using it. Also, what about migrations? How would I handle that?

node-orm doesn't seem very active either.

Thoughts on this?

like image 958
user847495 Avatar asked Nov 22 '11 22:11

user847495


People also ask

Does node js have ORM?

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8).

Should you use ORM in node JS?

Different database systems access data in myriad ways, and ORM helps you maintain objects even when the sources and apps they access change over time. ORM is commonly used to streamline the migration of data between databases. Before we get to the reasons why you shouldn't use ORM with Node.

Which DB is best for NodeJS?

js supports all kinds of databases no matter if it is a relational database or NoSQL database. However, NoSQL databases like MongoDb are the best fit with Node. js. To access the database from Node.


2 Answers

Sequelize is pretty good ORM for MySQL and has excellent documentation. You can use node-migrate for migrations.

like image 137
alessioalex Avatar answered Oct 03 '22 18:10

alessioalex


We are using Sequelize.js in our Node project and I guess it kind of does the job done but there are gotchas. One example is that the MySQL Sequelize query engine does case sensitive string matching on the SQL string that you feed it (this.sql.indexOf('SELECT') == 0). This means it can fail if your SQL happens to be lowercase. SQL keywords are usually case insensitive (although upper case by convention) so the Sequelize implementation seems like a hack.

There is migration support in Sequelize as of version 1.3.0 but I haven't used it and I'm considering rolling my own instead.

I come from a background of having used the Ruby ActiveRecord ORM and in light of this and the gotcha mentioned above I'm hesitant to recommend Sequelize. Unfortunately, I don't know what better alternatives are out there.

UPDATE1: there are other ORMs suggested under "Which ORM should I use for Node.js and MySQL?".

UPDATE2: I've released my Sequelize.js migration code on Github

like image 5
Peter Marklund Avatar answered Oct 02 '22 18:10

Peter Marklund