db

package
v0.0.0-...-73e35a2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2017 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConceptAlreadyExists = errors.New("concept already exists")

ErrConceptAlreadyExists is given on new concept creation, when a concept of that name and context already exists.

View Source
var ErrContextAlreadyExists = errors.New("context already exists")

ErrContextAlreadyExists self explanatory

View Source
var ErrEmptyLabel = errors.New("no label given")

ErrEmptyLabel is returned when trying to query for empty label

View Source
var ErrEmptyStatementSlice = errors.New("cannot generate statements from empty list")

ErrEmptyStatementSlice self explanatory

View Source
var ErrIncompleteUIDMap = errors.New("cannot find label in assigned uids")

ErrIncompleteUIDMap self explanatory

View Source
var ErrNoConceptFound = errors.New("no concept found")

ErrNoConceptFound is given when no concepts are found

View Source
var ErrNoPerspectivesFound = errors.New("no perspectives found")

ErrNoPerspectivesFound is given when no perspectives are found

View Source
var ErrNoStatements = errors.New("cannot create new perspective with no statements")

ErrNoStatements is given on creating a new perspective, with a zero length statement slice.

View Source
var ErrPasswordIncorrect = errors.New("password is incorrect")

ErrPasswordIncorrect is given when password is incorrect

View Source
var ErrResponseQuery = errors.New("database error: query")

ErrResponseQuery occurs on response query error, datasensitive version

View Source
var ErrResponseUnmarshalling = errors.New("database error: unmarshalling")

ErrResponseUnmarshalling occurs on response unmarshalling error, datasensitive version.

View Source
var ErrTooManyConcepts = errors.New("too many concepts")

ErrTooManyConcepts is given when too many concepts are found in a query expecting only one.

View Source
var ErrUsernameAlreadyExists = errors.New("username already exists")

ErrUsernameAlreadyExists is given on registration if user with username already exists

View Source
var ErrUsernameNotFound = errors.New("username not found")

ErrUsernameNotFound is given when queried username is not found

Functions

func AddSchema

func AddSchema(schema string)

AddSchema adds the given schema through the databaseclient

func Close

func Close()

Close the database client gracefully.

func FindConceptUID

func FindConceptUID(title string, context *Context) (uint64, error)

FindConceptUID finds the UID of the concept with the given title in the given context, if context is nil, and there exists only one concept of the title, that concept UID is returned, if there exists more concepts an error is returned.

func Init

func Init(args []string)

Init initializes the database, with the schema defined at TODO

func InitializeDatabaseClient

func InitializeDatabaseClient(ip string, port string)

InitializeDatabaseClient intializes the database client, this must be called before running other database functions.

func Query

func Query(name string, data interface{}) (*protos.Response, error)

Query queries with the query string through the database client

func QueryAndUnmarshal

func QueryAndUnmarshal(name string, data interface{}, result interface{}) error

QueryAndUnmarshal queries with the template of name, and the data. then unmarshals the result into the given result interface.

Types

type Comment

type Comment struct {
	Text      string `json:"text"`
	UID       uint64 `json:"_uid_"`
	UIDString string `json:"uidstring"`
}

Comment TODO

func (*Comment) NewReply

func (c *Comment) NewReply(user *User, text string) (*Comment, error)

NewReply will create a new reply on the given comment by the given user.

type Concept

type Concept struct {
	Title        string        `json:"title"`
	UID          uint64        `json:"_uid_"`
	Context      *Context      `json:"context"`
	Perspectives []Perspective `json:"perspectives"`
}

Concept TODO

func GetConcepts

func GetConcepts(title string) ([]Concept, error)

GetConcepts will given a concept title return a slice of concepts with the given title, differing in context

func NewConcept

func NewConcept(title string, context *Context) (*Concept, error)

NewConcept inserts a new concept into the database and returns the concept struct.

func (*Concept) NewPerspective

func (c *Concept) NewPerspective(texts []string) (*Perspective, error)

NewPerspective inserts a new perspective into the database and returns the concept struct.

type Context

type Context struct {
	Label     string `json:"label"`
	UID       uint64 `json:"_uid_"`
	UIDString string
}

Context TODO

func FindContext

func FindContext(label string) (*Context, error)

FindContext TODO

func NewContext

func NewContext(label string) (*Context, error)

NewContext TODO

type DatabaseClient

type DatabaseClient struct {
	Dgraph    *client.Dgraph
	Templater *templater.Templater
	Close     func()
}

DatabaseClient holds the dgraph client, and a function to gracefully close

func NewDatabaseClient

func NewDatabaseClient(ip string, port string) *DatabaseClient

NewDatabaseClient returns a dgraph client and the function to close it.

type Discussion

type Discussion struct {
	Text      string `json:"text"`
	DTitle    string `json:"dtitle"`
	UID       uint64 `json:"_uid_"`
	UIDString string `json:"uidstring"`
}

Discussion TODO

func NewDiscussion

func NewDiscussion(user *User, dTitle string, text string, subjectUIDString string) (*Discussion, error)

NewDiscussion creates a new discussion for the subject corresponding to the uidString, this discussion will have the given title. title is not unique.

func (*Discussion) NewComment

func (d *Discussion) NewComment(user *User, text string) (*Comment, error)

NewComment will create a new comment by the given user on the given discussion.

type Perspective

type Perspective struct {
	UID       uint64 `json:"_uid_"`
	UIDString string
	Statement *Statement `json:"statement"`
}

Perspective TODO

type Statement

type Statement struct {
	UID       uint64     `json:"_uid_"`
	UIDString string     `json:"uidstring"`
	Text      string     `json:"text"`
	Next      *Statement `json:"next"`
}

Statement TODO

type User

type User struct {
	Name      string `json:"name"`
	UID       uint64 `json:"_uid_"`
	UIDString string
}

User TODO

func FindUser

func FindUser(name string) (*User, error)

FindUser will given a user name return a user struct. error is nil if user exists.

func LoginUser

func LoginUser(name string, password string) (*User, error)

LoginUser will try to login with the name and password, returns the User struct. Errors returned are stripped for data.

func NewUser

func NewUser(name string, password string) (*User, error)

NewUser will save a user with the given name and password, returns the User struct, error will be nil if name is unique.

Jump to

Keyboard shortcuts

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