Why i need to use Navicat for a database of mysql using node.js ?? - mysql

Am able to connect to database in node.js but i wonder where to create, store and retrieve my tables .

Try using sequelize js ORM,
http://docs.sequelizejs.com/en/latest/docs/schema/
This module can be used for defining the tables,
By the way no need to navicat for this, in case you have specific requirement please brief here.

Related

What is the correct way of structuring mySQL code in a nodejs projects?

I have been working on a project lately and using node as my back-end but instead of Mongodb I am using MySQL as my DBMS as I will need it in my project but I am having trouble organizing MySQL queries and can't find a good solution that helps me structure my code and files right. And another issue is that I don't know when to close my connection or if leaving it is a good practice or not.
NOTE: I already use express generator for generating my file architecture my only problem is where to place the MySQL related code and what are the best practices for a clean code.
You can create a model folder and add all your 'tables'.js there.
You can also create a DB.js file, so you can use Mysql from Nodejs and also manipulate it from the prompt:
Model Exemple
I.e of DB connection:
DB Connection
You can create tables on the way below. ID's, creating date and updated date are created automatically by Nodejs, so you don't need to worry about.
how to create a table
You also will need to download mySQL (npm install MySQL --save) and to interact with MySQL (selects, deletes,...)
Another way is create a repository.js and add SQL queries there, but is not really useful since you are using nodejs and it provides you these queries.

Mongoose / Mongodb migration to MySQL

I have a NodeJS project running with mongodb database (using mongoose).
For a technological constraint reason I need to migrate the app from using mongodb to mysql - is there a way to migrate to mysql without having to rewrite the whole mongoose model files?
PS. although I'm using mongodb all the query is mainly still not on the nested document (I'm querying only by ID or by some first-level attribute) so actually putting nested document into a field in mysql table should still be fine
I would suggest letting your application run with Mongo for now. Meanwhile write a wrapper for MySQL that would translate your Mongo queries to mysql. Switch to that wrapper once done. Then write another wrapper for Mongo, just in case you need to switch back.
Try and keep all your Database specific function calls in the wrapper. So, that you won't need to do this again and again. Just write a new wrapper for whatever Database you will use and just switch.
And you'll probably need to run some sort of job to migrate your data from Mongo to MySQL.

NodeJS application database versioning and data migration

I am planning to use Postgres as my database and sequelize as my ORM framework one of my NodeJS project. I need your suggestion on how to accomplish database table changes in production enviroment.
For example , we deployed our version-1 application with some database schema.
Later , there is a change in my schema in Version-2. Say one of the table is altered and few columns are dropped and few columns are added.
Also one of the table itself is not required in Version-2.
In my production , I have some database with data. When I install Version-2 of my NodeJS application , I need to keep the old data as it is and apply the new database schema of Version-2.
How to achieve this , Let me point out some reference to this.
Thanks
Sequelize (or rather, sequelize-cli) has built in support for migrations.
You can write migrations using the Sequelize js api (e.g. queryInterface.dropColumn('users', 'address')) or write raw SQL and pass it to sequelize.query()

Do i really need to define models in sequelizejs?

I'm playing around with expressjs for a while and now the time has come to connect to a mysql database. Now i'm searching for a way to write and retrieve data from it. Normally i'm creating the database tables with MySQL Workbench. I'm using MySQL because of the ability of using ForeignKeys. Couldn't figure out yet how to do it in other database types...
Currently i'm more used to medoo for PHP. It only connected to a database and gave me the ability to access it in an object oriented way.
Is there a similar module for nodejs out there?
Try knex for a sql-builder library, it's pretty solid and looks sort of similar to medoo (but it uses Promises and is asynchronous).

Using existing mysql schema in nodejs

I tried using sequelize and node-orm as well - but is there a way to reuse existing mysql schema? I Have a db schema defined with tables in mysql and wanted to use this with my node.js app (using express). So, I don't have to write all the define methods of defining tables again.
Any help appreciated...
I went through bunch of stackoverflow questions already such as: Which ORM should I use for Node.js and MySQL?
Thanks,
JP
Checkout bookshelf.js, it doesn't require that you define the schema in the model layer.