database

package
Version: v0.0.0-...-301923a Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database driver names that we accept
	DriverMongo = "mongo"
	DriverBolt  = "bolt"
)

Variables

This section is empty.

Functions

func NewCollectionId

func NewCollectionId(in *wyc.Collection) string

Create new collection ID using Parent & Name variables

func NewItemId

func NewItemId(in *wyc.Item) string

Create new item ID using parent type & variant vars

func NewLinkId

func NewLinkId(in *wyc.Link) string

Create new link ID using name, src and dst

func NewResourceId

func NewResourceId(in *wyc.Resource) string

Create new resource ID using parent, name and type

func NewVersionId

func NewVersionId(in *wyc.Version) string

Create new version ID using parent & number

Types

type Database

type Database interface {
	// Given a Version ID, set the Version as "published"
	// That is, of all versions belonging to the parent Item, the version with
	// this ID is marked as the published "official" version
	//  - Must: Ensure at most one Version of a given Item is marked as published
	SetPublished(string) error

	// Given an Item ID, return the ID of the current PublishedVersion version (if any)
	Published(string) (*wyc.Version, error)

	// Insert a collection into the db, return created Id
	//  - Must: Ensure only one collection with given Name
	InsertCollection(*wyc.Collection) (string, error)

	// Insert an item into the db, return created Id
	//  - Must: Ensure only one item with the same Collection (parent Id), Type and Variant
	InsertItem(*wyc.Item) (string, error)

	// Insert a Version into the db, return created Id
	//  - Must: Ensure version number is both set on the obj & returned.
	//  - Must: Number version numbers starting with 1
	//  - Must: Ensure there is at most one version of a given number
	InsertNextVersion(*wyc.Version) (string, int32, error) // Ensure only one version of an Item with a given Number

	// Insert resource into the db, return created Id
	InsertResource(*wyc.Resource) (string, error)

	// Insert link into the db, return created Id
	InsertLink(*wyc.Link) (string, error)

	// Retrieve collections indicated by the given Id(s) from the db
	RetrieveCollection(...string) ([]*wyc.Collection, error)

	// Retrieve items indicated by the given Id(s) from the db
	RetrieveItem(...string) ([]*wyc.Item, error)

	// Retrieve versions indicated by the given Id(s) from the db
	RetrieveVersion(...string) ([]*wyc.Version, error)

	// Retrieve resources indicated by the given Id(s) from the db
	RetrieveResource(...string) ([]*wyc.Resource, error)

	// Retrieve links indicated by the given Id(s) from the db
	RetrieveLink(...string) ([]*wyc.Link, error)

	// Save the updated facets on the given version
	UpdateItem(string, *wyc.Item) error

	// Save the updated facets on the given item
	UpdateVersion(string, *wyc.Version) error

	// Save the updated facets on the given collection
	UpdateCollection(string, *wyc.Collection) error

	// Save the updated facets on the given resource
	UpdateResource(string, *wyc.Resource) error

	// Save the updated facets on the given link
	UpdateLink(string, *wyc.Link) error

	// Delete collection(s) with the given Id(s)
	DeleteCollection(...string) error

	// Delete item(s) with the given Id(s)
	DeleteItem(...string) error

	// Delete version(s) with the given Id(s)
	DeleteVersion(...string) error

	// Delete resource(s) with the given Id(s)
	DeleteResource(...string) error

	// Delete link(s) with the given Id(s)
	DeleteLink(...string) error

	// kill connection to db
	Close() error
}

Datastore whose primary goal is long term storage, not searching said data

func Connect

func Connect(settings *Settings) (Database, error)

Return a connect function for the given settings, or err if it can't be found

type Settings

type Settings struct {
	// The name of the driver (will be used to load via Connect in database.go)
	Driver string

	// Database settings to use in the connection
	Host     string
	Port     int
	User     string
	Pass     string
	Database string
	PemFile  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL