db

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Schema = `` /* 1251-byte string literal not displayed */

Schema is the database schema

Functions

This section is empty.

Types

type ConfigDB

type ConfigDB struct {
	DBClient *dgo.Dgraph
}

ConfigDB is the configuration for DGraph

func NewClient

func NewClient(url string) (*ConfigDB, error)

NewClient sets up a gRPC and returns a new dgraph connection

func (*ConfigDB) CountNodesWithFieldUnsafe

func (config *ConfigDB) CountNodesWithFieldUnsafe(f string) (*int, error)

CountNodesWithFieldUnsafe returns the number of nodes which contain the specified field this is a good indicator of the number of nodes of a certain type this is unsafe, there is no input sanitation and is open to injection attacks

func (*ConfigDB) GetEvent

func (config *ConfigDB) GetEvent(event Event) (*Event, error)

GetEvent should recieve a dgraph client and an event struct, and return the official event struct from the database, complete with Uid for referencing if no such event exists, then it returns an error

func (*ConfigDB) GetLocationFromKentSlug

func (config *ConfigDB) GetLocationFromKentSlug(slug string) (*Location, error)

GetLocationFromKentSlug returns a matching location from the slug kent uses internally

func (*ConfigDB) GetModuleFromSDSCode

func (config *ConfigDB) GetModuleFromSDSCode(slug string) (*Module, error)

GetModuleFromSDSCode returns a matching module from the slug kent uses internally, or nil if it doesnt exist

func (*ConfigDB) GetOldestScrape

func (config *ConfigDB) GetOldestScrape() (*Scrape, error)

GetOldestScrape retrieves the oldest scrape from the database

func (*ConfigDB) GetScrape

func (config *ConfigDB) GetScrape(scrape Scrape) (*Scrape, error)

GetScrape should recieve a dgraph client and a scrape struct, and return the official scrape struct from the database, complete with Uid for referencing if no such struct exists, then it returns an error

func (*ConfigDB) ReadOnly

func (config *ConfigDB) ReadOnly(q string) ([]byte, error)

ReadOnly is a read only transaction on the database - this is assumed to be ok

func (*ConfigDB) RemoveScrape

func (config *ConfigDB) RemoveScrape(scrape Scrape) error

RemoveScrape deletes the specified scrape from the database.

func (*ConfigDB) Setup

func (config *ConfigDB) Setup() error

Setup initiates the schema into the database

func (*ConfigDB) UpsertEvent

func (config *ConfigDB) UpsertEvent(event Event) (*api.Response, error)

UpsertEvent upserts the event struct into the database

func (*ConfigDB) UpsertLocation

func (config *ConfigDB) UpsertLocation(loc Location) (*api.Response, error)

UpsertLocation upserts the location struct into the database

func (*ConfigDB) UpsertModule

func (config *ConfigDB) UpsertModule(m Module) (*api.Response, error)

UpsertModule upserts the location struct into the database

func (*ConfigDB) UpsertScrape

func (config *ConfigDB) UpsertScrape(scrape Scrape) (*api.Response, error)

UpsertScrape upserts the scrape struct into the database

type Event

type Event struct {
	UID          string     `json:"uid,omitempty"`
	ID           string     `json:"event.id,omitempty"`
	Title        string     `json:"event.title,omitempty"`
	Description  string     `json:"event.description,omitempty"`
	StartDate    *time.Time `json:"event.start_date,omitempty"`
	EndDate      *time.Time `json:"event.end_date,omitempty"`
	Organiser    []Person   `json:"event.organiser,omitempty"`
	PartOfModule []Module   `json:"event.part_of_module,omitempty"`
	Location     []Location `json:"event.location,omitempty"`

	DType []string `json:"dgraph.type,omitempty"`
}

func (Event) Equal

func (e Event) Equal(e2 Event) bool

Equal checks if the two events are equal Does not check UID, as the contents could change Does not check the contents of Location, as these are decided at the start

type Loc

type Loc struct {
	Type   string    `json:"type,omitempty"`
	Coords []float64 `json:"coordinates,omitempty"`
}

type Location

type Location struct {
	UID            string   `json:"uid,omitempty"`
	ID             string   `json:"location.id,omitempty"`
	Name           string   `json:"location.name,omitempty"`
	Location       Loc      `json:"location.loc,omitempty"`
	DisabledAccess bool     `json:"location.disabled_access"`
	DType          []string `json:"dgraph.type,omitempty"`
}

func (Location) Equal

func (l Location) Equal(l2 Location) bool

Equal returns whether or not the two locations are equivalent

type Module

type Module struct {
	UID     string `json:"uid,omitempty"`
	Code    string `json:"module.code,omitempty"`
	Name    string `json:"module.name,omitempty"`
	Subject string `json:"module.subject,omitempty"`
	// URL     string   `json:"module.url,omitempty"`
	DType []string `json:"dgraph.type,omitempty"`
}

func (Module) Equal

func (m Module) Equal(m2 Module) bool

Equal returns whether or not the two modules are equivalent

type Person

type Person struct {
	UID   string   `json:"uid,omitempty"`
	Name  string   `json:"person.name,omitempty"`
	Email string   `json:"person.email,omitempty"`
	DType []string `json:"dgraph.type,omitempty"`
}

type Scrape

type Scrape struct {
	UID         string     `json:"uid,omitempty"`
	ID          int        `json:"scrape.id,omitempty"`
	LastScraped *time.Time `json:"scrape.last_scraped,omitempty"`
	FoundEvent  []Event    `json:"scrape.found_event,omitempty"`
	DType       []string   `json:"dgraph.type,omitempty"`
}

Jump to

Keyboard shortcuts

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