MCPcopy Create free account
hub / github.com/assetnote/hyoketsu / importFromSQLite

Function importFromSQLite

server/import.go:48–126  ·  view source on GitHub ↗
(ctx context.Context, ch *CHStore, sqlitePath string)

Source from the content-addressed store, hash-verified

46}
47
48func importFromSQLite(ctx context.Context, ch *CHStore, sqlitePath string) error {
49 sdb, err := sql.Open("sqlite", sqlitePath)
50 if err != nil {
51 return fmt.Errorf("open sqlite: %w", err)
52 }
53 defer sdb.Close()
54
55 // Import from both tables if they exist
56 for _, src := range []struct {
57 table string
58 dest string
59 }{
60 {"known_dlls", "known_dlls"},
61 {"known_jars", "known_jars"},
62 } {
63 // Check if source table exists
64 var name string
65 err := sdb.QueryRow(`SELECT name FROM sqlite_master WHERE type='table' AND name=?`, src.table).Scan(&name)
66 if err != nil {
67 continue // table doesn't exist, skip
68 }
69
70 rows, err := sdb.Query(fmt.Sprintf(`SELECT dll_name, source, package_name, version, hash FROM %s`, src.table))
71 if err != nil {
72 return fmt.Errorf("query sqlite %s: %w", src.table, err)
73 }
74
75 batch := make([][]interface{}, 0, importBatchSize)
76 total := 0
77
78 for rows.Next() {
79 var dllName, source string
80 var packageName, version, hash sql.NullString
81
82 if err := rows.Scan(&dllName, &source, &packageName, &version, &hash); err != nil {
83 rows.Close()
84 return fmt.Errorf("scan row: %w", err)
85 }
86
87 pkg := ""
88 if packageName.Valid {
89 pkg = packageName.String
90 }
91 ver := ""
92 if version.Valid {
93 ver = version.String
94 }
95 h := ""
96 if hash.Valid {
97 h = hash.String
98 }
99
100 batch = append(batch, []interface{}{dllName, source, pkg, ver, h})
101 total++
102
103 if len(batch) >= importBatchSize {
104 if err := flushBatch(ctx, ch, src.dest, batch, total); err != nil {
105 rows.Close()

Callers 1

mainFunction · 0.85

Calls 2

flushBatchFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected