database

package
v0.0.0-...-4dd6f99 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 3 Imported by: 0

README

Database pkg

Used to interface with SQLite.

Table definition

Item

When you want to delete an item the item will just set to archive true.

  • id id primary key
  • name string
  • description string
  • position reference position
  • archive bool
  • category reference category
  • sub-category reference sub-category
Composite

What about "ikea items"? Like items that are the union of more items. I could just reference one item in other items

  • id id primary key
  • id item reference parent item
  • id other item reference child item
Category
  • id
  • name
  • description
Sub-category
  • id id primary key
  • name string
  • description string
  • category id reference category
Suppier codes

Sqlite doesn't support arrays. So you should divide into smaller columns the data that should be rappresented as an array.

  • id id primary key
  • supplier code string
  • item id reference item
  • variant id reference variant
  • supplier id reference supplier
Images

Images is a one to many reference, so you will SELECT * FROM images, not the other way around. You do not need a reference in items. The same is true for supplier code.

  • id id primary key
  • uri string
  • item id reference item
  • variant id reference variant
Position
  • id id primary key
  • zone string
  • aisle string
  • rack string
  • shelf string
Variants

We could say that by default every item has at least one variant. We can then add other variants if we see fit, but it's an optional thing. The idea is that the name of the variant should complete the name of the item, rather than substitute it. So if we could have:

Black Lather Jacket -> Name of item Black Lather Jacket xl -> Name of variant Black Lather Jacket md -> Name of variant

So basically whenever we create an item we also create a default variant that has a fixed name, even like no name at all, so that we could just reference it whenever we are displaying a single item with no variant.

  • id id primary key
  • name string
  • description string
  • quantity int
  • internal id string
  • length int
  • width int
  • height int
  • weight int
  • item id reference item
  • default variant boolean
Supplier
  • id id primary key
  • name string
  • description string
User
  • id id primary key
  • name string
  • surname string
  • email string
  • password string
revoked token

I could even use the token itself as a form of id.

  • id id primary key
  • token string
  • time num
transision

Holds the warehouse movements and who did them. Basically whenever a product is added, modified or deleted a new transision is created. A transision is just a reference of the warehouse movement. It holds just the type of product, the quantity and the person responsible for said transision. Whenever a warehouse movement "happens" a transision is created with the number of products used and then the product entry is updated based on that number.

  • id
  • user id
  • product id
  • quantity
  • date
tools

A tool is kinda like an item. The only thing is that a tool istance is usually just used for checking the position in the warehouse.

  • id id primary key
  • name string
  • description string
  • quantity int
  • internal id string
  • length int
  • width int
  • height int
  • weight int
Images
  • id id primary key
  • uri string
  • tool is reference tool
products

Imagine items as components used for making, repaing and modifing products.

  • id id primary key

  • name string

  • description string

  • quantity int

  • internal id string

  • length int

  • width int

  • height int

  • weight int

  • state string
    rented / available / sold / under repair etc. the state could be set automatically based on the last ticket? If there are no open ticket is available. If a rent ticket is open, the machine is rented If a repair ticket is open, the machine in under maintainence

    SELECT name FROM ticket_state WHERE tickets.product = product

  • owner

image
  • id id primary key
  • uri string
  • tool is reference tool
movements
  • id id primary key
  • user id reference user
  • machine id reference machine
  • quantity int
  • date data
client
  • id id primary key
  • name string
  • address string
  • business boolean
tickets -> repairs, rent etc.
  • id id primary key
  • name string
  • description string
  • open date date
  • close date date
  • client id reference client
  • product id reference product
  • type id reference to type
  • state id reference state open / closed / in progress repair, rent, whatever you want
tickets types
  • id
  • name
  • description
ticket state
  • id
  • name
  • description
items used in ticket
  • id
  • ticket id
  • item id

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aisle

type Aisle struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Zone_id string `json:"zone"`
}

An Aisle is a collection of Racks

func (Aisle) GetId

func (i Aisle) GetId() string

type Category

type Category struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (Category) GetId

func (i Category) GetId() string

type Client

type Client struct {
	Id         string `json:"id"`
	Name       string `json:"name"`
	Surname    string `json:"surname"`
	IsBusiness bool   `json:"isBusiness"`
}

func (Client) GetId

func (i Client) GetId() string

type Database

type Database struct {
	Sorm *sorm.Database
}

func Init

func Init(path string) (Database, error)

Initializes the database, creates file if not present

func Open

func Open(path string) (Database, error)

func (*Database) CheckRevokedToken

func (db *Database) CheckRevokedToken(token string) error

func (*Database) CheckUser

func (db *Database) CheckUser(email, password string) error

Check if user is valid

func (Database) Delete

func (db Database) Delete(obj interface{}, condition string, args ...interface{}) error

General query to delete an item

func (Database) Insert

func (db Database) Insert(rows ...interface{}) error

General query for every table

func (*Database) InsertUser

func (db *Database) InsertUser(user User) error

func (*Database) RevokeToken

func (db *Database) RevokeToken(token string) error

func (*Database) SelectAisleById

func (db *Database) SelectAisleById(id string) (Aisle, error)

func (*Database) SelectAisles

func (db *Database) SelectAisles(condition string, args ...interface{}) ([]Aisle, error)

func (*Database) SelectAislesByZone

func (db *Database) SelectAislesByZone(id string) ([]Aisle, error)

func (*Database) SelectCategories

func (db *Database) SelectCategories(condition string, args ...interface{}) ([]Category, error)

func (*Database) SelectCategoryById

func (db *Database) SelectCategoryById(id string) (Category, error)

func (*Database) SelectClients

func (db *Database) SelectClients(condition string, args ...interface{}) ([]Client, error)

func (*Database) SelectDefaultVariant

func (db *Database) SelectDefaultVariant(item string) (Variant, error)

func (*Database) SelectItemById

func (db *Database) SelectItemById(id string) (Item, error)

Select a single item based on the id

func (Database) SelectItemImageById

func (db Database) SelectItemImageById(id string) (Item_image, error)

func (*Database) SelectItemImages

func (db *Database) SelectItemImages(condition string, args ...interface{}) ([]Item_image, error)

func (Database) SelectItemImagesByItemId

func (db Database) SelectItemImagesByItemId(id string) ([]Item_image, error)

From a given id gets all the images

func (*Database) SelectItemVariants

func (db *Database) SelectItemVariants(item string) ([]Variant, error)

func (*Database) SelectItems

func (db *Database) SelectItems(condition string, args ...interface{}) ([]Item, error)

Select an item based on the condition and the args

func (*Database) SelectItemsByCategoryId

func (db *Database) SelectItemsByCategoryId(id string) ([]Item, error)

func (*Database) SelectItemsBySubcategoryId

func (db *Database) SelectItemsBySubcategoryId(id string) ([]Item, error)

func (*Database) SelectOperations

func (db *Database) SelectOperations(condition string, args ...interface{}) ([]Operation, error)

func (*Database) SelectProductImages

func (db *Database) SelectProductImages(condition string, args ...interface{}) ([]ProductImage, error)

func (*Database) SelectProducts

func (db *Database) SelectProducts(condition string, args ...interface{}) ([]Product, error)

func (*Database) SelectRackById

func (db *Database) SelectRackById(id string) (Rack, error)

func (*Database) SelectRacks

func (db *Database) SelectRacks(condition string, args ...interface{}) ([]Rack, error)

func (*Database) SelectRacksByAisle

func (db *Database) SelectRacksByAisle(id string) ([]Rack, error)

func (*Database) SelectSettings

func (db *Database) SelectSettings() (Settings, error)

func (*Database) SelectShelfById

func (db *Database) SelectShelfById(id string) (Shelf, error)

func (*Database) SelectShelfs

func (db *Database) SelectShelfs(condition string, args ...interface{}) ([]Shelf, error)

func (*Database) SelectShelfsByRack

func (db *Database) SelectShelfsByRack(id string) ([]Shelf, error)

func (*Database) SelectSubcategories

func (db *Database) SelectSubcategories(condition string, args ...interface{}) ([]Subcategory, error)

func (*Database) SelectSubcategoryById

func (db *Database) SelectSubcategoryById(id string) (Subcategory, error)

func (*Database) SelectSupplierById

func (db *Database) SelectSupplierById(id string) (Supplier, error)

func (*Database) SelectSupplierCodes

func (db *Database) SelectSupplierCodes(condition string, args ...interface{}) ([]SupplierCode, error)

func (*Database) SelectSupplierCodesByItemId

func (db *Database) SelectSupplierCodesByItemId(id string) ([]SupplierCode, error)

func (*Database) SelectSuppliers

func (db *Database) SelectSuppliers(condition string, args ...interface{}) ([]Supplier, error)

func (*Database) SelectTicketStates

func (db *Database) SelectTicketStates(condition string, args ...interface{}) ([]TicketState, error)

func (*Database) SelectTicketTypes

func (db *Database) SelectTicketTypes(condition string, args ...interface{}) ([]TicketType, error)

func (*Database) SelectTickets

func (db *Database) SelectTickets(condition string, args ...interface{}) ([]Ticket, error)

func (*Database) SelectUnitById

func (db *Database) SelectUnitById(id string) (Unit, error)

func (*Database) SelectUnits

func (db *Database) SelectUnits(condition string, args ...interface{}) ([]Unit, error)

func (*Database) SelectUser

func (db *Database) SelectUser(condition string, args ...interface{}) ([]User, error)

func (*Database) SelectUserById

func (db *Database) SelectUserById(id string) (User, error)

Select a single item based on the id

func (*Database) SelectVariantById

func (db *Database) SelectVariantById(id string) (Variant, error)

func (*Database) SelectVariants

func (db *Database) SelectVariants(condition string, args ...interface{}) ([]Variant, error)

func (*Database) SelectZoneById

func (db *Database) SelectZoneById(id string) (Zone, error)

func (*Database) SelectZones

func (db *Database) SelectZones(condition string, args ...interface{}) ([]Zone, error)

func (Database) Update

func (db Database) Update(obj interface{}, condition string, args ...interface{}) error

General query to update an item

func (*Database) UpdateSettings

func (db *Database) UpdateSettings(new Settings) error

type Identifiable

type Identifiable interface {
	GetId() string
}

Interface used to get the id in the server package. Used to delete the nil item

type Item

type Item struct {
	Id             string `json:"id"`
	Name           string `json:"name"`
	Description    string `json:"description"`
	IsArchive      bool   `json:"isArchive"`
	Zone_id        string `json:"zone"`
	Aisle_id       string `json:"aisle"`
	Rack_id        string `json:"rack"`
	Shelf_id       string `json:"shelf"`
	Category_id    string `json:"category"`
	Subcategory_id string `json:"subcategory"`
}

type Item_image

type Item_image struct {
	Id      string `json:"id"`
	Uri     string `json:"uri"`
	Item_id string `json:"item"`
}

func (Item_image) GetId

func (i Item_image) GetId() string

type Metadata

type Metadata struct {
	Secret string
}

type NewUser

type NewUser struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Surname  string `json:"surname"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

This struct is used to handle incoming POST requests for new users

type Operation

type Operation struct {
	Id         string `json:"id"`
	Date       string `json:"date"`
	Quantity   int    `json:"quantity"`
	User_id    string `json:"user"`
	Item_id    string `json:"item"`
	Variant_id string `json:"variant"`
}

func (Operation) GetId

func (i Operation) GetId() string

type Position

type Position struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Zone_id  string `json:"zone"`
	Aisle_id string `json:"aisle"`
	Rack_id  string `json:"rack"`
	Shelf_id string `json:"shelf"`
}

type Product

type Product struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (Product) GetId

func (i Product) GetId() string

type ProductImage

type ProductImage struct {
	Id         string `json:"id"`
	Url        string `json:"url"`
	Product_id string `json:"product"`
}

func (ProductImage) GetId

func (i ProductImage) GetId() string

type Rack

type Rack struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Zone_id  string `json:"zone"`
	Aisle_id string `json:"aisle"`
}

A Rack is a collection of Shelfs

func (Rack) GetId

func (i Rack) GetId() string

type RefreshToken

type RefreshToken struct {
	Id      string `json:"id"`
	Token   string `json:"token"`
	Revoked bool   `json:"revoked"`
}

type Settings

type Settings struct {
	Id         string     `json:"id"`
	UnitSystem UnitSystem `json:"system"`

	Unit_Length_id string `json:"defaultLengthUnit"`
	Unit_Weight_id string `json:"defaultWeightUnit"`

	// WIP: Used to show the wizard
	Wizard bool `json:"wizard"`
}

type Shelf

type Shelf struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Zone_id  string `json:"zone"`
	Aisle_id string `json:"aisle"`
	Rack_id  string `json:"rack"`
}

A Shelf is the lowest one

func (Shelf) GetId

func (i Shelf) GetId() string

type Subcategory

type Subcategory struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Category_id string `json:"category"`
}

func (Subcategory) GetId

func (i Subcategory) GetId() string

type Supplier

type Supplier struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (Supplier) GetId

func (i Supplier) GetId() string

type SupplierCode

type SupplierCode struct {
	Id          string `json:"id"`
	Code        string `json:"code"`
	Supplier_id string `json:"supplier"`
	Item_id     string `json:"item"`
	Variant_id  string `json:"variant"`
}

func (SupplierCode) GetId

func (i SupplierCode) GetId() string

type Ticket

type Ticket struct {
	Id             string `json:"id"`
	Name           string `json:"name"`
	Description    string `json:"description"`
	Open           string `json:"open"`
	Close          string `json:"close"`
	Client_id      string `json:"client"`
	Product_id     string `json:"product"`
	TicketType_id  string `json:"type"`
	TicketState_id string `json:"state"`
}

func (Ticket) GetId

func (i Ticket) GetId() string

type TicketState

type TicketState struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (TicketState) GetId

func (i TicketState) GetId() string

type TicketType

type TicketType struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (TicketType) GetId

func (i TicketType) GetId() string

type Unit

type Unit struct {
	Id   string `json:"id"`
	Type string `json:"type"`
	// The ratio from smallest unit to current unit (grams or millimiters)
	Ratio      float64    `json:"ratio"`
	UnitSystem UnitSystem `json:"system"`
}

type UnitSystem

type UnitSystem string
const (
	MetricSystem   UnitSystem = "metric"
	ImperialSystem UnitSystem = "imperial"
)

type User

type User struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Surname  string `json:"surname"`
	Email    string `json:"email"`
	Password string `json:"-"`
}

func (User) GetId

func (i User) GetId() string

type Variant

type Variant struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Quantity    int64  `json:"quanity"`
	Identifier  string `json:"identifier"`

	Length         float64 `json:"length"`
	Width          float64 `json:"width"`
	Height         float64 `json:"height"`
	Weight         float64 `json:"weight"`
	DefaultVariant bool    `json:"defaultVariant"`
	Item_id        string  `json:"item"`

	// The definition is with underscores because sorm needs the first splitted item to be the
	// table name and the last the relationship, so in this case a foreign key. Do not change them
	// If you changed it change it back to Unit_x_id
	Unit_Length_id string `json:"lengthUnit"`
	Unit_Weight_id string `json:"weightUnit"`
}

func (Variant) GetId

func (i Variant) GetId() string

type Zone

type Zone struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

A zone is a collection of Aisles

func (Zone) GetId

func (i Zone) GetId() string

Directories

Path Synopsis
*******************************************************************
*******************************************************************

Jump to

Keyboard shortcuts

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