Skip to content

javaquery/SQLAnalyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLAnalyzer

SQLAnalyzer, an Open source SQL Query analysis library. Now don't just write SQL Query, understand the behind scene actions.

Why SQLAnalyzer created?

Developer thinks having high processing hardware allows them to interact database with unstructured SQL Query. Well writing structured query is really a big deal.

Now Developer can optimize the SQL Query in development phase using SQLAnalyzer and SQL Queries will give their best on Production environment. SQLAnalyzer can generate Graphical Analysis report of your SQL Query right from the CODE no extra configuration required on database.

#Features

✔ Analyze SQL Query ✔ Analyze SQL Plans
✔ Graphical Representation ✔ Query Statistics
✔ Browser based HTML Report ✔ Lightweight

#Database Support

✔ Microsoft SQL Server ✔ MySQL (5.6 or above)
✔ PostgreSQL

#Source code (Step 1) Create class and extend Database Service. [MSSQLServiceImpl, MySQLServiceImpl, PostgreSQLServiceImpl]

package com.sqlanalyzer.test;

import com.sqlanalyzer.database.service.MySQLServiceImpl;

/**
 * @author vicky.thakor
 */
public class MySQLApi extends MySQLServiceImpl{

    @Override
    public String DatabaseDriver() {
        return "com.mysql.jdbc.Driver";
    }

    @Override
    public String DatabaseHost() {
        return "jdbc:mysql://localhost:3306/sqlanalyzer";
    }

    @Override
    public String DatabaseUsername() {
        return "root";
    }

    @Override
    public String DatabasePassword() {
        return "root";
    }
}

#Source code (Step 2) Generate report from SQL Query. [Note: Real query must be execcuted before preparing report.]

public static void main(String[] args) throws IOException {
        List sQLPlans = new SQLAnalyzer(MySQLApi.class, null)
                .initDatabaseConnection()
                .fromQuery("select * from user_master this_ inner join message messages1_ on this_.id=messages1_.user_id inner join creditcard creditcard2_ on this_.id=creditcard2_.user_id where this_.email='vicky.thakor@javaquery.com'")
                .save("D:\\SQLAnalyzer\\MySQL", "SELECT", "_STAR")
                .generateReport();
        
        for (SQLPlan sqlPlan : sQLPlans) {
            /**
             * Customize graphical report as per your requirement.
             * Put String `htmlReport` anywhere between  block.
             */
            String htmlReport = sqlPlan.getHTMLReport();
            
            /* Open report saved to Physical location. */
            Desktop.getDesktop().open(sqlPlan.getReportFile());
        }
}

#Sample Reports https://javaquery.github.io/SQLAnalyzer/

#Add-ons

#Warning SQLAnalyzer is analysis tool and should be used at development phase. It'll cost a lot on Production environment so comment/delete SQLAnalyzer code before you deploy your code on Production environment.