db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	New        ProjectState = "New"
	Upcoming   ProjectState = "Upcoming"
	Pending    ProjectState = "Pending"
	NotStarted ProjectState = "Not Started"
	Draft      ProjectState = "Draft"
	Active     ProjectState = "Active"
	Priority   ProjectState = "Priority"
	Canceld    ProjectState = "Canceled"
	Onhold     ProjectState = "On-Hold"
	Archived   ProjectState = "Archived"

	Concept     RevisionState = "Concept"
	Underreview RevisionState = "Under Review"
	Released    RevisionState = "Released"
	Inwork      RevisionState = "In-Work"
	Depreciated RevisionState = "Depreciated"

	Lot       TracebilityState = "Lot"
	LotSerial TracebilityState = "Lot and Serial"
	Serial    TracebilityState = "Serial"
	NotTaced  TracebilityState = "Not-Traced"

	D_gmm3        DensityUnit = "Gram / mm^3"
	D_gcm3        DensityUnit = "Gram / cm^3"
	D_kgm3        DensityUnit = "Kilo Gram / m^3"
	D_tonnem3     DensityUnit = "Tonne / m^3"
	D_metrictonm3 DensityUnit = "Metric Ton / m^3" // equal to tonne
	D_poundft3    DensityUnit = "Pound / Ft^3"
	D_poundinch3  DensityUnit = "Pound / inch^3"

	V_mm3   VolumeUnit = "Cubic mm [mm^3]"
	V_cm3   VolumeUnit = "Cubic cm [cm^3]"
	V_m3    VolumeUnit = "Cubic m [m^3]"
	V_litre VolumeUnit = "Litre"
	V_ft3   VolumeUnit = "Cubic ft [Ft^3]"
	V_inch3 VolumeUnit = "Cubic inch [Inch^3]"

	W_g         WeightUnit = "Gram [g]"
	W_kg        WeightUnit = "Kilo Gram [kg]"
	W_tonne     WeightUnit = "Tonne [t]"
	W_metricton WeightUnit = "Metric Ton" // equal to tonne
	W_pound     WeightUnit = "Pound [p]"
	W_slug      WeightUnit = "Slug"

	A_mm2   AreaUnit = "Square mm [mm^2]"
	A_cm2   AreaUnit = "Square cm [cm^2]"
	A_m2    AreaUnit = "Square m [m^2]"
	A_ft2   AreaUnit = "Square ft [Ft^2]"
	A_inch2 AreaUnit = "Square inch [Inch^2]"
)
View Source
const DB_HOST = "127.0.0.1"
View Source
const DB_NAME = "my_db"
View Source
const DB_PASSWORD = "root"
View Source
const DB_PORT = "3306"
View Source
const DB_USERNAME = "root"

Variables

View Source
var Db *gorm.DB

Functions

func CreateDefaultTables

func CreateDefaultTables(db *gorm.DB) error

CreateDefaultTables creates the default set of tables in the database.

func CreateNumber

func CreateNumber(number string, ndigits *int) (string, error)

Create new Project number number is only added when it has a value. CreateNumber generates a new project number based on the last current number. number: Last current number as a string, including leading zeros. ndigits: Number of digits for the new number length. If -1, the length is just the length of the number.

func InitDB

func InitDB()

To initialize the database

func InitDb

func InitDb() *gorm.DB

func InitializeDB

func InitializeDB(databaseURL string) (*gorm.DB, error)

InitializeDB initializes the database connection.

func RolePermissions

func RolePermissions(role Permission) []string

role -> permissions mapping See: https://www.osohq.com/academy/role-based-access-control-rbac

Types

type AreaUnit

type AreaUnit string

type Base

type Base struct {
	ID uint `gorm:"primaryKey"`
}

Base struct to embed in other models

type DataBasePostgreSQL

type DataBasePostgreSQL struct {
	*DatabaseGen
}

DataBasePostgreSQL struct feeds forward of generic SQL functions to PostgreSQL

func NewDataBasePostgreSQL

func NewDataBasePostgreSQL() *DataBasePostgreSQL

NewDataBasePostgreSQL initializes a new PostgreSQL database

func (*DataBasePostgreSQL) StartEngine

func (db *DataBasePostgreSQL) StartEngine(echo bool) error

StartEngine starts the PostgreSQL engine

type Database

type Database struct {
	Engine *gorm.DB
}

Database struct encapsulates the GORM DB instance.

func StartYourEngine

func StartYourEngine(url string) (*Database, error)

StartYourEngine initializes the database connection.

func (*Database) CreateDefaultTables

func (d *Database) CreateDefaultTables() error

CreateDefaultTables creates default tables in the database.

type DatabaseGen

type DatabaseGen struct {
	DriverName   string
	Username     string
	Password     string
	Host         string
	Port         int
	DatabaseName string
	Engine       *gorm.DB
}

DatabaseGen is a generic SQL Database class

func NewDatabaseGen

func NewDatabaseGen() *DatabaseGen

NewDatabaseGen initializes a new DatabaseGen

func (*DatabaseGen) CreateDB

func (db *DatabaseGen) CreateDB() error

CreateDB not implemented yet

func (*DatabaseGen) CreateTable

func (db *DatabaseGen) CreateTable() error

CreateTable not implemented yet

func (*DatabaseGen) DeleteTable

func (db *DatabaseGen) DeleteTable() error

DeleteTable not implemented yet

func (*DatabaseGen) GetTables

func (db *DatabaseGen) GetTables() error

GetTables not implemented yet

func (*DatabaseGen) MakeURL

func (db *DatabaseGen) MakeURL() string

MakeURL creates a new connection URL

type DensityUnit

type DensityUnit string

type Document

type Document struct {
}

Document related

type FileSystem

type FileSystem struct{}

File System related Class

func (*FileSystem) CreateFileIdx

func (fs *FileSystem) CreateFileIdx()

Create file copy

func (*FileSystem) CreateFolder

func (fs *FileSystem) CreateFolder()

Create new folder

func (*FileSystem) Init

func (fs *FileSystem) Init()

type Item

type Item struct {
	gorm.Model
	ID       uint   `gorm:"primaryKey"`
	ItemName string `gorm:"size:100"`
	// number          int
	Project         string
	Path            string
	Name            string
	Description     string
	FullDescription string
}

Item represents the items table.

func (*Item) AddItemImage

func (i *Item) AddItemImage()

Update existing item

func (*Item) RemoveItem

func (i *Item) RemoveItem()

Remove existing item

func (*Item) UpdateItem

func (i *Item) UpdateItem()

Update existing item

type Model

type Model struct {
}

Model related

func (Model) CreateModel

func (m Model) CreateModel()

Create new model

func (Model) GetVersion

func (m Model) GetVersion()

Get model that is not latest version

func (Model) RemoveModel

func (m Model) RemoveModel()

Remove existing model

func (Model) UpdateModel

func (m Model) UpdateModel()

Update existing model

type OwnerStates

type OwnerStates struct {
}

Item / Model / Document Ownership states

func (OwnerStates) CheckIn

func (o OwnerStates) CheckIn()

Check in Items, Models, Documents

func (OwnerStates) CheckInCheckOut

func (o OwnerStates) CheckInCheckOut()

Check in Items, Models, Documents

func (OwnerStates) CheckOut

func (o OwnerStates) CheckOut()

Check in Items, Models, Documents

type PdmDocument

type PdmDocument struct {
	Base
	DocumentNumber          int    // Or string?
	DocumentName            string `gorm:"type:varchar(32)"`
	DocumentDescription     string `gorm:"type:varchar(32)"`
	DocumentFullDescription string
	DocumentFilename        string `gorm:"type:varchar(253);not null"`
	DocumentExt             string `gorm:"type:varchar(253);not null"`

	UserID uint    `gorm:"foreignKey:UserID"`
	User   PdmUser `gorm:"foreignKey:UserID"`
	ItemID uint    `gorm:"foreignKey:ItemID"`
	Item   PdmItem `gorm:"foreignKey:ItemID"`
}

PdmDocument represents the documents table

type PdmHistory

type PdmHistory struct {
	Base
	HistoryDateCreated    *time.Time
	HistoryCreatedBy      string
	HistoryDateLastEdit   *time.Time
	HistoryLastEditBy     string
	HistoryCheckedOutBy   string
	HistoryRevisionState  string // Enum can be defined later
	HistoryRevisionNumber int
	HistoryStoredNumber   int
}

PdmHistory represents the history table

type PdmItem

type PdmItem struct {
	Base
	ItemNumber            string `gorm:"type:varchar(16)"`
	ItemName              string `gorm:"type:varchar(32)"`
	ItemDescription       string `gorm:"type:varchar(32)"`
	ItemFullDescription   string
	ItemNumberLinkedFiles int
	ItemPath              string `gorm:"not null"`
	ItemPreview           []byte // For LargeBinary

	UserID    uint          `gorm:"foreignKey:UserID"`
	User      PdmUser       `gorm:"foreignKey:UserID"`
	ProjectID uint          `gorm:"foreignKey:ProjectID"`
	Models    []PdmModel    `gorm:"foreignKey:ItemID"`
	Documents []PdmDocument `gorm:"foreignKey:ItemID"`
}

PdmItem represents the items table

type PdmManufacturer

type PdmManufacturer struct {
	Base
	ManufacturerName string      `gorm:"type:varchar(32)"`
	PurchasingID     uint        `gorm:"foreignKey:PurchasingID"`
	Purchasing       PdmPurchase `gorm:"foreignKey:PurchasingID"`
}

PdmManufacturer represents the manufacturers table

type PdmMaterial

type PdmMaterial struct {
	Base
	MaterialName            string `gorm:"type:varchar(32)"`
	MaterialFinish          string `gorm:"type:varchar(32)"`
	MaterialDensity         float64
	MaterialDensityUnit     string // Enum can be defined later
	MaterialVolume          float64
	MaterialVolumeUnit      string // Enum can be defined later
	MaterialWeight          float64
	MaterialWeightUnit      string // Enum can be defined later
	MaterialSurfaceArea     float64
	MaterialSurfaceAreaUnit string // Enum can be defined later

	// ModelID uint     `gorm:"foreignKey:ModelID"`
	// Model   PdmModel `gorm:"foreignKey:ModelID"`
	ItemID uint    `gorm:"foreignKey:ItemID"`
	Item   PdmItem `gorm:"foreignKey:ItemID"`
}

PdmMaterial represents the materials table

type PdmModel

type PdmModel struct {
	Base
	ModelNumber          int    // Or string?
	ModelName            string `gorm:"type:varchar(32)"`
	ModelDescription     string `gorm:"type:varchar(32)"`
	ModelFullDescription string
	ModelFilename        string `gorm:"type:varchar(253);not null"`
	ModelExt             string `gorm:"type:varchar(253);not null"`
	ModelPreview         []byte // For LargeBinary

	UserID   uint        `gorm:"foreignKey:UserID"`
	User     PdmUser     `gorm:"foreignKey:UserID"`
	ItemID   uint        `gorm:"foreignKey:ItemID"`
	Item     PdmItem     `gorm:"foreignKey:ItemID"`
	Material PdmMaterial `gorm:"foreignKey:ModelID"`
}

PdmModel represents the models table

type PdmProject

type PdmProject struct {
	Base
	ProjectNumber     string `gorm:"type:varchar(16);not null"`
	ProjectName       string `gorm:"type:varchar(32)"`
	ProjectStatus     string // Enum type can be defined later
	ProjectDateStart  *time.Time
	ProjectDateFinish *time.Time
	ProjectPath       string

	Users []*PdmUser `gorm:"many2many:user_project_link"`
}

PdmProject represents the projects table

type PdmProjectItemLink struct {
	ProjectID uint `gorm:"primaryKey;autoIncrement:false"`
	ItemID    uint `gorm:"primaryKey;autoIncrement:false"`
}

PdmProjectItemLink is the association table for projects and items

type PdmPurchase

type PdmPurchase struct {
	Base
	PurchasingSource       bool
	PurchasingTraceability string // Enum can be defined later

	ItemID         uint              `gorm:"foreignKey:ItemID"`
	Item           PdmItem           `gorm:"foreignKey:ItemID"`
	ManufacturerID uint              `gorm:"foreignKey:ManufacturerID"`
	Manufacturers  []PdmManufacturer `gorm:"foreignKey:ManufacturerID"`
	VendorID       uint              `gorm:"foreignKey:VendorID"`
	Vendors        []PdmVendor       `gorm:"foreignKey:VendorID"`
}

PdmPurchase represents the purchasing table

type PdmRole

type PdmRole struct {
	Base
	RoleName string `gorm:"type:varchar(32)"`

	Users []*PdmUser `gorm:"many2many:user_role_link"`
}

PdmRole represents the roles table

type PdmUser

type PdmUser struct {
	Base
	UserName         string `gorm:"type:varchar(30)"`
	UserFirstName    string `gorm:"type:varchar(30)"`
	UserLastName     string `gorm:"type:varchar(30)"`
	UserFullName     string
	UserEmailAddress string `gorm:"not null"`
	UserPhoneNumber  int    // Consider changing to string if phone numbers include characters
	UserDepartment   string // Enum type can be defined later

	Roles     []*PdmRole    `gorm:"many2many:user_role_link"`
	Projects  []*PdmProject `gorm:"many2many:user_project_link"`
	Items     []PdmItem     `gorm:"foreignKey:UserID"`
	Models    []PdmModel    `gorm:"foreignKey:UserID"`
	Documents []PdmDocument `gorm:"foreignKey:UserID"`
}

PdmUser represents the users table

type PdmUserProjectLink struct {
	UserID    uint `gorm:"primaryKey;autoIncrement:false"`
	ProjectID uint `gorm:"primaryKey;autoIncrement:false"`
}

PdmUserProjectLink is the association table for users and projects

type PdmUserRoleLink struct {
	UserID uint `gorm:"primaryKey;autoIncrement:false"`
	RoleID uint `gorm:"primaryKey;autoIncrement:false"`
}

PdmUserRoleLink is the association table for users and roles

type PdmVendor

type PdmVendor struct {
	Base
	VendorName    string      `gorm:"type:varchar(32)"`
	VPurchasingID uint        `gorm:"foreignKey:VPurchasingID"`
	VPurchasing   PdmPurchase `gorm:"foreignKey:VPurchasingID"`
}

PdmVendor represents the vendors table

type Permission

type Permission int
const (
	General Permission = iota
	CadUser
	SuperUser
	ProjectLeader
	Admin
)

type Project

type Project struct {
	gorm.Model
	ID          uint   `gorm:"primaryKey"`
	ProjectName string `gorm:"size:100"`
	// contains filtered or unexported fields
}

Project represents the projects table.

func NewProject

func NewProject(number string, name string, status *string, path string) (*Project, error)

Create new project

func (*Project) AddUserToProject

func (p *Project) AddUserToProject()

Add user to project

func (Project) GetId

func (p Project) GetId(number string) int

Get id with Project number

func (*Project) RemovePproject

func (p *Project) RemovePproject()

Remove existing project

func (*Project) RemoveUserFromProject

func (p *Project) RemoveUserFromProject()

Remove user from project

func (*Project) UpdateProject

func (p *Project) UpdateProject()

Update existing project

type ProjectState

type ProjectState string

type ReleaseStates

type ReleaseStates struct {
}

Item / Model /Document release states struct

func (ReleaseStates) ChangeReleaseState

func (r ReleaseStates) ChangeReleaseState()

new Item, Model, Document

func (ReleaseStates) Depreciated

func (r ReleaseStates) Depreciated()

Check in Items, Models, Documents

func (ReleaseStates) New

func (r ReleaseStates) New()

New Item, Model, Document

func (ReleaseStates) NotForNew

func (r ReleaseStates) NotForNew()

Check in Items, Models, Documents

func (ReleaseStates) Prototype

func (r ReleaseStates) Prototype()

Prototype Item, Model, Document

func (ReleaseStates) Release

func (r ReleaseStates) Release()

Check in Items, Models, Documents

type RevisionState

type RevisionState string

type Role

type Role struct {
}

for generating Roles

func (Role) AddRole

func (r Role) AddRole()

Create new role

func (Role) RemoveRole

func (r Role) RemoveRole()

Delete existing role

type Search struct {
}

Search https://docs.sqlalchemy.org/en/14/orm/session_basics.html

func (Search) SearchDescription

func (s Search) SearchDescription(description string)

Search on description

func (Search) SearchHelp

func (s Search) SearchHelp() string

help function

func (Search) SearchNumber

func (s Search) SearchNumber(number int)

Search on number

func (Search) SearchSomething_else

func (s Search) SearchSomething_else(something string)

Search on something else

type SearchItem

type SearchItem struct {
}

Search for projects

type SearchProject

type SearchProject struct {
}

Search for projects

type SearchUser

type SearchUser struct {
}

Search for projects

type TempRole

type TempRole struct {
}

struct for generating Roles

func (TempRole) AddRole

func (t TempRole) AddRole()

Create new Role

func (TempRole) RemoveRole

func (t TempRole) RemoveRole()

Delete existing role

type TempUser

type TempUser struct {
}

Struct for generating users Users are Aliases for roles in SQL see: https://www.postgresql.org/docs/14/sql-createuser.html

func (TempUser) AddUserToLdap

func (t TempUser) AddUserToLdap(username string)

func (TempUser) AddUserToSql

func (t TempUser) AddUserToSql(username string)

func (TempUser) RemoveUserFromLdap

func (t TempUser) RemoveUserFromLdap(user_id int, username string)

Delete existing user

func (TempUser) RemoveUserFromSql

func (t TempUser) RemoveUserFromSql(user_id int, username string)

Delete existing user

type TracebilityState

type TracebilityState string

type User

type User struct {
}

for generating users Users are Aliases for roles in SQL see: https://www.postgresql.org/docs/14/sql-createuser.html

func (User) AddUserToLdap

func (r User) AddUserToLdap(username string)

func (User) AddUserToSql

func (r User) AddUserToSql(username string)

func (User) RemoveUserFromLdap

func (r User) RemoveUserFromLdap(user_id int, username string)

Delete existing user

func (User) RemoveUserFromSql

func (r User) RemoveUserFromSql(user_id int, username string)

Delete existing user

type UserAccount

type UserAccount struct {
	ID   uint   `gorm:"primaryKey"`
	Name string `gorm:"size:100"`
}

UserAccount represents the user_accounts table.

type UserRole

type UserRole struct {
	ID       uint   `gorm:"primaryKey"`
	RoleName string `gorm:"size:100"`
}

UserRole represents the user_roles table.

type VolumeUnit

type VolumeUnit string

type WeightUnit

type WeightUnit string

Jump to

Keyboard shortcuts

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