Search code examples
mysqlnode.jsjugglingdb

Using arbitrary mySQL Query with JugglingDB?


I am currently using juggling db with NodeJS for ORM. I now need to do some reporting, which involves joining data from several tables using arbitrary SQL with SUM and GROUP BY too. How would I do this using the jugglingdb framework, and get a list of objects containing data from several columns.


Solution

  • You can access to the query function from the mysql package using the adapter client:

    var Schema = require('jugglingdb').Schema;
    var schema = new Schema('mysql', {
     // your config
    });
    
    schema.client.query('your very wild query', function(err, data) {
     // data will be an Array of Objects if no error
    });
    

    Actually this is a direct call to the query function of node-mysql package