graph

package
v0.0.0-...-3a6b306 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TABLE_CLASSES    = "_classes"
	TABLE_VERTICES   = "_vertices"
	TABLE_PROPERTIES = "_properties"

	TABLE_USERS    = "_users"
	TABLE_SESSIONS = "_sessions"
)
View Source
const (
	SHORT_ID_BUF_LEN = 12
	SESSION_KEY_LEN  = 64
)
View Source
const (
	SHA3_ID_LENGTH = 15
	MAX_CLASS_NAME = 20
)

Variables

This section is empty.

Functions

func Hash256

func Hash256(input []byte) string

Types

type AUTO_INCREMENT

type AUTO_INCREMENT struct {
	Val string
}

func (AUTO_INCREMENT) SQL

func (c AUTO_INCREMENT) SQL() string

func (AUTO_INCREMENT) Value

func (c AUTO_INCREMENT) Value() string

type CHECK

type CHECK struct{}

func (CHECK) SQL

func (c CHECK) SQL() string

func (CHECK) Value

func (c CHECK) Value() string

type ChannelConfig

type ChannelConfig struct {
	Channel   chan interface{}
	Listeners []*EventClient
}

type Channels

type Channels struct {
	EdgeState    *ChannelConfig
	InsertVertex *ChannelConfig
	DeleteVertex *ChannelConfig
	UpdateVertex *ChannelConfig
}

func (*Channels) ListenDeleteVertex

func (c *Channels) ListenDeleteVertex(listener *EventClient)

func (*Channels) ListenEdgeState

func (c *Channels) ListenEdgeState(listener *EventClient)

func (*Channels) ListenInsertVertex

func (c *Channels) ListenInsertVertex(listener *EventClient)

func (*Channels) ListenUpdateVertex

func (c *Channels) ListenUpdateVertex(listener *EventClient)

type Class

type Class struct {
	// root schema
	DB *Database `json:"-"`
	// deterministic id
	Uid int64
	// class name
	Name string
	// primary keys
	PKs []Constraint
	// foreign keys
	FKs map[string]Constraint
	// class schema
	Properties  Properties
	PropertyMap map[string]*Property
	// gf node
	//	Node *gf.Node
	// gf node
	//	InstanceNode *gf.Node
	// is internal class
	IsUser   bool
	IsAnchor bool
	Internal bool
	sync.RWMutex
}

func (*Class) AddProperty

func (class *Class) AddProperty(key string, value *validation.Config, options ...interface{})

func (*Class) Column

func (class *Class) Column(i int) (bool, *Property)

func (*Class) HasProperty

func (class *Class) HasProperty(key string) (bool, *Property)

func (*Class) InsertColumns

func (class *Class) InsertColumns() Properties
func (class *Class) Link(predicate string, classes ...*Class)

func (*Class) NewProperty

func (class *Class) NewProperty(key string, value *validation.Config) *Property

func (*Class) NewVertex

func (class *Class) NewVertex(x string, data map[string]interface{}) *Vertex

func (*Class) Table

func (class *Class) Table() string

func (*Class) Validation

func (class *Class) Validation() *common.Payload

type Classes

type Classes struct {
	DB            *Database `json:"-"`
	Index         []*Class
	UidIndex      map[int64]*Class
	NameIndex     map[string]*Class
	Predicates    map[string]*Predicate
	Relationships []*Relationship
	sync.RWMutex
}

func (*Classes) Add

func (classes *Classes) Add(class *Class)

type Client

type Client interface {
	SetDB(*Database)
	//
	Exec(string, ...interface{}) (bool, sql.Result)
	CreateDatabase(string) bool
	InsertInternalTable(*Class) bool
	InsertClass(string) (bool, int64)
	InsertVertex(*Class, string) (bool, int64)
	InsertProperty(*Vertex, string, interface{}) bool
	DeleteVertex(int64) bool
	//
	QueryClassUID(string) (bool, int64)
	//
	QueryRows(string, ...interface{}) (bool, *sql.Rows)
	CountRows(string, ...interface{}) int64
	//
	QueryUser(string, ...interface{}) (bool, *User)
	QuerySession(string, ...interface{}) (bool, *Session)
	//
	QueryVertex(int64) (bool, *Vertex)
	QueryVertexByX(string, ...*Class) (bool, *Vertex)
	QueryVertices(string, ...interface{}) (bool, []*Vertex)
	//
	QueryEdge(*Predicate, string, ...interface{}) (bool, *Link)
	QueryEdges(*Predicate, string, ...interface{}) (bool, []*Link)
	QueryAllEdges(*Predicate) (bool, []*Link)
	CountAllEdges(*Predicate) int64
	//
	QueryLink(string, ...interface{}) (bool, *Link)
	QueryLinks(string, ...interface{}) (bool, []*Link)
	//
	SearchClassProperties(*Class, string, string) (bool, []*PropertyExport)
	SearchProperties(string, string) (bool, []interface{})
	QueryProperties(*Vertex, ...string) (bool, map[string]interface{})
	//
	QueryState(*Vertex, *Vertex, *Predicate, bool) bool
	QueryClassCount(*Class) int64
	QueryClassList(*Class, int64, int64) (bool, []*Vertex)
	// in
	QueryInCount(*Predicate, *Vertex) int64
	QueryInList(*Predicate, *Vertex, int64) (bool, []*Vertex)
	QueryInClassCount(*Class, *Predicate, *Vertex) int64
	QueryInClassList(*Class, *Predicate, *Vertex, int64, int64) (bool, []*Vertex)
	// out
	QueryOutCount(*Predicate, *Vertex) int64
	QueryOutList(*Predicate, *Vertex, int64) (bool, []*Vertex)
	QueryOutClassCount(*Class, *Predicate, *Vertex) int64
	QueryOutClassList(*Class, *Predicate, *Vertex, int64, int64) (bool, []*Vertex)
	//
	TraverseEdges(int64, *Predicate, bool, int64) (bool, []*Link)
	Traverse(int64, *Predicate, bool, bool, int64) (bool, []*Vertex)
	TraverseCount(int64, *Predicate, bool) int64
}

type Constraint

type Constraint interface {
	SQL() string
	Value() string
}

type Constraints

type Constraints struct {
	PRIMARY_KEY PRIMARY_KEY
	FOREIGN_KEY FOREIGN_KEY
	NOT_NULL    NOT_NULL
	DEFAULT     DEFAULT
	UNIQUE      UNIQUE
	CHECK       CHECK
}

func (*Constraints) List

func (c *Constraints) List() []Constraint

type Credentials

type Credentials interface {
	ProjectID() string
	ServiceName() string
	DatabaseName() string
}

type DEFAULT

type DEFAULT struct{}

func (DEFAULT) SQL

func (c DEFAULT) SQL() string

func (DEFAULT) Value

func (c DEFAULT) Value() string

type Database

type Database struct {

	// logging interface
	Log logging.Logger

	// database name
	Name string

	// database client
	Client Client

	// custom classes
	Classes *Classes

	// class representing user
	UserClass *Class

	// callback channels
	Channels Channels

	MemGraph bool

	sync.RWMutex
	// contains filtered or unexported fields
}

func DB

func DB() *Database

func NewDatabase

func NewDatabase(logger logging.Logger, databaseName string, client Client, tools ...interface{}) *Database

func (*Database) AddClass

func (db *Database) AddClass(name string) *Class

adds a custom class to the schema

func (*Database) AddPredicate

func (db *Database) AddPredicate(name string) *Predicate

func (*Database) AddRelationship

func (db *Database) AddRelationship(relationship *Relationship)

func (*Database) ClassNameIndex

func (db *Database) ClassNameIndex(name string) *Class

func (*Database) ClassUidIndex

func (db *Database) ClassUidIndex(uid int64) *Class

func (*Database) ExportVertexList

func (db *Database) ExportVertexList(list []*Vertex)

func (*Database) FindSession

func (db *Database) FindSession(token string) (bool, *Session)

func (*Database) GetPredicate

func (db *Database) GetPredicate(name string) *Predicate

func (*Database) GetVertex

func (db *Database) GetVertex(uid int64) *Vertex

func (*Database) MOD_authenticate

func (db *Database) MOD_authenticate(req web.RequestInterface, arg interface{}) *web.ResponseStatus

func (*Database) MOD_createVertex

func (db *Database) MOD_createVertex(req web.RequestInterface, arg interface{}) *web.ResponseStatus

func (*Database) MOD_edgeState

func (db *Database) MOD_edgeState(req web.RequestInterface, arg interface{}) *web.ResponseStatus

func (*Database) MOD_getProperty

func (db *Database) MOD_getProperty(req web.RequestInterface, arg interface{}) *web.ResponseStatus

func (*Database) MOD_lookupVertex

func (db *Database) MOD_lookupVertex(req web.RequestInterface, arg interface{}) *web.ResponseStatus

func (*Database) MOD_return

func (db *Database) MOD_return(req web.RequestInterface, arg interface{}) *web.ResponseStatus

func (*Database) SetPredicate

func (db *Database) SetPredicate(name string, predicate *Predicate)

func (*Database) SetVertex

func (db *Database) SetVertex(vtx *Vertex)

func (*Database) Table

func (db *Database) Table(id string) string

type Edge

type Edge struct {
	Phase     bool
	InKey     string
	Predicate string
	OutKey    string
	State     bool
}

type EventClient

type EventClient interface {
	NewEventState(*Link) bool
	InsertVertex(*Vertex) bool
	UpdateVertex(*Vertex) bool
	DeleteVertex(*Vertex) bool
}

type FOREIGN_KEY

type FOREIGN_KEY struct {
	Val string
}

func (FOREIGN_KEY) SQL

func (c FOREIGN_KEY) SQL() string

func (FOREIGN_KEY) Value

func (c FOREIGN_KEY) Value() string

type InternalClasses

type InternalClasses struct {
	Constraints Constraints
	// contains filtered or unexported fields
}
type Link struct {
	Predicate *Predicate `json:"-"`
	// history uid
	Uid int64
	// edge id
	Id string
	// in
	I      *Vertex
	Iuid   int64
	Iclass int64
	// out
	O      *Vertex
	Ouid   int64
	Oclass int64
	// state
	State bool
	// update timestamp
	M time.Time
	// number of props
	H int64
	//
	Props int
	//
	sync.RWMutex
}

func (*Link) EdgeID

func (link *Link) EdgeID() string

func (*Link) HistoryID

func (link *Link) HistoryID() string

func (*Link) LoadVertex

func (link *Link) LoadVertex(phase bool) bool

func (*Link) ToIndex

func (link *Link) ToIndex()

type NOT_NULL

type NOT_NULL struct{}

func (NOT_NULL) SQL

func (c NOT_NULL) SQL() string

func (NOT_NULL) Value

func (c NOT_NULL) Value() string

type NULL

type NULL struct{}

func (NULL) SQL

func (c NULL) SQL() string

func (NULL) Value

func (c NULL) Value() string

type NewVertex

type NewVertex struct {
	Class    *Class
	ParamKey string
}

type PRIMARY_KEY

type PRIMARY_KEY struct {
	Val string
}

func (PRIMARY_KEY) SQL

func (c PRIMARY_KEY) SQL() string

func (PRIMARY_KEY) Value

func (c PRIMARY_KEY) Value() string

type Predicate

type Predicate struct {
	DB          *Database `json:"-"`
	Name        string
	Edges       *Class
	History     *Class
	Properties  *Class
	Initialized bool
	In          *Vector
	Out         *Vector

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Predicate) Add

func (predicate *Predicate) Add(state *Link)

func (*Predicate) Init

func (predicate *Predicate) Init()

func (*Predicate) Insert_Edge

func (predicate *Predicate) Insert_Edge(link *Link) bool

func (*Predicate) Insert_History

func (predicate *Predicate) Insert_History(link *Link) bool
func (predicate *Predicate) NewLink(inVertex *Vertex, outVertex *Vertex, s bool, properties ...map[string]interface{}) (bool, *Link)

func (*Predicate) PredicateService

func (predicate *Predicate) PredicateService()

func (*Predicate) Sync

func (predicate *Predicate) Sync() bool

func (*Predicate) SyncEdges

func (predicate *Predicate) SyncEdges(offset int64) bool

func (*Predicate) Traverse

func (predicate *Predicate) Traverse(uid int64, phase, export bool, limit int64) []*Vertex

func (*Predicate) TraverseCount

func (predicate *Predicate) TraverseCount(uid int64, phase bool) int64

func (*Predicate) TraverseEdges

func (predicate *Predicate) TraverseEdges(uid int64, phase bool, limit int64) []*Link

func (*Predicate) Update_Properties

func (predicate *Predicate) Update_Properties(historyId int64, payload map[string]interface{}) bool

type Properties

type Properties []*Property

func (Properties) Keys

func (properties Properties) Keys() []string

type Property

type Property struct {
	// root schema
	DB *Database `json:"-"`
	// vertex uid
	Vertex int64
	// name of this field
	Key string
	// arbitrary value
	Value *validation.Config
	// max length for strings
	Max int
	// is primary key
	Constraints map[Constraint]bool `json:"-"`
	sync.RWMutex
}

func (*Property) Options

func (property *Property) Options(options []interface{}) *Property

func (*Property) SQL_Datatype

func (property *Property) SQL_Datatype() string

func (*Property) Type

func (prop *Property) Type() reflect.Type

type PropertyExport

type PropertyExport struct {
	Vertex int64
	K      string
	V      interface{}
}

type Relationship

type Relationship struct {
	In        *Class
	Out       *Class
	Predicate string
}

type Relationships

type Relationships []*Relationship

type Session

type Session struct {
	DB        *Database `json:"-"`
	Uid       int64
	User      int64
	TokenHash string
	Timestamp int64
}

type StateIndex

type StateIndex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*StateIndex) Add

func (si *StateIndex) Add(state *Link, target int64) bool

type UNIQUE

type UNIQUE struct{}

func (UNIQUE) SQL

func (c UNIQUE) SQL() string

func (UNIQUE) Value

func (c UNIQUE) Value() string

type URL

type URL struct{}

type User

type User struct {
	DB           *Database `json:"-"`
	Uid          int64
	Name         string
	PasswordHash string
	Vertex       *Vertex
}

func (*User) NewSession

func (user *User) NewSession() (bool, string)

type Vector

type Vector struct {
	DB *Database

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Vector) Active

func (vector *Vector) Active(uid int64, phase bool, limit int64) []*Vertex

func (*Vector) ActiveCount

func (vector *Vector) ActiveCount(uid int64) int64

func (*Vector) ActiveEdges

func (vector *Vector) ActiveEdges(uid int64, limit int64) []*Link

func (*Vector) Add

func (vector *Vector) Add(state *Link)

func (*Vector) Count

func (vector *Vector) Count() int64

func (*Vector) SortOrder

func (vector *Vector) SortOrder(uid int64)

type Vertex

type Vertex struct {
	DB    *Database `json:"-"`
	Class *Class    `json:"-"`
	Uid   int64
	X     string
	Data  map[string]interface{}
	sync.RWMutex
}

func (*Vertex) Delete

func (vertex *Vertex) Delete() bool

deletes the existing vertex

func (*Vertex) GetProperty

func (vertex *Vertex) GetProperty(key string) interface{}

func (*Vertex) InCount

func (vertex *Vertex) InCount(predicateName string) int64

func (*Vertex) InList

func (vertex *Vertex) InList(predicateName string, export bool, limit int64) (bool, []*Vertex)

func (*Vertex) Insert

func (vertex *Vertex) Insert() bool

publishes the new vertex

func (*Vertex) LoadPayload

func (vertex *Vertex) LoadPayload(req web.RequestInterface) *web.ResponseStatus

func (*Vertex) LoadProperties

func (vertex *Vertex) LoadProperties(args ...string) bool

func (*Vertex) OutCount

func (vertex *Vertex) OutCount(predicateName string) int64

func (*Vertex) OutList

func (vertex *Vertex) OutList(predicateName string, export bool, limit int64) (bool, []*Vertex)

func (*Vertex) Patch

func (vertex *Vertex) Patch(props map[string]interface{}) bool

saves the properties of the vertex

func (*Vertex) Properties

func (vertex *Vertex) Properties(key string) map[string]interface{}

func (*Vertex) SaveData

func (vertex *Vertex) SaveData() bool

saves the properties of the vertex

func (*Vertex) SetEdgeState

func (vertex *Vertex) SetEdgeState(out *Vertex, predicateName string, state bool) bool

updates a state of a link between two vertices

func (*Vertex) SetProperty

func (vertex *Vertex) SetProperty(key string, value interface{})

type VertexIndex

type VertexIndex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (VertexIndex) New

func (vi VertexIndex) New() *VertexIndex

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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