134 lines
3.6 KiB
HTML
134 lines
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>DAO & RowMapper Generator</title>
|
|
<link rel="stylesheet" href="./css/bootstrap.min.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-sm my-4">
|
|
<ul class="nav nav-pills">
|
|
<li class="nav-item"><a href="index.html" class="nav-link active">Schema Info</a></li>
|
|
<li class="nav-item"><a href="generate-daos-row-mapper.html" class="nav-link">DAO Generator</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-sm">
|
|
<h2 class="mb-4">Schema Definition</h2>
|
|
</div>
|
|
</div>
|
|
<form class="form" data-schema-form>
|
|
<div class="form-row">
|
|
<div class="form-group col-sm">
|
|
<label>DB Name</label>
|
|
<input type="text" class="form-control" value="inventory" data-db-name>
|
|
</div>
|
|
<div class="form-group col-sm">
|
|
<label>Username</label>
|
|
<input type="text" class="form-control" value="root" data-db-user>
|
|
</div>
|
|
<div class="form-group col-sm">
|
|
<label>Password</label>
|
|
<input type="password" class="form-control" value="qwerty" data-db-password>
|
|
</div>
|
|
<div class="form-group col-sm">
|
|
<label>Host</label>
|
|
<input type="text" class="form-control" value="localhost" data-db-host>
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-primary">Get Schema Info</button>
|
|
</form>
|
|
<div class="bg-light p-3 mt-5" data-results></div>
|
|
</div>
|
|
|
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
|
<script>
|
|
(async function( $ ) {
|
|
// caching dom elements
|
|
let $formDb = $( '[data-schema-form]' ),
|
|
$inputDbName = $( '[data-db-name]' ),
|
|
$inputDbUser = $( '[data-db-user]' ),
|
|
$inputDbPass = $( '[data-db-password]' ),
|
|
$inputDbHost = $( '[data-db-host]' ),
|
|
$inputClassPath = $( '[data-class-path]' ),
|
|
$containerResults = $( '[data-results]' );
|
|
|
|
// function to prepare html string
|
|
let showSchemaStr = function( schemaInfo ) {
|
|
let htmlStr = '<div>';
|
|
for ( table in schemaInfo ) {
|
|
htmlStr += '<div class="mb-3">';
|
|
htmlStr += `<h5>Table: ${table}</h5>`;
|
|
|
|
// console.log( schemaInfo[table] );
|
|
for ( column in schemaInfo[table] ) {
|
|
htmlStr += `<div><code>${column}: ${schemaInfo[table][column]}</code></div>`;
|
|
}
|
|
|
|
// query string
|
|
htmlStr += '<br />'
|
|
htmlStr += '<div><code>INSERT INTO %s (';
|
|
let columnCount = 0;
|
|
for ( column in schemaInfo[table] ) {
|
|
columnCount++;
|
|
htmlStr += `${column}`;
|
|
if ( columnCount < Object.keys( schemaInfo[table] ).length ) {
|
|
htmlStr += ', ';
|
|
}
|
|
}
|
|
htmlStr += ') VALUES (';
|
|
columnCount = 0;
|
|
for ( column in schemaInfo[table] ) {
|
|
columnCount++;
|
|
htmlStr += `:${column}`;
|
|
if ( columnCount < Object.keys( schemaInfo[table] ).length ) {
|
|
htmlStr += ', ';
|
|
}
|
|
}
|
|
htmlStr += ') ON DUPLICATE KEY UPDATE ';
|
|
columnCount = 0;
|
|
for ( column in schemaInfo[table] ) {
|
|
columnCount++;
|
|
if ( 'id' === column ) {
|
|
continue;
|
|
}
|
|
htmlStr += `${column} = :${column}`;
|
|
if ( columnCount < Object.keys( schemaInfo[table] ).length ) {
|
|
htmlStr += ', ';
|
|
}
|
|
}
|
|
htmlStr += '</code></div>';
|
|
|
|
htmlStr += '</div><hr />';
|
|
}
|
|
|
|
htmlStr += '</div>';
|
|
return htmlStr;
|
|
};
|
|
|
|
|
|
$formDb.on( 'submit', async function( e ) {
|
|
e.preventDefault();
|
|
|
|
let schemaInfo = await $.post( 'http://localhost:3001/get-schema-info', {
|
|
dbConfig: {
|
|
host: $inputDbHost.val(),
|
|
user: $inputDbUser.val(),
|
|
password: $inputDbPass.val(),
|
|
database: $inputDbName.val(),
|
|
insecureAuth: true
|
|
},
|
|
classpath: $inputClassPath.val()
|
|
} );
|
|
|
|
$containerResults.html( showSchemaStr( schemaInfo ) );
|
|
});
|
|
|
|
})( jQuery );
|
|
</script>
|
|
</body>
|
|
</html> |