leaps: github.com/Jeffail/leaps/lib/store Index | Files

package store

import "github.com/Jeffail/leaps/lib/store"

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

Package Files

document.go file_based.go interface.go memory.go package.go sql_based.go

Variables

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

SQL Type errors.

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

Errors for the Memory type.

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

Errors for the FileStore type.

type Document Uses

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 Uses

func NewDocument(content string) Document

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

type File Uses

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 Uses

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

Create - Create a new document in a file location

func (*File) Read Uses

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

Read - Read document from its file location.

func (*File) Update Uses

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

Update - Update a document in its file location.

type Memory Uses

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

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

func (*Memory) Create Uses

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

Create - Store document in memory.

func (*Memory) Read Uses

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

Read - Read document from memory.

func (*Memory) Update Uses

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

Update - Update document in memory.

type SQL Uses

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

SQL - A document store implementation for an SQL database.

func (*SQL) Create Uses

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

Create - Create a new document in a database table.

func (*SQL) Read Uses

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

Read - Read document from a database table.

func (*SQL) Update Uses

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

Update - Update document in a database table.

type SQLConfig Uses

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 Uses

func NewSQLConfig() SQLConfig

NewSQLConfig - A default SQL configuration.

type TableConfig Uses

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 Uses

func NewTableConfig() TableConfig

NewTableConfig - Default table configuration.

type Type Uses

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 Uses

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

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

func NewMemory Uses

func NewMemory() Type

NewMemory - Returns a Memory store type.

func NewMySQL Uses

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 Uses

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&...]

Package store imports 10 packages (graph) and is imported by 3 packages. Updated 2018-02-20. Refresh now. Tools for package owners.