sqlite

package
v0.0.0-...-0be5f3d Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MemoryDSN is the in-memory data source name.
	MemoryDSN = "sqlite://:memory:"
	// Migrations is the file path glob for migrations.
	Migrations = "schema/*.sql"
	// Scehem is required sqlite scheme
	Scheme = "sqlite"
)

Variables

This section is empty.

Functions

func FormatLimitOffset

func FormatLimitOffset(limit, offset int) string

FormatLimitOffset returns a SQL string for a given limit & offset. Clauses are only added if limit and/or offset are greater than zero.

func StringPtr

func StringPtr(s string) *string

Types

type DB

type DB struct {

	// Datasource name.
	DSN string
	// contains filtered or unexported fields
}

DB represents the database connection.

func NewDB

func NewDB(dsn string) *DB

NewDB returns a new instance of DB associated with the given datasource name.

func (*DB) BeginTx

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

BeginTx starts a transaction and returns a wrapper Tx type. This type provides a reference to the database and a fixed timestamp at the start of the transaction. The timestamp allows us to mock time during tests as well.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Open

func (db *DB) Open() (err error)

Open opens the database connection.

type EdgeService

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

EdgeService lets you manage edges.

func NewEdgeService

func NewEdgeService(db *DB) (*EdgeService, error)

NewEdgeService creates an instance of EdgeService and returns it.

func (*EdgeService) CreateEdge

func (es *EdgeService) CreateEdge(ctx context.Context, graphUID string, e *api.Edge) error

CreateEdge creates a new edge.

func (*EdgeService) DeleteEdge

func (es *EdgeService) DeleteEdge(ctx context.Context, graphUID, edgeUID string) error

DeleteEdge permanently removes an edge by UID.

func (*EdgeService) DeleteEdgeBetween

func (es *EdgeService) DeleteEdgeBetween(ctx context.Context, graphUID, source, target string) error

DeleteEdgeBetween permanently deletes all edges between two nodes.

func (*EdgeService) FindEdgeByUID

func (es *EdgeService) FindEdgeByUID(ctx context.Context, graphUID, edgeUID string) (*api.Edge, error)

FindEdgeByUID returns a single edge with the given uid.

func (*EdgeService) FindEdges

func (es *EdgeService) FindEdges(ctx context.Context, graphUID string, filter api.EdgeFilter) ([]*api.Edge, int, error)

FindEdges returns all edges matching the filter.

func (*EdgeService) UpdateEdgeBetween

func (es *EdgeService) UpdateEdgeBetween(ctx context.Context, graphUID, source, target string, update api.EdgeUpdate) (*api.Edge, error)

UpdateEdgeBetween updates an edge between two nodes.

type GraphService

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

GraphService lets you manage graphs.

func NewGraphService

func NewGraphService(db *DB) (*GraphService, error)

NewGraphService creates an instance of GraphService and returns it.

func (*GraphService) CreateGraph

func (gs *GraphService) CreateGraph(ctx context.Context, g *api.Graph) error

CreateGraph creates a new graph.

func (*GraphService) DeleteGraph

func (gs *GraphService) DeleteGraph(ctx context.Context, uid string) error

DeleteGraph permanently removes a graph by ID.

func (*GraphService) FindGraphByUID

func (gs *GraphService) FindGraphByUID(ctx context.Context, uid string) (*api.Graph, error)

FindGraphByUID returns a single graph with the given uid.

func (*GraphService) FindGraphs

func (gs *GraphService) FindGraphs(ctx context.Context, filter api.GraphFilter) ([]*api.Graph, int, error)

FindGraphs returns all graphs matching the filter. It also returns a count of total matching graphs which may differ from the number of returned graphs if the Limit field is set.

func (*GraphService) UpdateGraph

func (gs *GraphService) UpdateGraph(ctx context.Context, uid string, update api.GraphUpdate) (*api.Graph, error)

UpdateGraph updates an existing graph by ID.

type NodeService

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

NodeService lets you manage graphs.

func NewNodeService

func NewNodeService(db *DB) (*NodeService, error)

NewNodeService creates an instance of NodeService and returns it.

func (*NodeService) CreateNode

func (ns *NodeService) CreateNode(ctx context.Context, graphUID string, n *api.Node) error

CreateNode creates a new node.

func (*NodeService) DeleteNodeByID

func (ns *NodeService) DeleteNodeByID(ctx context.Context, graphUID string, id int64) error

DeleteNodeByID permanently removes a node by ID. It automatically removes removed node's incoming and outgoing edges.

func (*NodeService) DeleteNodeByUID

func (ns *NodeService) DeleteNodeByUID(ctx context.Context, graphUID, nodeUID string) error

DeleteNodeByUID permanently removes a node by UID. It automatically removes removed node's incoming and outgoing edges.

func (*NodeService) FindNodeByID

func (ns *NodeService) FindNodeByID(ctx context.Context, graphUID string, id int64) (*api.Node, error)

FindNodeByUID returns a single node with the given uid.

func (*NodeService) FindNodeByUID

func (ns *NodeService) FindNodeByUID(ctx context.Context, graphUID, nodeUID string) (*api.Node, error)

FindNodeByUID returns a single node with the given uid.

func (*NodeService) FindNodes

func (ns *NodeService) FindNodes(ctx context.Context, graphUID string, filter api.NodeFilter) ([]*api.Node, int, error)

FindNodes returns all nodes matching the filter. It also returns a count of total matching nodes which may differ from the number of returned nodes if the Limit field is set.

func (*NodeService) UpdateNode

func (ns *NodeService) UpdateNode(ctx context.Context, graphUID string, id int64, update api.NodeUpdate) (*api.Node, error)

UpdateNode updates an existing node by ID.

type NullTime

type NullTime time.Time

NullTime represents a helper wrapper for time.Time. It automatically converts time fields to/from RFC 3339 format. Also supports NULL for zero time.

func (*NullTime) Scan

func (n *NullTime) Scan(value interface{}) error

Scan reads a time value from the database.

func (*NullTime) Value

func (n *NullTime) Value() (driver.Value, error)

Value formats a time value for the database.

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

Tx wraps the SQL Tx object to provide a timestamp at the start of the transaction.

Jump to

Keyboard shortcuts

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