GithubHelp home page GithubHelp logo

jeanbisutti / quick-sql-test-data Goto Github PK

View Code? Open in Web Editor NEW

This project forked from quick-perf/quick-sql-test-data

0.0 0.0 0.0 194 KB

Quickly create your SQL test data

Home Page: https://quickperf.io

License: Apache License 2.0

Java 100.00%

quick-sql-test-data's Introduction

Quick SQL test data

Maven Central    License    Build Status  

Why use Quick SQL test data?

Writing datasets with SQL may be tedious and time-consuming because of database integrity constraints.

This Java library aims to ease the generation of datasets to test SQL queries. It produces INSERT statements taking account of integrity constraints.

The library automatically:

  • identifies NOT NULL columns and provides values by requesting the database
  • adds rows of dependent tables in case of foreign key constraints
  • sorts insert statements to accommodate foreign key constraints
  • sorts insert statements following primary key values

Another project provides a web page to ease the use of the Quick SQL test data library.

How to use the library

With Maven, you have to add the following dependency:

<dependency>
    <groupId>org.quickperf</groupId>
    <artifactId>quick-sql-test-data</artifactId>
    <version>0.1-SNAPSHOT</version>
</dependency>

You can generate the insert statements with the help of an instance of org.qstd.QuickSqlTestData class.

Quick SQL test data works with:

  • PostgreSQL
  • Oracle
  • MariaDB
  • MySQL
  • Microsoft SQL Server
  • H2
  • HSQLDB

Use cases

This library can be helpful in the two following situations.

Create a dataset before starting the writing of an SQL query

This case happens when you develop SQL queries with Test-Driven Development (TDD).

You can read below an example where we define a dataset row for which we generate the INSERT statement:

QuickSqlTestData quickSqlTestData = QuickSqlTestData.buildFrom(dataSource);
DatasetRow datasetRow = DatasetRow.ofTable("Player")
                                  .addColumnValue("lastName","Pogba");
List<String> insertStatements = quickSqlTestData.generateInsertListFor(datasetRow);

System.out.println(insertStatements);

The console displays the following result:

[INSERT INTO PLAYER(FIRSTNAME, LASTNAME) VALUES('Paul', 'Pogba')]

FIRSTNAME column owns a NOT NULL constraint. For this reason, the library has retrieved a FIRSTNAME value for the Pogba LASTNAME and has used it in the generated statement.

Test an existing SQL query

Let's take an example:

QuickSqlTestData quickSqlTestData = QuickSqlTestData.buildFrom(dataSource);
String selectStatement = "SELECT * FROM Player WHERE LASTNAME = 'Pogba'";
String insertScript = quickSqlTestData.generateInsertScriptFor(selectStatement);
System.out.println(insertScript);

The console displays the following queries:

INSERT INTO TEAM(ID, NAME) VALUES(1, 'Manchester United');
INSERT INTO PLAYER(ID, FIRSTNAME, LASTNAME, TEAM_ID) VALUES(1, 'Paul', 'Pogba', 1);

The library has done its best to generate INSERT queries allowing to test the SELECT query. It has detected a foreign key constraint and has generated a first statement inserting on a Team table. This one contains a value for the NAME column that must not be null.

License

Apache License 2.0

quick-sql-test-data's People

Contributors

ftarfasse avatar jeanbisutti avatar jlecordier avatar quick-perf avatar raychenon avatar smorineau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.