mysql framework for node.js - mysql

Is there any mysql framework for node.js?
I found only https://github.com/felixge/node-mysql but this only allows executing "raw" mysql statements. I am looking for some tool which will provide easier way of manipulating mysql database and data.
Especially I need pagination and joining mechanisms...
I am not looking for a full framework because I am using restify to build RESTapi - just need a module to retrieve/save data to mysql db. So I need only "model" part of MVC ;).

It sounds like you may be looking for an ORM. If that's the case, you can take a look at Sequelize. It will let you define your objects, and then simply 'save' and 'fetch' them, without really having to worry about how its doing it.

You can look at db-mysql module. This module provides api for creating queries. Here is module GitHub page.

Related

How to use same MySQL database with both Django and Express.js together?

For Django, ORM makes it very easy to manage tables so I am using Django to manage the outline of the database. How to use express.js to use the same database so that IDEs can suggest field names and queries? Ideally the goal is to avoid or minimize typing manual sql queries in express.js.
You could use API, between Django and Express, but it doesn't make sense to use both of them because both are backend frameworks.
If the only purpose of Django is managing tables, use Sequelize with express.js instead.
Also, most IDE can't suggest field name and queries between different runtimes, say python and node.js, unless there is an extension hack built around it.

Can I use GraphQL for mongoDB or mySQL?

I have started learning GraphQL and found that GraphQL is an awesome query language.
However I wonder if I can use GraphQL for existing databases such as mongoDB or mySQL.
Also please explain about prisma.
Is prisma a cloud database or something?
Edit:
TL;DR:
GraphQL can be used with any database as long as the data satisfies the type-strict qualification. Prisma is a node.js/typescript ORM library and works great with GraphQL.
Looking back to this a bit old question, I noticed that the question was so dumb and a bit too wide. So I've decided to add some more thoughts as I'm now quite familiar with GraphQL and Prisma. Hope this could be a help for new developers who are starting to learn GraphQL and Prisma.
GraphQL is a query language that we can use to interact with the API.
Like the REST API, GraphQL is another type of API format where we can use Queries to get data and Mutations to update data.
As the REST API doesn't depend on the database type, GraphQL can also be used with any database as long as the data can be formatted into type-strict models.
On the backend side tho, you need to implement the GraphQL interface that reads data from the database and sends as the Query response, and updates the database with the data from the Mutation.
Prisma on the other hand is a node.js/typescript ORM library - similar to mongoose or sequelize. The benefits of using Prisma is that it auto-generates the TS models and makes it much easier to interact with the database in typescript.
As GraphQL and Prisma are both strict in type usages, they match quite well. Also, Prisma provides an exclusive interface for GraphQL implementation, so you can easily write GraphQL interface with Prisma.
Please check out here for more information on the combination of GraphQL and Prisma: https://www.prisma.io/graphql
It was a long edit, but hope this helps.
As it was mentioned on previous post - yes, you can.
An example, if you backend application wrote on .NET stack - you may use, guess two, main libs that really tested and guys use it in real projects (google GraphQL.Net and second lib should be spelled almost the same)
But, both of these libs give you only processing of graphql queries and describe schemes ("accounts {id name}" means you should define resolver which returns data from db or another data source)
Most of guys use EF (EntityFramework) as a data-adapter between GraphQL and db. But, from my point of view it's useless, especially, if we are talking about get data from db and that may be thousands requests.
We implemented component that based on light-weight DB lib (to almost all popular dbs like MSSQL, Postgresql, MySQL or Elasticsearch), gives ability to configure GraphQL scheme very easy and provide main features like sort, pagination and complex filter.
Yes, you can use it with existing DB.
Prisma is an ORM layer build using GraphQL server, it abstracts away the database and let you interact with the database using GraphQL query. It currently supports MySQL, MongoDB, AWS RDS & PostgreSQL. It's not a database, but you can host it on the cloud.
Typically, you need another GraphQL server that inside it resolvers will call Prisma's GraphQL server. This GraphQL server is the one that is called by the client.

meteor reporting of data in existing mysql db. how?

I'm trying to make some reports using meteor and raphael js. I have to report data from an existing MySQL database. I do not wish to write to that database. I need only the "R" from CRUD.
I have thought of various manual ways of: exporting .csv files from the MySQL db via the application itself (Limesurvey) and using mongoimport to populate a MongoDB collection, and then do my CollectionName.find() etc in Meteor.
or perhaps some way of exposing REST full endpoints only to consume data, and use the http package for Meteor.
Is there a good clean solution for using existing SQL data in a Meteor JS application?
How can one use pre-existing SQL data?
(I've no problem with duplication in MongoDB, mind you. however it has to be...)
Thank You
You can do it without any duplication completely from inside Meteor, but you will have to jump through a couple of hoops.
Firstly, use the mysql npm package to query the SQL database. Though Meteor provides Npm to require node packages, I find that using meteor-npm is an easier. Then to do the "R"eading form MySQL, create a Meteor.method on your server which queries the MySQL directly.
Then the second problem is that the mysql package is completely asynchronous. Hence, the execution of the SQL query returns value in a call back and by that point, your Meteor.method call would return leaving the client with an undefined. To fix that issue, we can use Future.
There are a couple of ways of smoothing over this step:
Using `meteor-sync-methods
Spinning out your own version from advice from the issue to allow this natively
Use this easy to implement one-time pattern: "fence has already activated -- too late to add writes"
Hope that helps.

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?
Sequelize is pretty good ORM for MySQL and has excellent documentation. You can use node-migrate for migrations.
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
You can use light-orm and mysql:
https://npmjs.org/package/light-orm - ORM wrapper
https://npmjs.org/package/mysql - Driver
Bookshelf.js is also pretty good, but, in some aspects, not flexible. For example, you can not execute SQL request and convert result to models. So, use light-orm.

Migrating subsets of production data back to dev

In our rails app we sometimes have db entries created by users that we'd like to make part of our dev environment, without exporting the whole table. So, we'd like to be able to have a special 'dev and testing' dump.
Any recommended best practices? mysqldump seems pretty cumbersome, and we'd like to pull in rails associations as well, so maybe a rake task would make more sense.
Ideas?
You could use an ETL tool like Pentaho Kettle. Once you have initial transformation setup that you want you could easily run it with different parameters in the future. This way you could also keep all your associations. I wrote a little blurb about Pentaho for another question here.
If you provide a rough schema I could probably help you get started on what your transformation would look like.
I had a similar need and I ended up creating a plugin for that. It was developed for Rails 2.x and worked fine for me, but I didn't have much use for it lately.
The documentation is lacking, but it's pretty simple. You basically install the plugin and then have a method to_sql available on all your models. Options are explained in README.
You can try it out and let me know if you have any issues, I'll try to help.
I'd go after it using a Rails runner script. That will allow your code to access the same things your Rails app would, including the database initializations. ActiveRecord will be able to take advantage of the model relationships you've defined.
Create some "transfer" tables in your production database and copy the desired data into those using the "runner" script. From there you could serialize the data, or use a dump tool, since you'll be dealing with a reduced amount of records. Reverse the process in the development environment to move the data into the database.
I had a need to populate the database in one of my apps from remote web logs and wrote a runner script that fired off periodically via cron, ftps the data from my site and inserts the data.