Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quick-perf/quick-sql-test-data
Quickly create your SQL test data
https://github.com/quick-perf/quick-sql-test-data
code-generator database h2 hsqldb java mariadb mssql mysql oracle postgresql sql sql-query tdd tdd-framework tdd-sql tdd-utilities test testing
Last synced: 12 days ago
JSON representation
Quickly create your SQL test data
- Host: GitHub
- URL: https://github.com/quick-perf/quick-sql-test-data
- Owner: quick-perf
- License: apache-2.0
- Created: 2021-04-15T09:57:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-22T09:39:41.000Z (about 2 years ago)
- Last Synced: 2024-10-17T12:29:46.116Z (22 days ago)
- Topics: code-generator, database, h2, hsqldb, java, mariadb, mssql, mysql, oracle, postgresql, sql, sql-query, tdd, tdd-framework, tdd-sql, tdd-utilities, test, testing
- Language: Java
- Homepage: https://quickperf.io
- Size: 199 KB
- Stars: 15
- Watchers: 2
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Quick SQL test data
## 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](https://github.com/quick-perf/quick-sql-test-data-web) 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:
```xml
org.quickperf
quick-sql-test-data
0.1```
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:
```java
QuickSqlTestData quickSqlTestData = QuickSqlTestData.buildFrom(dataSource);
DatasetRow datasetRow = DatasetRow.ofTable("Player")
.addColumnValue("lastName","Pogba");
List 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:```java
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](/LICENSE.txt)