sqlite

package
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sqlite provides implementation of api.PasteService that uses sqlite database as a storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PasteService

type PasteService struct {
	Options SvcOptions
	// contains filtered or unexported fields
}

PasteService stores all the pastes in sqlite database and implements the api.PasteService interface.

func New

func New(opts SvcOptions) (*PasteService, error)

New returns new PasteService with an empty map of pastes.

func (*PasteService) Create

func (s *PasteService) Create(p api.PasteForm) (*api.Paste, error)

Create initialises a new paste from the provided data and adds it to the storage. It returns the newly created paste.

func (*PasteService) Delete

func (s *PasteService) Delete(id int64) error

Delete removes the paste from the storage

func (*PasteService) Get

func (s *PasteService) Get(id int64) (*api.Paste, error)

Get returns a paste by it's ID. The return values are as follows: - if there is a problem talking to the database paste== nil, err != nil - if paste is not found paste== nil, err == nil - if paste is found paste != nil, err == nil

func (*PasteService) List

func (s *PasteService) List(uid int64) []api.Paste

List returns a slice of all the pastes by a user ID.

type SvcOptions

type SvcOptions struct {
	// Database connection string.
	// For sqlite it should be either a file name or `file::memory:?cache=shared`
	// to use temporary database in memory (ex. for testing).
	DBConnection *gorm.DB
	//
	DBAutoMigrate bool
}

SvcOptions contains all the options needed to create an instance of PasteService

Jump to

Keyboard shortcuts

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