Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const addColumnBtn = document.getElementById('add-column');
+ const columnsContainer = document.getElementById('columns-container');
+ const generateBtn = document.getElementById('generate');
+ const copyBtn = document.getElementById('copy');
+ const sqlOutput = document.getElementById('sql-output');
+
+ function createColumnInput() {
+ const div = document.createElement('div');
+ div.className = 'column-input';
+
+ const input = document.createElement('input');
+ input.type = 'text';
+ input.placeholder = 'Column name';
+
+ const removeBtn = document.createElement('button');
+ removeBtn.className = 'btn remove-column';
+ removeBtn.textContent = '×';
+ removeBtn.onclick = () => div.remove();
+
+ div.appendChild(input);
+ div.appendChild(removeBtn);
+ columnsContainer.insertBefore(div, addColumnBtn);
+ }
+
+ function generateSQL() {
+ const tableName = document.getElementById('table-name').value;
+ const queryType = document.getElementById('query-type').value;
+ const columns = Array.from(document.querySelectorAll('.column-input input'))
+ .map(input => input.value)
+ .filter(val => val.trim());
+
+ let sql = '';
+
+ switch(queryType) {
+ case 'select':
+ sql = `SELECT ${columns.join(', ') || '*'}\nFROM ${tableName};`;
+ break;
+ case 'insert':
+ sql = `INSERT INTO ${tableName} (${columns.join(', ')})\nVALUES (${columns.map(() => '?').join(', ')});`;
+ break;
+ case 'update':
+ sql = `UPDATE ${tableName}\nSET ${columns.map(col => `${col} = ?`).join(', ')}\nWHERE condition;`;
+ break;
+ case 'delete':
+ sql = `DELETE FROM ${tableName}\nWHERE condition;`;
+ break;
+ }
+
+ sqlOutput.textContent = sql;
+ }
+
+ addColumnBtn.addEventListener('click', createColumnInput);
+ generateBtn.addEventListener('click', generateSQL);
+
+ copyBtn.addEventListener('click', () => {
+ navigator.clipboard.writeText(sqlOutput.textContent);
+ copyBtn.textContent = 'Copied!';
+ setTimeout(() => {
+ copyBtn.textContent = 'Copy to Clipboard';
+ }, 2000);
+ });
+
+ // Add initial column input
+ createColumnInput();
+ });