-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariantindex_openbgicnogo.go
52 lines (40 loc) · 1.18 KB
/
variantindex_openbgicnogo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build !cgo
package bgen
// If cgo is not enabled, we will use the modernc.org/sqlite non-cgo sqlite
// driver. It is slower than the sqlite3 cgo driver.
import (
"fmt"
"strings"
"github.com/jmoiron/sqlx"
_ "modernc.org/sqlite"
)
const whichSQLiteDriver = "sqlite"
func OpenBGI(path string) (*BGIIndex, error) {
bgi := &BGIIndex{
Metadata: &BGIMetadata{},
}
// URI filenames have to begin with 'file:'; see
// https://www.sqlite.org/c3ref/open.html . It seems that sqlite3 permitted
// URI filenames without the file: prefix, but that is not standard.
if !strings.HasPrefix(path, "file:") {
path = "file:" + path
}
db, err := sqlx.Connect("sqlite", path)
if err != nil {
return nil, err
}
bgi.DB = db
// See https://www.rockyourcode.com/til-sqlite-foreign-key-support-with-go/
// and https://twitter.com/frioux/status/1483235674228596739
_, err = db.DB.Exec(`
PRAGMA journal_mode = OFF;
PRAGMA synchronous = OFF;
PRAGMA auto_vacuum = NONE;
`)
if err != nil {
return nil, fmt.Errorf("unable to set pragmas: %w", err)
}
// Not all index files have metadata; ignore any error
_ = bgi.DB.Get(bgi.Metadata, "SELECT * FROM Metadata LIMIT 1")
return bgi, nil
}