dbprimitives

package module
v0.0.0-...-cfd880f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dbprimitives

Reusable primitives for the common DB interactions in spuri-style tools:

  • Cayley graph over bbolt (read/write + read-only)
  • bbolt KV (blob/location cache)
  • SQLite with spuri-typical pragmas (WAL + FK + busy_timeout)

The goal is to encapsulate "how do I correctly open these things" so you don't relearn the driver registration, InitQuadStore dance, URI modes, or PRAGMA sequences every time.

Usage (from a consumer)

import "github.com/jmonroynieto/dbprimitives"

g, err := dbprimitives.OpenGraph(path, nil, dbprimitives.GraphOptions{})
cache, err := dbprimitives.OpenBbolt(cachePath, false)
props, err := dbprimitives.OpenSQLite(sqlPath, false)

// Lock-wait warnings: if any open blocks more than ~2s (held write lock or
// slow disk), logrus emits WARN naming the store path and suggesting another
// spurilo may hold the store; re-warns every 5s until open returns.

See cayley.go for the small set of helpers (Close*, ApplyCommonPragmas).

Code crimes / things relearned here

  • You must blank-import the bbolt kv driver for cayley before NewGraph.
  • InitQuadStore before first NewGraph on a new file.
  • bbolt options for ReadOnly.
  • sqlite URI file:...?mode=ro for true read-only.
  • The exact pragmas that make concurrent catalog/melt safe.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCommonPragmas

func ApplyCommonPragmas(db *sql.DB) error

ApplyCommonPragmas reapplies the standard spuri pragmas to an already-open writable sqlite DB. Useful for events or properties tables opened by other means.

func CloseBbolt

func CloseBbolt(db *bbolt.DB) error

CloseBbolt closes if non-nil.

func CloseGraph

func CloseGraph(g *cayley.Handle) error

CloseGraph is a small helper; real code often does more logging.

func CloseSQL

func CloseSQL(db *sql.DB) error

CloseSQL closes if non-nil.

func OpenBbolt

func OpenBbolt(path string, readOnly bool) (*bbolt.DB, error)

OpenBbolt opens a bbolt database (used for the fast cache of blobs + locations). Supports read-only mode for inspection tools. RO opens wait up to 15s on the meta lock so list/show can run while another process holds a write handle (e.g. mid-intake). Write opens still have no bbolt Timeout (can block until the peer releases); lock-wait warnings fire after lockWaitWarnAfter either way.

func OpenGraph

func OpenGraph(path string, existing *cayley.Handle, opts GraphOptions) (*cayley.Handle, error)

OpenGraph opens (or creates) a Cayley graph backed by bbolt at the given path. If existing is non-nil it is closed first (caller must reassign the result). When ReadOnly=false and the store does not exist it will be initialized. Logs debug info about creation/size using the caller's logger config. Blocks that take longer than lockWaitWarnAfter emit lock-wait warnings.

func OpenSQLite

func OpenSQLite(path string, readOnly bool) (*sql.DB, error)

OpenSQLite opens a sqlite database and applies common pragmas used by spuri (WAL journal, busy timeout, foreign keys). For read-only it uses the URI mode=ro and still sets busy_timeout so concurrent list/show can wait on a writer instead of failing immediately with SQLITE_BUSY. The directory is created if needed. Callers typically keep the returned *sql.DB and are responsible for closing it. First-connection work (PRAGMAs) can block on a writer; lock-wait warnings apply.

Types

type GraphOptions

type GraphOptions struct {
	ReadOnly bool
}

GraphOptions controls graph opening behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址