JSFiddle - React, Tailwind, and code Playground
by Cody Bennett
JavaScript
/**
* Converts SQL queries, schema, and statements between variants:
*
* @param {string} source - Input SQL
*
* @param {string} source_type - Source SQL variant
* - Greenplum
* - Hive
* - IBM DB2
* - Informix
* - Impala
* - MariaDB
* - Microsoft SQL Server
* - MySQL
* - Netezza
* - Oracle
* - Snowflake
* - Spark SQL
* - Sybase ASE
* - Sybase SQL Anywhere
* - Sybase Advantage
* - PostgreSQL
* - Presto
* - Redshift
* - Teradata
* - Vertica
*
* @param {string} target_type - Target SQL variant
* - Microsoft SQL Server
* - Oracle
* - IBM DB2
* - Hive
* - MySQL
* - MariaDB
* - PostgreSQL
* - Presto
* - Redshift
* - Snowflake
* - Spark SQL
* - Sybase
* - Informix
* - Teradata
* - Greenplum
* - Netezza
* - Vertica
*/
async function convertSQL(options) {
try {
// NodeJS doesn't have window.URLSearchParams
const body = Object.keys(options)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options[key])}`)
.join('&');
// Need to migrate to our own servers for commercial use
const response = await fetch('http://www.sqlines.com/sqlines_run.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body
});
if (response.status !== 200) throw new Error(response.statusText);
const data = await response.json();
return data;
} catch (error) {
console.error(error);
}
}
// Data received from client
const options = {
source: 'SELECT * FROM database;',
source_type: 'Greenplum',
target_type: 'Microsoft SQL Server'
};
convertSQL(options).then(sql => console.log(sql));