feat: add SQL/SQLite, AppSec, Capstone incident-tracker, Gitea Actions CI and spaced repetition
Test and Lint / quality (push) Successful in 1m50s
Test and Lint / quality (push) Successful in 1m50s
This commit is contained in:
1 parent
015eae08c3
commit
9130af822e
19 files changed
+722
-7
No files matched your search
@@ -0,0 +1,29 @@
|
||||
# SQL i Bazy Danych w Ruście (`rusqlite`, `sqlx`, SQLite, PostgreSQL)
|
||||
|
||||
SQL pojawia się w **~22% wszystkich ofert IT w Polsce**. W Ruście dwa główne narzędzia to **`rusqlite`** (synchroniczny SQLite, świetny do CLI i narzędzi lokalnych) oraz **`sqlx`** (asynchroniczny SQL z weryfikacją zapytań w czasie kompilacji pod PostgreSQL/SQLite/MySQL).
|
||||
|
||||
---
|
||||
|
||||
## 1. Podstawy SQL i `rusqlite`
|
||||
|
||||
```sql
|
||||
CREATE TABLE IF NOT EXISTS incidents (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
severity TEXT NOT NULL CHECK (severity IN ('low', 'medium', 'high', 'critical')),
|
||||
status TEXT NOT NULL DEFAULT 'open'
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_incidents_status_sev ON incidents(status, severity);
|
||||
```
|
||||
|
||||
## 2. Zawsze parametryzowane zapytania (`params![]`)
|
||||
```rust
|
||||
// ŹLE (SQL Injection!):
|
||||
conn.execute(&format!("DELETE FROM services WHERE name = '{input}'"), [])?;
|
||||
|
||||
// DOBRZE (parametryzowane zapytanie):
|
||||
conn.execute("DELETE FROM services WHERE name = ?1", params![input])?;
|
||||
```
|
||||
|
||||
## 3. Transakcje ACID
|
||||
W `rusqlite` używasz `let tx = conn.transaction()?;` — jeśli transakcja wyjdzie poza zakres (*drop*) bez wywołania `tx.commit()?`, Rust **automatycznie robi `ROLLBACK`** (wzorzec RAII)!
|
||||
Reference in new issue
Block a user