SQLite 임베디드 데이터베이스
임베디드 SQLite 데이터베이스를 사용해 Electron 앱에 구조화되고 조회 가능한 데이터를 저장하고, 키-값 저장소와 원시 파일을 넘어서는 방법을 배웁니다.
SQLite 임베디드 데이터베이스은(는) CoddyKit의 무료 Electron Desktop App Development 강의입니다. 이것은 3개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Electron Desktop App Development 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Electron Desktop App Development 강의에는 총 3개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
When Files Are Not Enough
Key-value storage and flat files work for small data. For relational, queryable data, an embedded database like SQLite is the right tool.
Why SQLite for Desktop
SQLite is serverless and stores everything in a single file. It ships inside your app, no installation needed by the user.
Choosing a Driver
Popular Node drivers include better-sqlite3 (synchronous, fast) and sqlite3 (async). Run database code in the main process.
const Database = require('better-sqlite3');
const db = new Database('app.db');Creating a Table
Define your schema once with CREATE TABLE IF NOT EXISTS so it is safe to run on every launch.
db.exec('CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT)');Inserting Rows
Use prepared statements with placeholders to insert data safely.
const insert = db.prepare('INSERT INTO notes (body) VALUES (?)');
insert.run('Buy groceries');Querying Data
Read rows back with all() for many or get() for one.
function buildQuery(table) {
return 'SELECT * FROM ' + table;
}
console.log(buildQuery('notes'));Parameterize Everything
Never concatenate user input into SQL. Placeholders prevent SQL injection and quoting bugs.
function isSafe(query) {
return query.includes('?');
}
console.log(isSafe('SELECT * FROM notes WHERE id = ?'));Exposing Data to the Renderer
The renderer should never touch the DB directly. Expose query functions through a preload bridge over IPC.
ipcMain.handle('notes:list', () => {
return db.prepare('SELECT * FROM notes').all();
});Migrations
As your schema evolves, track a user_version and apply migrations step by step on startup.
Where to Store the File
Place the database in the user-data directory via app.getPath('userData') so it survives updates and is writable.
const path = require('path');
function dbPath(userData) {
return path.join(userData, 'app.db');
}
console.log(dbPath('/home/user/.config/myapp'));Transactions for Safety
Wrap multiple writes in a transaction so they all succeed or all roll back, keeping data consistent.
Quick Check
Test your SQLite knowledge.
Recap
You learned to add structured persistence with SQLite: choosing a driver, creating tables, using prepared statements, exposing data over IPC, storing the file in userData, and using transactions and migrations.
AI 튜터와 함께 JavaScript을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 12
- 레슨
- 47
자주 묻는 질문
“SQLite 임베디드 데이터베이스” 강의는 무료인가요?
네 — “SQLite 임베디드 데이터베이스” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Electron Desktop App Development 강의 전체를 잠금 해제할 수 있습니다. Electron Desktop App Development 강의에는 총 3개의 강의가 포함되어 있습니다.
“SQLite 임베디드 데이터베이스”에서 뭘 배우나요?
임베디드 SQLite 데이터베이스를 사용해 Electron 앱에 구조화되고 조회 가능한 데이터를 저장하고, 키-값 저장소와 원시 파일을 넘어서는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Electron Desktop App Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Electron Desktop App Development을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Electron Desktop App Development은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 3개 중 3번째 강의입니다.
“SQLite 임베디드 데이터베이스” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Electron Desktop App Development 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Electron Desktop App Development 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 로컬 저장소 및 IndexedDB
- 파일 시스템 액세스
- SQLite 임베디드 데이터베이스