SQLite: CRUD, Migrations & Prepared Statements | Go Tutorial #33
11views
0018:05
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Learn how to work with databases in Go! Using database/sql with a pure Go SQLite driver (modernc.org/sqlite) - no CGO or C compiler needed.
📚 What you'll learn:
- sql.Open("sqlite", "file.db") to connect to SQLite
- db.Exec() for CREATE TABLE, INSERT, UPDATE, DELETE
- ? placeholders to prevent SQL injection
- db.QueryRow().Scan() for single-row queries
- db.Query() with rows.Next() and rows.Scan() for multiple rows
- result.LastInsertId() and result.RowsAffected()
- Full CRUD operations with verification after each mutation
- PRAGMA user_version for schema version tracking
- Migrations with db.Begin() / tx.Commit() transactions
- ALTER TABLE and CREATE INDEX in migration functions
- Idempotent migration runner
- db.Prepare() for efficient batch inserts
- sql.NullString for nullable column handling
- Aggregate queries: COUNT(*), SUM(price)
- Transactions: db.Begin(), tx.Exec(), tx.Commit(), tx.Rollback()
⏱️ Timestamps:
0:00 - Introduction
0:30 - SQLite Basics (Connect, Create, Insert, Query)
4:09 - CRUD Operations (Insert, Update, Delete with verification)
8:01 - Schema Migrations (PRAGMA user_version, transactions)
12:38 - Advanced Queries (Prepared statements, NullString, transactions)
17:41 - Recap
18:11 - Up Next: Testing in Go
💻 Code: https://github.com/GoCelesteAI/go_sqlite_database
🔔 Subscribe for more Go tutorials!
Tags
golanggoprogrammingtutorialsqlitedatabasesqldatabase/sqlCRUDmigrationstransactionsprepared statementssql.NullStringmodernc.org/sqlitego tutorial
Back to tutorialsOpen in YouTube
Duration
18:05
Published
February 6, 2026
Added to Codegiz
March 15, 2026