Vibe Coding · บทเรียน

การจัดเก็บข้อมูลอย่างง่าย

จากพื้นที่จัดเก็บภายในเครื่องสู่ฐานข้อมูลจริง

บทเรียน 3 จาก 413 ขั้นตอน

การจัดเก็บข้อมูลอย่างง่าย เป็นบทเรียน Vibe Coding ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Vibe Coding และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Vibe Coding มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Data That Sticks Around

Most apps need to remember things: your to-do list, your saved notes, the dark-mode setting you chose. Without storage, everything disappears when you refresh the page.

The good news: you can go from 'remembers nothing' to 'remembers everything' just by describing what to save — AI handles the storage code.

The Storage Ladder

There are levels of storage, from simplest to most powerful. Start low and climb only when you need to:

  • In memory — fast but forgotten on refresh
  • Local storage — saved in the user's browser, survives refresh
  • A database — shared across devices and users, the real deal

Telling AI which rung you want keeps your app as simple as possible.

Saving to the Browser

The easiest persistent storage is localStorage — a little notebook the browser keeps for your app. It's perfect for settings and small lists on a single device.

You don't need a server or account for this. A prompt like the one below adds it instantly.

Make my to-do list save to the browser's
localStorage so my tasks are still there after I
refresh the page. Load them automatically when the
page opens.

How localStorage Works

localStorage stores text by a name (a 'key'). To save objects or lists, you turn them into JSON text first, then turn them back when reading.

Run this to see the pattern AI uses: save a value, then read it back.

const settings = { theme: 'dark', fontSize: 16 };

const saved = JSON.stringify(settings);
console.log('Saved text:', saved);

const loaded = JSON.parse(saved);
console.log('Theme is:', loaded.theme);

When localStorage Isn't Enough

localStorage only lives in one browser on one device. If you want users to see their data on their phone and laptop, or share data between users, you need a database on a server.

That sounds scary, but tools make it easy. You'll describe what to store, and AI sets up the database calls.

Easy Databases for Vibe Coders

You don't need to run your own server. Hosted databases give you storage with almost no setup:

  • Supabase — a friendly database with built-in login, great with AI tools
  • Firebase — Google's real-time database
  • Airtable — a spreadsheet that acts like a database

Builders like Bolt, Lovable and Replit can connect these for you when you ask.

Adding a Database by Prompt

To add real storage, describe what you're saving and where. Naming Supabase (a popular choice) tells AI exactly which setup to generate.

This prompt turns a local-only app into one with a shared, persistent database.

Connect this app to Supabase. Create a table called
notes with columns: id, title, content, and
created_at. Update the app so saving a note inserts
a row, and the homepage loads all notes from the
table, newest first.

Thinking in Tables

A database stores data in tables — like spreadsheets with named columns. A 'notes' table might have a title, content, and a date. Each saved note is one row.

You don't need to master database design. Just tell AI what fields each thing has, and it builds the table for you.

Create, Read, Update, Delete

Almost every data app does four things, nicknamed CRUD: Create new items, Read them back, Update them, and Delete them. If your app can do all four, it's a real tool.

You can ask AI to add them one at a time, testing each before moving on.

Add full editing to my notes app: I should be able
to create a note, edit an existing note's title and
content, and delete a note with a confirm dialog.
Keep everything saved to Supabase.

Start Simple, Upgrade Later

The pro move is to start at the lowest rung that works. Building a quick prototype? localStorage. Need it on every device? Move up to a database. AI can even migrate you — 'switch my app from localStorage to Supabase.'

Don't over-engineer early. Match the storage to what your app actually needs today.

My app currently uses localStorage. Migrate it to
use Supabase instead so my data syncs across
devices, and move any existing local data into the
database on first load.

Backups and Not Losing Data

Data is precious — users get upset if it vanishes. Hosted databases like Supabase and Firebase keep backups for you, which is another reason to graduate from localStorage for anything important.

You can also let users export their own data as a safety net. Ask AI to add a one-click backup so nobody loses their work.

Add a "Download backup" button that exports all my
notes from the database as a JSON file, and an
"Import backup" option that restores them. This
way users never lose their data.

Quick Check

You built a notes app that uses the browser's localStorage. A user complains they can't see their notes when they open the app on their phone. What kind of storage do they actually need?

Recap: Storing Data Simply

You learned the storage ladder: in-memory, then localStorage for single-device persistence, then a real database for cross-device, shared data.

You saw how to save settings in the browser, when to upgrade to hosted databases like Supabase, how data lives in tables, and the CRUD actions every data app needs. Start simple and let AI upgrade you. Next: keeping your API keys and secrets safe.

เริ่มต้นได้ฟรี

เรียนรู้ JavaScript ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
25
บทเรียน
100

คำถามที่พบบ่อย

บทเรียน “การจัดเก็บข้อมูลอย่างง่าย” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การจัดเก็บข้อมูลอย่างง่าย” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Vibe Coding ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Vibe Coding มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การจัดเก็บข้อมูลอย่างง่าย”

จากพื้นที่จัดเก็บภายในเครื่องสู่ฐานข้อมูลจริง คุณปฏิบัติ Vibe Coding ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Vibe Coding หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Vibe Coding บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การจัดเก็บข้อมูลอย่างง่าย” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Vibe Coding นี้ได้ไหม

ได้ บทเรียน Vibe Coding ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การสื่อสารกับ API
  2. การอ่านและบันทึกไฟล์
  3. การจัดเก็บข้อมูลอย่างง่าย
  4. การจัดการความลับและคีย์
← กลับไปที่ Vibe Coding