MCPcopy
hub / github.com/cayleygraph/cayley / New

Function New

graph/sql/quadstore.go:284–317  ·  view source on GitHub ↗
(typ string, addr string, options graph.Options)

Source from the content-addressed store, hash-verified

282}
283
284func New(typ string, addr string, options graph.Options) (graph.QuadStore, error) {
285 if typ == "" {
286 typ = typeFromOpts(options)
287 }
288 fl, ok := types[typ]
289 if !ok {
290 return nil, fmt.Errorf("unsupported sql database: %s", typ)
291 }
292 conn, err := connect(addr, fl.Driver, options)
293 if err != nil {
294 return nil, err
295 }
296 qs := &QuadStore{
297 db: conn,
298 opt: NewOptimizer(),
299 flavor: fl,
300 quads: -1,
301 nodes: -1,
302 sizes: lru.New(1024),
303 ids: lru.New(1024),
304 noSizes: true, // Skip size checking by default.
305 }
306 qs.opt.SetRegexpOp(qs.flavor.RegexpOp)
307 if qs.flavor.NoOffsetWithoutLimit {
308 qs.opt.NoOffsetWithoutLimit()
309 }
310
311 if local, err := options.BoolKey("local_optimize", false); err != nil {
312 return nil, err
313 } else if ok && local {
314 qs.noSizes = false
315 }
316 return qs, nil
317}
318
319func escapeNullByte(s string) string {
320 return strings.Replace(s, "\u0000", `\x00`, -1)

Callers 2

makeDatabaseFuncFunction · 0.92
registerQuadStoreFunction · 0.70

Calls 8

NewFunction · 0.92
typeFromOptsFunction · 0.85
connectFunction · 0.85
NewOptimizerFunction · 0.85
SetRegexpOpMethod · 0.80
NoOffsetWithoutLimitMethod · 0.80
BoolKeyMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected