MCPcopy
hub / github.com/livebud/bud / Load

Function Load

internal/dag/sqlite.go:35–69  ·  view source on GitHub ↗
(log log.Log, dbPath string)

Source from the content-addressed store, hash-verified

33}
34
35func Load(log log.Log, dbPath string) (*DB, error) {
36 // Make the path directory
37 if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
38 return nil, err
39 }
40 // Open the SQLite database
41 db, err := sql.Open("sqlite3", dbPath)
42 if err != nil {
43 return nil, fmt.Errorf("dag/sqlite: unable to open %q. %w", dbPath, err)
44 }
45
46 // Create the files and links tables.
47 if _, err := db.Exec(`
48 CREATE TABLE IF NOT EXISTS files (
49 path TEXT PRIMARY KEY,
50 data BLOB,
51 mode INTEGER
52 )
53 `); err != nil {
54 return nil, fmt.Errorf("dag/sqlite: unable to create files table. %w", err)
55 }
56 if _, err := db.Exec(`
57 CREATE TABLE IF NOT EXISTS links (
58 from_path TEXT,
59 to_path TEXT,
60 FOREIGN KEY(from_path) REFERENCES files(path),
61 FOREIGN KEY(to_path) REFERENCES files(path),
62 PRIMARY KEY(from_path, to_path)
63 )
64 `); err != nil {
65 return nil, fmt.Errorf("dag/sqlite: unable to create links table. %w", err)
66 }
67
68 return &DB{db, log, dbPath}, nil
69}
70
71type DB struct {
72 db *sql.DB

Callers 15

GenFSFunction · 0.92
TestUpdateFileFunction · 0.92
TestUpdateFileFunction · 0.92
loadServerFunction · 0.92
openDBMethod · 0.92
TestSetGetFunction · 0.92
TestGetNotFoundFunction · 0.92
TestAncestorsFunction · 0.92
TestDeleteFunction · 0.92
TestPrintFunction · 0.92
TestManyWritesFunction · 0.92
TestConcurrentWritesFunction · 0.92

Calls 3

DirMethod · 0.80
MkdirAllMethod · 0.65
OpenMethod · 0.65

Tested by 13

TestUpdateFileFunction · 0.74
TestUpdateFileFunction · 0.74
loadServerFunction · 0.74
TestSetGetFunction · 0.74
TestGetNotFoundFunction · 0.74
TestAncestorsFunction · 0.74
TestDeleteFunction · 0.74
TestPrintFunction · 0.74
TestManyWritesFunction · 0.74
TestConcurrentWritesFunction · 0.74
TestUpsertLinkFunction · 0.74
TestUpsertFileFunction · 0.74