mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
docs: trim code comments to the why (#676)
Comments that restated names or narrated the code are gone, and multi-line ones are cut to a line of why. Only comments change: each edited Go file has the same token stream as before. winapi and abe come later.
This commit is contained in:
1 parent
4e98ba7884
commit
0ed920f846
130 files changed
+201
-869
No files matched your search
@@ -6,9 +6,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// CountRows runs a scalar count query (e.g. SELECT COUNT(*) FROM ...) and
|
||||
// returns the integer result. Unlike eachRow (which swallows per-row scan
|
||||
// errors), CountRows uses QueryRow for fail-fast behavior on scan failures.
|
||||
// CountRows fails fast on a scan error, unlike QueryRows, which skips the row.
|
||||
func CountRows(dbPath string, journalOff bool, query string) (int, error) {
|
||||
if _, err := os.Stat(dbPath); err != nil {
|
||||
return 0, fmt.Errorf("database file: %w", err)
|
||||
@@ -32,11 +30,7 @@ func CountRows(dbPath string, journalOff bool, query string) (int, error) {
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// QueryRows is a generic helper (Go 1.18+) that wraps eachRow and collects
|
||||
// results into a typed slice. Each extract method only needs to provide the
|
||||
// scan function that converts one database row into a typed value.
|
||||
//
|
||||
// Rows that fail to scan are skipped (logged at debug level by eachRow).
|
||||
// Rows that fail to scan are skipped and logged at debug level.
|
||||
func QueryRows[T any](dbPath string, journalOff bool, query string, scanRow func(*sql.Rows) (T, error)) ([]T, error) {
|
||||
var items []T
|
||||
err := eachRow(dbPath, journalOff, query, func(rows *sql.Rows) error {
|
||||
|
||||
@@ -11,14 +11,8 @@ import (
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
// eachRow opens a SQLite database, optionally disables journal mode (required
|
||||
// for Firefox databases), runs the query, and calls scanFn for each row.
|
||||
//
|
||||
// It validates the database file exists before opening to prevent sql.Open from
|
||||
// silently creating an empty database.
|
||||
//
|
||||
// scanFn should return nil to continue iteration, or an error to skip the current
|
||||
// row (the error is logged at debug level and iteration continues).
|
||||
// journalOff is for Firefox databases; the file is checked first so sql.Open never creates an empty one.
|
||||
// A row whose scanFn returns an error is skipped and logged at debug level.
|
||||
func eachRow(dbPath string, journalOff bool, query string, scanFn func(*sql.Rows) error) error {
|
||||
if _, err := os.Stat(dbPath); err != nil {
|
||||
return fmt.Errorf("database file: %w", err)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func TestEachRow(t *testing.T) {
|
||||
// Create a temp SQLite database
|
||||
dir := t.TempDir()
|
||||
dbPath := filepath.Join(dir, "test.db")
|
||||
|
||||
@@ -23,7 +22,6 @@ func TestEachRow(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.Close())
|
||||
|
||||
// Query using our helper
|
||||
var names []string
|
||||
err = eachRow(dbPath, false, "SELECT name FROM items ORDER BY id", func(rows *sql.Rows) error {
|
||||
var name string
|
||||
|
||||
Reference in new issue
Block a user