graphdb

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package graphdb provides a connection pool for Kuzu graph databases. It manages multiple connections to different Kuzu DBs, identified by namespace ID, and handles memory allocation for these connections. The pool ensures efficient reuse of connections and provides mechanisms for periodic maintenance to close unused databases and free up memory.

Index

Constants

View Source
const ConnectionDuration = 20 * time.Minute
View Source
const MaintenanceInterval = 1 * time.Minute
View Source
const MaxBufferSize = 200 * 1024 * 1024 // 200 MB
View Source
const MaxConnections = 10 // maximum number of connections to single database
View Source
const MaxVirtMem = 1024 * 1024 * 1024 // 1GB - this is needed to avoid hitting max virtual memory limit
View Source
const MinBufferSize = 10 * 1024 * 1024 // 10 MB
View Source
const QueryTimeoutSeconds = 15

Variables

This section is empty.

Functions

func RequiredBufferSize

func RequiredBufferSize(path string, min, max uint64) uint64

Types

type Client

type Client struct {
	NamespaceID   uint64 // namespace ID (currently only project namespace ID)
	GraphIndexDir string // top-level directory
	DbPath        string // kuzu database file path
}

A Client represents basic information about graph DB for a specific namespace (base index directory, directory with database and metadata files for the namespace).

func NewClient

func NewClient(namespaceID uint64, graphIndexDir string) *Client

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

A Connection represents a single connection to a Kuzu DB. The connection can be reused for multiple requests but should not be used by multiple requests at the same time.

func NewConnection

func NewConnection(db *Database) (*Connection, error)

func (*Connection) Acquire

func (c *Connection) Acquire() bool

func (*Connection) Query

func (c *Connection) Query(q string) *QueryResult

func (*Connection) Release

func (c *Connection) Release()

type ConnectionPool

type ConnectionPool struct {
	// contains filtered or unexported fields
}

A ConnectionPool keeps and maintains a pool of open connections to Kuzu DBs. There can be multiple connections to different DBs (identified by namespace ID). Each DB connection reserves a memory buffer, size of buffer equals to DB file size. Each DB connection can have multiple connections to allow concurrent access to the same DB, maximum connections to the same DB is 10

It returns a Connection object which can be used to execute DB queries. Make sure to call Release() on this object when done so the connection can be reused.

func NewConnectionPool

func NewConnectionPool(memLimit uint64) *ConnectionPool

func (*ConnectionPool) Connect

func (pool *ConnectionPool) Connect(path string) (*Connection, error)

type Database

type Database struct {
	// contains filtered or unexported fields
}

A Database represents a Kuzu DB, there can be multiple connections opened to the same DB.

func NewDatabase

func NewDatabase(path string, bufferSize uint64, maxConn int) (*Database, error)

func (*Database) Close

func (db *Database) Close()

func (*Database) GetConnection

func (db *Database) GetConnection() (*Connection, error)

func (*Database) Locked

func (db *Database) Locked() bool

type QueryRequest

type QueryRequest struct {
	Query       string `json:"query,omitempty"`
	NamespaceID uint64 `json:"namespace_id,omitempty"`
}

func NewQueryRequest

func NewQueryRequest(r *http.Request) (*QueryRequest, error)

type QueryResult

type QueryResult struct {
	Error  error            `json:"Error"`
	Result []map[string]any `json:"Result"`
}

Jump to

Keyboard shortcuts

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