api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package api provides the public database API for gograph, a graph database engine. It offers a high-level interface for executing Cypher queries and managing graph data including nodes, relationships, and their properties.

Package api provides the public database API for gograph, a graph database engine.

Package api provides the public database API for gograph, a graph database engine.

Index

Constants

This section is empty.

Variables

View Source
var ErrDBClosed = errors.New("database is closed")

ErrDBClosed is returned when attempting to perform operations on a closed database.

View Source
var ErrNoMoreRows = errors.New("no more rows")

ErrNoMoreRows is returned by Scan when there are no more rows to read.

Functions

This section is empty.

Types

type DB

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

DB represents a graph database instance. It provides methods for executing Cypher queries and managing transactions. A DB instance is safe for concurrent use by multiple goroutines.

func Open

func Open(path string, opts ...DBOption) (*DB, error)

Open opens a database at the specified path and returns a DB instance. The path is used as the storage location for the underlying Pebble database. Optional DBOption functions can be provided to configure the database.

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error)

BeginTx starts a new transaction with the specified options. If opts is nil, a read-write transaction is started. A transaction allows grouping multiple operations into a single atomic unit.

func (*DB) Close

func (db *DB) Close() error

Close closes the database and releases all associated resources. It returns an error if the database is already closed.

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, cypherQuery string, args ...interface{}) (Result, error)

Exec executes a Cypher query that modifies data (CREATE, SET, DELETE, REMOVE) and returns a Result containing the count of affected nodes and relationships. The query can include optional positional parameters passed as arguments.

func (*DB) IsClosed

func (db *DB) IsClosed() bool

IsClosed returns true if the database has been closed.

func (*DB) Query

func (db *DB) Query(ctx context.Context, cypherQuery string, args ...interface{}) (*Rows, error)

Query executes a Cypher query that returns rows of data (MATCH ... RETURN) and returns a Rows iterator for scanning the results. The query can include optional positional parameters passed as arguments.

type DBOption

type DBOption func(*DB)

DBOption configures optional parameters for database operations.

func WithObservability

func WithObservability(o *cypher.Observability) DBOption

WithObservability enables observability features for the database executor, allowing tracing and metrics collection during query execution.

type Result

type Result = cypher.Result

Result contains the count of affected graph elements after executing a data-modifying Cypher query (CREATE, SET, DELETE, REMOVE).

type Rows

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

Rows represents a result set iterator from a Cypher query. It provides methods to iterate over the rows and scan column values into Go variables.

func (*Rows) Close

func (r *Rows) Close() error

Close releases the Rows resources. It is idempotent and safe to call multiple times.

func (*Rows) Columns

func (r *Rows) Columns() []string

Columns returns the column names of the result set.

func (*Rows) Next

func (r *Rows) Next() bool

Next advances the iterator to the next row. It returns true if there is a next row, or false if there are no more rows.

func (*Rows) Scan

func (r *Rows) Scan(dest ...interface{}) error

Scan copies the column values of the current row into the dest variables. The number of dest arguments must be less than or equal to the number of columns in the result set. Supported types are *string, *int, *int64, *float64, and *bool.

type Tx

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

Tx represents a database transaction. It provides methods for executing Cypher queries within a transaction. A transaction is safe for concurrent use by multiple goroutines, though serial execution is recommended.

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit commits the transaction, making all changes permanent. Returns an error if the transaction is already closed or if the commit fails.

func (*Tx) Exec

func (tx *Tx) Exec(cypherQuery string, args ...interface{}) (Result, error)

Exec executes a Cypher query within the transaction and returns a Result containing the count of affected nodes and relationships. The query can include optional positional parameters passed as arguments.

func (*Tx) Query

func (tx *Tx) Query(cypherQuery string, args ...interface{}) (*Rows, error)

Query executes a Cypher query within the transaction and returns a Rows iterator for scanning the results. The query can include optional positional parameters passed as arguments.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback aborts the transaction and discards all changes. If the transaction is already closed, Rollback returns nil.

type TxOptions

type TxOptions struct {
	// ReadOnly indicates whether the transaction should be read-only.
	// A read-only transaction cannot modify data but may have better performance.
	ReadOnly bool
}

TxOptions specifies configuration options for a transaction.

Jump to

Keyboard shortcuts

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