Tired of installing a full blown database just to store a few rows of config and regret your life choices later Use SQLite3 instead It is a zero config SQL database that lives in a single file and does exactly what you expect
Open a shell and create or open a database file
sqlite3 mydb.db
Use plain SQL to define a schema Here is a simple users table
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)
The database file stores both the schema and the rows so deployment is basically copy the file and move on with your life
From a quick shell or from application code insert rows Parameter binding is your friend to avoid SQL injection
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')
From application code use prepared statements and bindings rather than interpolating strings It keeps things predictable and you avoid being that person who left a SQL hole in production
SELECT is all you need to get useful data Use WHERE ORDER BY and LIMIT to slice and dice
SELECT id, name FROM users WHERE name LIKE '%Al%' ORDER BY id LIMIT 10
Wrap related writes in a transaction so a crash does not leave your database in a sad state
BEGIN TRANSACTION
INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com')
COMMIT
Add an index to speed up common lookups
CREATE INDEX idx_users_email ON users (email)
For backups a simple copy of the database file works fine for small apps You can also use your language driver backup functions if you prefer
SQLite supports ALTER TABLE for basic changes For complex migrations the trick is create a new table copy rows and rename tables Keep migration scripts version controlled so your team does not blame the intern
ALTER TABLE users ADD COLUMN created_at TEXT
This tutorial showed how to install and use SQLite3 create and populate tables run queries and manage schema and backups It is ideal for local apps prototypes and small production services where a single file database is a feature not a limitation
Now go make a tiny database and feel superior to anyone running a full server for a single table
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.