blank

mrfdn.com – Sveltekit lagi-lagi menjadi pilihan saya untuk belajar javascript.

Kali ini saya ingin belajar menampilkan data dari sebuah sqlite database menggunakan Svelte dan Svelte Kit.

Buat yang belum tahu, Svelte adalah mesinnya sedangkan Svelte Kit untuk membuat tampilannya.

Kenapa harus capek-capek menampilkan data dari database?

Karena saya ingin membuat sebuah aplikasi soal-soal pilihan ganda. Dimana soal dan jawabannya disimpan pada sebuah database.

Tanpa berlama-lama lagi, begini cara load data dari database dengan sveltekit.

  1. Setup sebuah svelte app npm create svelte@latest my-app.
  2. Setelah itu buatlah sebuah sqlite database. Bisa menggunakan file csv lalu convert menjadi sqlite.db. Lalu simpan file databasenya pada folder root sveltekit.
  3. Setelah itu buat folder dan file /src/api/+server.js.
  4. Pada file +server.js ini isi dengan kode berikut:
import { error, json } from '@sveltejs/kit';import Database from "better-sqlite3";import fs from "node:fs";let db = new Database(fs.readFileSync("mydatabase.db"));export function GET() { const items = db.prepare("select * from mytable"); return json(items.all());}
  1. Edit file /src/routes/+page.svelte menjadi seprti ini.
<script>// untuk bisa load data, pastikan menggunakan onMountimport { onMount } from 'svelte';let items = [];onMount (async () => { const response = await fetch('./api'); items = await response.json();})</script><main><ol> {#each items as item} <li> {item.id} {item.nama} </li> {/each}</ol></main>
  1. Sekarang coba jalankan aplikasi dengan perintah npm run dev di terminal.

Semestinya data sudah tampil pada layar.

Semoga bermanfaat.

PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch

Leave a Reply

Your email address will not be published. Required fields are marked *

TOP