Skip to content
go-libfossil Artifact [617e3a5f06]
Login

Artifact [617e3a5f06]

Artifact 617e3a5f06b896baaa76d55869e589efcae6f7135ded9510435da3b5faeadc7d:


//go:build js

package ncruces

import (
	"fmt"
	"strings"

	"github.com/danmestas/go-libfossil/db"
	_ "github.com/danmestas/go-sqlite3-opfs"
	"github.com/ncruces/go-sqlite3"
	_ "github.com/ncruces/go-sqlite3/driver"
	"github.com/ncruces/go-sqlite3/ext/fts5"
)

func init() {
	sqlite3.AutoExtension(fts5.Register)
	db.Register(db.DriverConfig{
		Name:     "sqlite3",
		BuildDSN: buildDSN,
	})
}

func buildDSN(path string, pragmas map[string]string) string {
	if path == "" {
		panic("ncruces.buildDSN: path must not be empty")
	}
	var parts []string
	parts = append(parts, "vfs=opfs")
	for k, v := range pragmas {
		parts = append(parts, fmt.Sprintf("_pragma=%s(%s)", k, v))
	}
	return fmt.Sprintf("file:%s?%s", path, strings.Join(parts, "&"))
}