Generate DML file from DDL file #459
Replies: 1 comment 4 replies
-
Hi, Yes, Benerator can generate 'INSERT' queries by understanding a static DDL (Data Definition Language) schema. Below is a sample configuration that demonstrates how to use Benerator to create and populate tables based on a given schema. <setup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.benerator.de/schema/3.0.0"
xsi:schemaLocation="https://www.benerator.de/schema/3.0.0 https://www.benerator.de/schema/benerator-3.0.0.xsd"
defaultDataset="US" defaultLocale="en_US">
<!-- Define a database that will be referred to by the id 'db' later -->
<comment>Define a database that will be referred to by the id 'db' subsequently</comment>
<database id="db" url="jdbc:hsqldb:mem:benerator" driver="org.hsqldb.jdbcDriver" user="sa" schema="PUBLIC"
tableFilter="db_.*"/>
<!-- Drop existing tables if they exist -->
<execute target="db" onError="warn">
DROP TABLE IF EXISTS "playlist";
DROP TABLE IF EXISTS TRACK;
DROP TABLE IF EXISTS PLAYLIST_TRACK;
</execute>
<!-- Create tables based on the schema definition -->
<execute target="db">
CREATE TABLE "playlist" (
PLAYLIST_ID int NOT NULL,
name varchar(16) NOT NULL,
PRIMARY KEY (PLAYLIST_ID)
);
CREATE TABLE TRACK (
TRACK_ID int NOT NULL,
name varchar(16) NOT NULL,
PRIMARY KEY (TRACK_ID)
);
CREATE TABLE PLAYLIST_TRACK (
PLAYLIST_ID int NOT NULL,
TRACK_ID int NOT NULL,
name varchar(16) NOT NULL,
unique (PLAYLIST_ID, TRACK_ID)
);
</execute>
<!-- Generate data for the 'playlist' table -->
<generate type="playlist" count="20" consumer="db">
<id name="PLAYLIST_ID" type="int" generator="IncrementGenerator"/>
</generate>
<!-- Generate data for the 'TRACK' table -->
<generate type="TRACK" count="20" consumer="db">
<id name="TRACK_ID" type="int" generator="IncrementGenerator"/>
</generate>
<!-- Generate data for the 'PLAYLIST_TRACK' table with references to 'playlist' and 'TRACK' tables -->
<generate type="PLAYLIST_TRACK" count="20" consumer="db">
<reference name="PLAYLIST_ID" type="int" source="db" targetType="playlist" unique="true"/>
<reference name="TRACK_ID" type="int" source="db" targetType="TRACK" unique="true"/>
</generate>
<!-- Output generated data to the console -->
<echo>Printing generated data</echo>
<iterate type="playlist" source="db" consumer="ConsoleExporter"/>
<iterate type="TRACK" source="db" consumer="ConsoleExporter"/>
<iterate type="PLAYLIST_TRACK" source="db" consumer="ConsoleExporter"/>
<!-- Verify the generated data by counting the records -->
<echo>Verifying generated data</echo>
<evaluate assert="result == 20" target="db">select count(*) from "playlist"</evaluate>
<evaluate assert="result == 20" target="db">select count(*) from "TRACK"</evaluate>
<evaluate assert="result == 20" target="db">select count(*) from "PLAYLIST_TRACK"</evaluate>
</setup> Explanation:
This configuration will generate and insert data into the database tables based on the schema definition provided. The generated data can then be used for testing or development purposes, ensuring it adheres to the constraints of the schema. Feel free to reach out if you have any more questions or need further assistance! |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi.
https://docs.benerator.de/latest/introduction_to_benerator.html
This explain us that benerator can understand schema and generate data with connecting live database.
Can benerator generate 'INSERT' query with understanding static DDL?
I want to prepare test/develop data which follow any condition of schema model.
Beta Was this translation helpful? Give feedback.
All reactions