ent: github.com/facebookincubator/ent/dialect/sql/sqlgraph Index | Files

package sqlgraph

import "github.com/facebookincubator/ent/dialect/sql/sqlgraph"

sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen.

Index

Package Files

graph.go

func CountNodes Uses

func CountNodes(ctx context.Context, drv dialect.Driver, spec *QuerySpec) (int, error)

CountNodes counts the nodes in the given graph query.

func CreateNode Uses

func CreateNode(ctx context.Context, drv dialect.Driver, spec *CreateSpec) error

CreateNode applies the CreateSpec on the graph.

func DeleteNodes Uses

func DeleteNodes(ctx context.Context, drv dialect.Driver, spec *DeleteSpec) (int, error)

DeleteNodes applies the DeleteSpec on the graph.

func HasNeighbors Uses

func HasNeighbors(q *sql.Selector, s *Step)

HasNeighbors applies on the given Selector a neighbors check.

func HasNeighborsWith Uses

func HasNeighborsWith(q *sql.Selector, s *Step, pred func(*sql.Selector))

HasNeighborsWith applies on the given Selector a neighbors check. The given predicate applies its filtering on the selector.

func Neighbors Uses

func Neighbors(dialect string, s *Step) (q *sql.Selector)

Neighbors returns a Selector for evaluating the path-step and getting the neighbors of one vertex.

func QueryEdges Uses

func QueryEdges(ctx context.Context, drv dialect.Driver, spec *EdgeQuerySpec) error

QueryEdges queries the edges in the graph and scans the result with the given dest function.

func QueryNodes Uses

func QueryNodes(ctx context.Context, drv dialect.Driver, spec *QuerySpec) error

QueryNodes queries the nodes in the graph query and scans them to the given values.

func SetNeighbors Uses

func SetNeighbors(dialect string, s *Step) (q *sql.Selector)

SetNeighbors returns a Selector for evaluating the path-step and getting the neighbors of set of vertices.

func UpdateNode Uses

func UpdateNode(ctx context.Context, drv dialect.Driver, spec *UpdateSpec) error

UpdateNode applies the UpdateSpec on one node in the graph.

func UpdateNodes Uses

func UpdateNodes(ctx context.Context, drv dialect.Driver, spec *UpdateSpec) (int, error)

UpdateNodes applies the UpdateSpec on a set of nodes in the graph.

type ConstraintError Uses

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

A ConstraintError represents an error from mutation that violates a specific constraint.

func (ConstraintError) Error Uses

func (e ConstraintError) Error() string

type CreateSpec Uses

type CreateSpec struct {
    Table  string
    ID     *FieldSpec
    Fields []*FieldSpec
    Edges  []*EdgeSpec
}

CreateSpec holds the information for creating a node in the graph.

type DeleteSpec Uses

type DeleteSpec struct {
    Node      *NodeSpec
    Predicate func(*sql.Selector)
}

DeleteSpec holds the information for delete one or more nodes in the graph.

type EdgeMut Uses

type EdgeMut struct {
    Add   []*EdgeSpec
    Clear []*EdgeSpec
}

EdgeMut defines edge mutations.

type EdgeQuerySpec Uses

type EdgeQuerySpec struct {
    Edge       *EdgeSpec
    Predicate  func(*sql.Selector)
    ScanValues func() [2]interface{}
    Assign     func(out, in interface{}) error
}

EdgeQuerySpec holds the information for querying edges in the graph.

type EdgeSpec Uses

type EdgeSpec struct {
    Rel     Rel
    Inverse bool
    Table   string
    Columns []string
    Bidi    bool        // bidirectional edge.
    Target  *EdgeTarget // target nodes.
}

EdgeSpec holds the information for updating a field column in the database.

type EdgeSpecs Uses

type EdgeSpecs []*EdgeSpec

EdgeSpecs used for perform common operations on list of edges.

func (EdgeSpecs) GroupRel Uses

func (es EdgeSpecs) GroupRel() map[Rel][]*EdgeSpec

GroupRel groups edges by their relation type.

func (EdgeSpecs) GroupTable Uses

func (es EdgeSpecs) GroupTable() map[string][]*EdgeSpec

GroupTable groups edges by their table name.

type EdgeTarget Uses

type EdgeTarget struct {
    Nodes  []driver.Value
    IDSpec *FieldSpec
}

EdgeTarget holds the information for the target nodes of an edge.

type FieldMut Uses

type FieldMut struct {
    Set   []*FieldSpec // field = ?
    Add   []*FieldSpec // field = field + ?
    Clear []*FieldSpec // field = NULL
}

FieldMut defines field mutations.

type FieldSpec Uses

type FieldSpec struct {
    Column string
    Type   field.Type
    Value  driver.Value // value to be stored.
}

FieldSpec holds the information for updating a field column in the database.

type NodeSpec Uses

type NodeSpec struct {
    Table   string
    Columns []string
    ID      *FieldSpec
}

NodeSpec defines the information for querying and decoding nodes in the graph.

type NotFoundError Uses

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

NotFoundError returns when trying to update an entity and it was not found in the database.

func (*NotFoundError) Error Uses

func (e *NotFoundError) Error() string

type QuerySpec Uses

type QuerySpec struct {
    Node *NodeSpec     // Nodes info.
    From *sql.Selector // Optional query source (from path).

    Limit     int
    Offset    int
    Unique    bool
    Order     func(*sql.Selector)
    Predicate func(*sql.Selector)

    ScanValues func() []interface{}
    Assign     func(...interface{}) error
}

QuerySpec holds the information for querying nodes in the graph.

type Rel Uses

type Rel int

Rel is a relation type of an edge.

const (
    O2O Rel // One to one / has one.
    O2M     // One to many / has many.
    M2O     // Many to one (inverse perspective for O2M).
    M2M     // Many to many.
)

Relation types.

func (Rel) String Uses

func (r Rel) String() (s string)

String returns the relation name.

type Step Uses

type Step struct {
    // From is the source of the step.
    From struct {
        // V can be either one vertex or set of vertices.
        // It can be a pre-processed step (sql.Query) or a simple Go type (integer or string).
        V   interface{}
        // Table holds the table name of V (from).
        Table string
        // Column to join with. Usually the "id" column.
        Column string
    }
    // Edge holds the edge information for getting the neighbors.
    Edge struct {
        // Rel of the edge.
        Rel Rel
        // Table name of where this edge columns reside.
        Table string
        // Columns of the edge.
        // In O2O and M2O, it holds the foreign-key column. Hence, len == 1.
        // In M2M, it holds the primary-key columns of the join table. Hence, len == 2.
        Columns []string
        // Inverse indicates if the edge is an inverse edge.
        Inverse bool
    }
    // To is the dest of the path (the neighbors).
    To  struct {
        // Table holds the table name of the neighbors (to).
        Table string
        // Column to join with. Usually the "id" column.
        Column string
    }
}

A Step provides a path-step information to the traversal functions.

func NewStep Uses

func NewStep(opts ...StepOption) *Step

NewStep gets list of options and returns a configured step.

NewStep(
	From("table", "pk", V),
	To("table", "pk"),
	Edge("name", O2M, "fk"),
)

type StepOption Uses

type StepOption func(*Step)

StepOption allows configuring Steps using functional options.

func Edge Uses

func Edge(rel Rel, inverse bool, table string, columns ...string) StepOption

Edge sets the edge info for getting the neighbors.

func From Uses

func From(table, column string, v ...interface{}) StepOption

From sets the source of the step.

func To Uses

func To(table, column string) StepOption

To sets the destination of the step.

type UpdateSpec Uses

type UpdateSpec struct {
    Node      *NodeSpec
    Edges     EdgeMut
    Fields    FieldMut
    Predicate func(*sql.Selector)

    ScanValues []interface{}
    Assign     func(...interface{}) error
}

UpdateSpec holds the information for updating one or more nodes in the graph.

Package sqlgraph imports 9 packages (graph) and is imported by 21 packages. Updated 2020-07-08. Refresh now. Tools for package owners.