Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/asg017/sqlite-vec-ncruces-bindings

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/asg017/sqlite-vec-ncruces-bindings

  • v0.1.6
  • Source
  • Go
  • Socket score

Version published
Created
Source

sqlite-vec-go-bindings

Go bindings for sqlite-vec project. In a separate repo to keep the original repo from getting too large.

There are two options when adding sqlite-vec to a Go project — A traditional CGO option, and a WASM-based option for the ncruces/go-sqlite3 project.

Both are available in this Go module, which can be installed with:

go get -u github.com/asg017/sqlite-vec-go-bindings

CGO Bindings

For most SQLite Go libraries that use CGO, like mattn/go-sqlite3, use the CGO portion of this Go module. It will compile the sqlite-vec libary from source and embed into your application.

package main

import (
	"database/sql"
	"log"

	sqlite_vec "github.com/asg017/sqlite-vec-go-bindings/cgo"
	_ "github.com/mattn/go-sqlite3"
)

import "C"

func main() {
	sqlite_vec.Auto()
	db, err := sql.Open("sqlite3", ":memory:")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	var sqliteVersion string
	var vecVersion string
	err = db.QueryRow("select sqlite_version(), vec_version()").Scan(&sqliteVersion, &vecVersion)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("sqlite_version=%s, vec_version=%s\n", sqliteVersion, vecVersion)
}

Use sqlite_vec.Auto() before opening a connection to automatically register sqlite-vec functions. See simple-go-cgo/demo.go for a larger example.

While this works with CGO SQLite/Go libraries like mattn/go-sqlite3, this will NOT work with other non-CGO library like modernc.org/sqlite or ncruces/go-sqlite3.

ncruces WASM Bindings

If you are using the ncruces/go-sqlite3 library, then use the ncruces portion of this Go module.

package main

import (
	_ "embed"
	"log"

	_ "github.com/asg017/sqlite-vec-go-bindings/ncruces"
	"github.com/ncruces/go-sqlite3"
)

func main() {
	db, err := sqlite3.Open(":memory:")
	if err != nil {
		log.Fatal(err)
	}

	stmt, _, err := db.Prepare(`SELECT sqlite_version(), vec_version()`)
	if err != nil {
		log.Fatal(err)
	}

	stmt.Step()

	log.Printf("sqlite_version=%s, vec_version=%s\n", stmt.ColumnText(0), stmt.ColumnText(1))
}

"github.com/asg017/sqlite-vec-go-bindings/ncruces" will automatically register a new SQLite WASM build that includes sqlite-vec functions by default. This replaces the "github.com/ncruces/go-sqlite3/embed" module in that project, so do NOT include them both.

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc