async function getPersonalData(page) {
	const response = await fetch('/api?page=' + page);
	return await response.json();
}

async function showPersonalData(target) {
	const urlParams = new URLSearchParams(window.location.search); 
	const page = urlParams.get('page') || 1;
	const data = await getPersonalData(page);
	let html = '';
	for(let row of data.rows){
	html += `<tr>
	<td>${row.id}</td>
	<td>${row.name}</td>
	<td>${row.email}</td>
	</tr>`;
	}
	target.innerHTML = html;
	}

async function addPersonalData(data) {
	const response = await fetch('/api/add', {

		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(data)
	});
	return await response.json();
}


async function updatePersonalData(data) {
	const response = await fetch('/api/edit', {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(data)
	});
	return await response.json();
}

async function deletePersonalData(data) {
	const response = await fetch('/api/delete', {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify(data)
	});
	return await response.json();
}