Skip to content

Commit

Permalink
bump, remove Init
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarchie committed Dec 25, 2024
1 parent ae22859 commit 2e20eae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@ Below is an example of how to use SQLiteZSTD in a Go program:

```go
import (
sqlitezstd "github.com/jtarchie/sqlitezstd"
_ "github.com/jtarchie/sqlitezstd"
)

initErr := sqlitezstd.Init()
if initErr != nil {
panic(fmt.Sprintf("Failed to initialize SQLiteZSTD: %s", initErr))
}

db, err := sql.Open("sqlite3", "<path-to-your-file>?vfs=zstd")
if err != nil {
panic(fmt.Sprintf("Failed to open database: %s", err))
Expand Down Expand Up @@ -78,7 +73,6 @@ if err != nil {

In this Go code example:

- The SQLiteZSTD library is initialized first with `sqlitezstd.Init()`.
- The `sql.Open()` function takes as a parameter the path to the compressed
SQLite database, appended with a query string with `vfs=zstd` to use the VFS.
- Setting the `PRAGMA` ensures that the read only VFS is not used to create
Expand Down
4 changes: 1 addition & 3 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"time"

"github.com/brianvoe/gofakeit/v7"
sqlitezstd "github.com/jtarchie/sqlitezstd"
_ "github.com/jtarchie/sqlitezstd"
_ "github.com/mattn/go-sqlite3" // ensure you import the SQLite3 driver
"github.com/onsi/gomega/gexec"
)
Expand Down Expand Up @@ -43,8 +43,6 @@ func setupDB(b *testing.B) (string, string) {
return dbPath, zstPath
}

_ = sqlitezstd.Init()

buildPath, err := os.MkdirTemp("", "")
if err != nil {
b.Fatalf("Failed to create temp directory: %v", err)
Expand Down
7 changes: 1 addition & 6 deletions sqlite_zstd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"

"github.com/georgysavva/scany/v2/sqlscan"
sqlitezstd "github.com/jtarchie/sqlitezstd"
_ "github.com/jtarchie/sqlitezstd"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -143,11 +143,6 @@ func createComplexDatabase() (string, string) {
}

var _ = Describe("SqliteZSTD", func() {
BeforeEach(func() {
err := sqlitezstd.Init()
Expect(err).ToNot(HaveOccurred())
})

It("can read from a compressed sqlite db", func() {
zstPath := createDatabase()

Expand Down
10 changes: 9 additions & 1 deletion vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ var once = sync.OnceValue(func() error {
return nil
})

// noop, kept for old interface
func Init() error {
return once()
return nil
}

func init() {
err := once()
if err != nil {
panic(fmt.Sprintf("could not register vfs: %v", err))
}
}

0 comments on commit 2e20eae

Please sign in to comment.