github.com/cayleygraph/cayley@v0.7.7/schema/global.go (about)

     1  package schema
     2  
     3  import (
     4  	"context"
     5  	"reflect"
     6  
     7  	"github.com/cayleygraph/cayley/graph"
     8  	"github.com/cayleygraph/cayley/graph/path"
     9  	"github.com/cayleygraph/quad"
    10  	"github.com/cayleygraph/quad/voc"
    11  )
    12  
    13  // GenerateID is called when any object without an ID field is being saved.
    14  //
    15  // Deprecated: see Config.GenerateID
    16  var GenerateID = func(_ interface{}) quad.Value {
    17  	return quad.RandomBlankNode()
    18  }
    19  
    20  var global = NewConfig()
    21  
    22  // Global returns a default global schema config.
    23  func Global() *Config {
    24  	return global
    25  }
    26  
    27  // PathForType builds a path (morphism) for a given Go type.
    28  //
    29  // Deprecated: see Config.PathForType
    30  func PathForType(rt reflect.Type) (*path.Path, error) {
    31  	return global.PathForType(rt)
    32  }
    33  
    34  // WriteAsQuads writes a single value in form of quads into specified quad writer.
    35  //
    36  // Deprecated: see Config.WriteAsQuads
    37  func WriteAsQuads(w quad.Writer, o interface{}) (quad.Value, error) {
    38  	return global.WriteAsQuads(w, o)
    39  }
    40  
    41  // WriteNamespaces will writes namespaces list into graph.
    42  //
    43  // Deprecated: see Config.WriteNamespaces
    44  func WriteNamespaces(w quad.Writer, n *voc.Namespaces) error {
    45  	return global.WriteNamespaces(w, n)
    46  }
    47  
    48  // LoadNamespaces will load namespaces stored in graph to a specified list.
    49  //
    50  // Deprecated: see Config.LoadNamespaces
    51  func LoadNamespaces(ctx context.Context, qs graph.QuadStore, dest *voc.Namespaces) error {
    52  	return global.LoadNamespaces(ctx, qs, dest)
    53  }
    54  
    55  // LoadIteratorToDepth is the same as LoadIteratorTo, but stops at a specified depth.
    56  //
    57  // Deprecated: see Config.LoadIteratorToDepth
    58  func LoadIteratorToDepth(ctx context.Context, qs graph.QuadStore, dst reflect.Value, depth int, list graph.Iterator) error {
    59  	return global.LoadIteratorToDepth(ctx, qs, dst, depth, list)
    60  }
    61  
    62  // LoadIteratorTo is a lower level version of LoadTo.
    63  //
    64  // Deprecated: see Config.LoadIteratorTo
    65  func LoadIteratorTo(ctx context.Context, qs graph.QuadStore, dst reflect.Value, list graph.Iterator) error {
    66  	return global.LoadIteratorToDepth(ctx, qs, dst, -1, list)
    67  }
    68  
    69  // LoadPathTo is the same as LoadTo, but starts loading objects from a given path.
    70  //
    71  // Deprecated: see Config.LoadPathTo
    72  func LoadPathTo(ctx context.Context, qs graph.QuadStore, dst interface{}, p *path.Path) error {
    73  	return global.LoadIteratorTo(ctx, qs, reflect.ValueOf(dst), p.BuildIterator())
    74  }
    75  
    76  // LoadTo will load a sub-graph of objects starting from ids (or from any nodes, if empty)
    77  // to a destination Go object. Destination can be a struct, slice or channel.
    78  //
    79  // Deprecated: see Config.LoadTo
    80  func LoadTo(ctx context.Context, qs graph.QuadStore, dst interface{}, ids ...quad.Value) error {
    81  	return global.LoadTo(ctx, qs, dst, ids...)
    82  }
    83  
    84  // LoadToDepth is the same as LoadTo, but stops at a specified depth.
    85  //
    86  // Deprecated: see Config.LoadToDepth
    87  func LoadToDepth(ctx context.Context, qs graph.QuadStore, dst interface{}, depth int, ids ...quad.Value) error {
    88  	return global.LoadToDepth(ctx, qs, dst, depth, ids...)
    89  }