feat: WAL mode explícito con PRAGMA para acceso concurrente
Cambia de _journal_mode=WAL en connection string a PRAGMA journal_mode=WAL explícito. Esto persiste en el archivo y cualquier cliente externo (sqlite3 CLI, DuckDB) hereda WAL automáticamente sin configuración adicional. Permite leer mientras el agente escribe simultáneamente sin bloqueos. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -128,11 +128,18 @@ func Open(path string) (*DB, error) {
|
|||||||
return nil, fmt.Errorf("creating db directory: %w", err)
|
return nil, fmt.Errorf("creating db directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := sql.Open("sqlite3", path+"?_journal_mode=WAL&_foreign_keys=on")
|
conn, err := sql.Open("sqlite3", path+"?_foreign_keys=on")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("opening database: %w", err)
|
return nil, fmt.Errorf("opening database: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WAL mode: enables concurrent reads while writing.
|
||||||
|
// Persists in the file — any client opening the DB inherits it.
|
||||||
|
if _, err := conn.Exec("PRAGMA journal_mode=WAL"); err != nil {
|
||||||
|
conn.Close()
|
||||||
|
return nil, fmt.Errorf("setting WAL mode: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := conn.Exec(schemaSQL); err != nil {
|
if _, err := conn.Exec(schemaSQL); err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil, fmt.Errorf("applying schema: %w", err)
|
return nil, fmt.Errorf("applying schema: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user