MCPcopy Index your code
hub / github.com/perkeep/perkeep / InitDB

Function InitDB

pkg/sorted/sqlite/dbschema.go:49–78  ·  view source on GitHub ↗

InitDB creates a new sqlite database based on the file at path.

(path string)

Source from the content-addressed store, hash-verified

47
48// InitDB creates a new sqlite database based on the file at path.
49func InitDB(path string) error {
50 db, err := sql.Open("sqlite", path)
51 if err != nil {
52 return err
53 }
54 defer db.Close()
55 for _, tableSQL := range SQLCreateTables() {
56 if _, err := db.Exec(tableSQL); err != nil {
57 return err
58 }
59 }
60
61 // Use Write Ahead Logging which improves SQLite concurrency.
62 // Requires SQLite >= 3.7.0
63 if _, err := db.Exec("PRAGMA journal_mode = WAL"); err != nil {
64 return err
65 }
66
67 // Check if the WAL mode was set correctly
68 var journalMode string
69 if err = db.QueryRow("PRAGMA journal_mode").Scan(&journalMode); err != nil {
70 log.Fatalf("Unable to determine sqlite3 journal_mode: %v", err)
71 }
72 if journalMode != "wal" {
73 log.Fatal("SQLite Write Ahead Logging (introducted in v3.7.0) is required. See http://perkeep.org/issue/114")
74 }
75
76 _, err = db.Exec(fmt.Sprintf(`REPLACE INTO meta VALUES ('version', '%d')`, SchemaVersion()))
77 return err
78}

Callers 2

RunCommandMethod · 0.92
newKeyValueFromConfigFunction · 0.85

Calls 7

QueryRowMethod · 0.80
FatalMethod · 0.80
SQLCreateTablesFunction · 0.70
SchemaVersionFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected