Skip to content

Instantly share code, notes, and snippets.

@ichux
Created August 15, 2025 12:39
Show Gist options
  • Save ichux/361b20813c98052d46aa76bcb2d119e4 to your computer and use it in GitHub Desktop.
Save ichux/361b20813c98052d46aa76bcb2d119e4 to your computer and use it in GitHub Desktop.
sqlite3 ~/terminaLogs.db <<EOF
CREATE TABLE IF NOT EXISTS logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
message TEXT NOT NULL
);
EOF
echo .schema | sqlite3 ~/terminaLogs.db
log() {
# sqlite3 ~/terminaLogs.db "SELECT * FROM logs ORDER BY id DESC;"
local ts
ts=$(date '+%Y-%m-%d %H:%M:%S.%6N')
echo "$ts - $1"
sqlite3 ~/terminaLogs.db <<EOF >/dev/null
PRAGMA journal_mode = WAL;
INSERT INTO logs (timestamp, message) VALUES ('$ts', '$1');
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment