store

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 10 Imported by: 6

Documentation

Overview

Package store - Contains solutions for Reading/Writing leaps documents, all store types should implement the Storage interface as this is used by leaps to read and write documents.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingDSN          = errors.New("Missing DSN")
	ErrUnrecognizedSQLType = errors.New("SQL Type not recognized")
)

SQL Type errors.

View Source
var (
	ErrDocumentNotExist = errors.New("attempted to fetch memory doc that has not been initialized")
)

Errors for the Memory type.

View Source
var (
	ErrInvalidDirectory = errors.New("invalid directory")
)

Errors for the FileStore type.

Functions

This section is empty.

Types

type Document

type Document struct {
	ID      string `json:"id" yaml:"id"`
	Content string `json:"content" yaml:"content"`
}

Document - A representation of a leap document, must have a unique ID.

func NewDocument

func NewDocument(content string) Document

NewDocument - Create a document with content and a generated UUID.

type File

type File struct {
	// contains filtered or unexported fields
}

File - Most basic persistent implementation of store.Crud. Simply stores each document into a file within a configured directory. The ID represents the filepath relative to the configured directory.

For example, with StoreDirectory set to /var/www, a document can be given the ID css/main.css to create and edit the file /var/www/css/main.css

func (*File) Create

func (s *File) Create(doc Document) error

Create - Create a new document in a file location

func (*File) Read

func (s *File) Read(id string) (Document, error)

Read - Read document from its file location.

func (*File) Update

func (s *File) Update(doc Document) error

Update - Update a document in its file location.

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Memory - Simply keeps documents in memory. Has zero persistence across sessions.

func (*Memory) Create

func (s *Memory) Create(doc Document) error

Create - Store document in memory.

func (*Memory) Read

func (s *Memory) Read(id string) (Document, error)

Read - Read document from memory.

func (*Memory) Update

func (s *Memory) Update(doc Document) error

Update - Update document in memory.

type SQL

type SQL struct {
	// contains filtered or unexported fields
}

SQL - A document store implementation for an SQL database.

func (*SQL) Create

func (m *SQL) Create(doc Document) error

Create - Create a new document in a database table.

func (*SQL) Read

func (m *SQL) Read(id string) (Document, error)

Read - Read document from a database table.

func (*SQL) Update

func (m *SQL) Update(doc Document) error

Update - Update document in a database table.

type SQLConfig

type SQLConfig struct {
	DSN         string      `json:"dsn" yaml:"dsn"`
	TableConfig TableConfig `json:"db_table" yaml:"db_table"`
}

SQLConfig - The configuration fields for an SQL document store solution.

func NewSQLConfig

func NewSQLConfig() SQLConfig

NewSQLConfig - A default SQL configuration.

type TableConfig

type TableConfig struct {
	Name       string `json:"table" yaml:"table"`
	IDCol      string `json:"id_column" yaml:"id_column"`
	ContentCol string `json:"content_column" yaml:"content_column"`
}

TableConfig - Fields for specifying the table labels of the SQL database target.

func NewTableConfig

func NewTableConfig() TableConfig

NewTableConfig - Default table configuration.

type Type

type Type interface {
	// Create - Create a new document.
	Create(Document) error

	// Read - Read a document.
	Read(ID string) (Document, error)

	// Update - Update an existing document.
	Update(Document) error
}

Type - Implemented by types able to acquire and store documents. This is abstracted in order to accommodate for multiple storage strategies. These methods should be asynchronous if possible.

func NewFile

func NewFile(storeDirectory string, allowWrites bool) (Type, error)

NewFile - Just a func that returns a File based store type.

func NewMemory

func NewMemory() Type

NewMemory - Returns a Memory store type.

func NewMySQL

func NewMySQL(config SQLConfig) (Type, error)

NewMySQL - Returns an SQL store type for connecting to MySQL databases.

DSN Should be of the format: [username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

func NewPostgreSQL

func NewPostgreSQL(config SQLConfig) (Type, error)

NewPostgreSQL - Returns an SQL store type for connecting to PostgreSQL databases.

DSN Should be of the format: postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]

Jump to

Keyboard shortcuts

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