dao

package
v0.0.0-...-6b4d9e4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dao provides access to the database. The main object is Source, from which a gorm.DB can be derived. The controllers are the methods used to access the database. Controllers are defined as methods on SOurce.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

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

Source is used to generate a DAO object (singleton)

func NewMemorySource

func NewMemorySource() *Source

NewMemorySource generate a memory database source

func NewPostgresSource

func NewPostgresSource() *Source

NewPostgresSource generates a postgres source

func (*Source) AllProducts

func (s *Source) AllProducts() models.Products

AllProducts dumps table content.

func (*Source) Close

func (s *Source) Close() error

Close the underlying database

func (*Source) CountProducts

func (s *Source) CountProducts() int

CountProducts return the number of products in db.

func (*Source) CreateProduct

func (s *Source) CreateProduct(price uint, code string) uint

CreateProduct register new product, return ID. Duplicates if already exists.

func (*Source) DeleteProduct

func (s *Source) DeleteProduct(id uint)

DeleteProduct using primary key.

func (*Source) DeleteProducts

func (s *Source) DeleteProducts()

DeleteProducts delete all products

func (*Source) GetDB

func (s *Source) GetDB() *gorm.DB

GetDB (lazily open and) returns the database associated with that source

func (*Source) GetProduct

func (s *Source) GetProduct(id uint) *models.Product

GetProduct by id

Jump to

Keyboard shortcuts

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