model

package
v0.0.0-...-f12796d Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package model is where we keep our database tables representations as structures.

Index

Constants

This section is empty.

Variables

DSN must be set before using DB() function.

View Source
var Logger *log.Logger

Logger must be instantiated before using any function from this package.

Functions

func DB

func DB() *sqlx.DB

func GetByID

func GetByID[T Record](r *T, id int32) error

func Record2Table

func Record2Table[T Record](record *T) string

Record2Table converts struct type name like *model.UsersInvoicesLastID to users_invoices_last_id and returns it. Caches the converted name for subsequent calls.

func SQLFor

func SQLFor(query, table string) string

SQLFor compooses an SQL query for the given key. Returns the composed query.

Types

type Aliases

type Aliases struct {
	ID         int32
	OldAlias   string
	NewAlias   string
	AliasID    string
	AliasTable string
}

type Box

type Box string
const (
	MainBox   Box = "main"
	LeftBox   Box = "left"
	RightBox  Box = "right"
	HeaderBox Box = "header"
	FooterBox Box = "footer"
)

type CelDataType

type CelDataType string

CelDataType represents the logical data type for a celina. Based on it we choose the appropriate template for displaying it. "default": "note", "enum":["title", "note", "writing", "book", "chapter", "question", "answer", "paragraph"]

const (
	Title     CelDataType = "title"
	Note      CelDataType = "note"
	Writing   CelDataType = "writing"
	Book      CelDataType = "book"
	Chapter   CelDataType = "chapter"
	Question  CelDataType = "question"
	Answer    CelDataType = "Answer"
	Paragraph             = "paragraph"
)

func (CelDataType) String

func (d CelDataType) String() string

type Celini

type Celini struct {
	ID          int32
	Alias       string
	Pid         int32
	FromID      int32
	PageID      int32
	UserID      int32
	GroupID     int32
	Sorting     int32
	DataType    CelDataType
	DataFormat  string
	CreatedAt   int32
	Tstamp      int32
	Title       string
	Description string
	Keywords    string
	Tags        string
	Body        string
	Box         Box
	Language    string
	Permissions string
	Featured    int32
	Accepted    int32
	Bad         bool
	Deleted     bool
	Start       int32
	Stop        int32
	ChangedBy   sql.NullString
	Published   uint8
}

func ListCelini

func ListCelini(args StraniciArgs) (items []Celini)

ListCelini returns a slice of celini which are children of the page with StraniciArgs.Alias. The celina used for title of the page in the respective language is `pid` for these celini.

func (*Celini) FindForDisplay

func (cel *Celini) FindForDisplay(args StraniciArgs) error

func (*Celini) TemplatePath

func (cel *Celini) TemplatePath(defaultTemplate string) string

type Domove

type Domove struct {
	ID          int32
	Domain      string
	SiteName    string
	Description string
	OwnerID     int32
	GroupID     int32
	Permissions string
	Published   int32
	Ips         string
	Aliases     string
	Templates   string
}

Domove is a record from table domove.

func (*Domove) GetByName

func (d *Domove) GetByName(domain string) error

type FirstLogin

type FirstLogin struct {
	ID        int32
	Token     string
	FromUID   int32
	ToUID     int32
	StartDate int32
	StopDate  int32
}

type Groups

type Groups struct {
	ID          int32
	Name        string
	Description string
	Disabled    int32
	CreatedBy   int32
	ChangedBy   int32
}

type Invoices

type Invoices struct {
	ID            int32
	UserInvoiceID int32
	UserID        int32
	OrderID       int32
	ChangedBy     int32
}

type Orders

type Orders struct {
	ID          int32
	Name        string
	Email       string
	Phone       string
	Deliverer   string
	DelivererID string
	CityName    string
	Poruchka    string
	WayBill     string
	CreatedAt   int32
	Tstamp      int32
	WayBillID   string
	Executed    int32
}

type PageType

type PageType string
const (
	Regular PageType = "regular"
	Root    PageType = "root"
)

type PasswLogin

type PasswLogin struct {
	ID        int32
	Token     string
	ToUID     int32
	StartDate int32
	StopDate  int32
}

type Products

type Products struct {
	ID         int32
	Sku        string
	Alias      string
	Title      string
	PType      string
	Properties string
}

type Record

Record is a generic constraint on the allowed types. Each type here is the record type in a table with the same name in lowercase. Note! these types *must* be named exactly after the tables, because we use them to guess the respective table name. Example: UsersInvoicesLastID === users_invoices_last_id

type SQLMap

type SQLMap map[string]any

SQLMap is a map of name/query. Each entry has a name and an SQL query used in some method.

type StrMenuItem

type StrMenuItem struct {
	ID          int32
	Pid         int32
	Alias       string
	Title       string
	Language    string
	Permissions string
}

StrMenuItem holds subset of the fields of a page and some fields from Celini for pdisplaying a link in the main menu. The query to populate this struct is SELECT_PAGES_FOR_MAIN_MENU.

func SelectMenuItems

func SelectMenuItems(args StraniciArgs) (items []StrMenuItem)

SelectMenuItems populates a []StrMenuItem slice and returns it or an error from DB().

func (*StrMenuItem) IsDir

func (s *StrMenuItem) IsDir() bool

IsDir returns true if the permissions field starts with `d`.

type Stranici

type Stranici struct {
	ID          int32
	Pid         int32
	DomID       int32
	Alias       string
	PageType    PageType
	Permissions string
	Sorting     int32
	Template    sql.NullString
	UserID      int32
	GroupID     int32
	Tstamp      int32
	Start       int32
	Stop        int32
	Published   uint8
	Hidden      bool
	Deleted     bool
	ChangedBy   string
	/*
		Here are fields from Celini. We may get them with some Get, when we
		select from both tables. When selecting only from stranici table, these
		will be empty. When selecting default content for a page these are
		populated from the celina with the same `alias` field as the page. This
		celina is created when the page is created and holds all the other
		celini in this page.
	*/
	Title       string
	Description string
	Keywords    string
	Tags        string
	Language    string
	Body        string
	DataType    string
	DataFormat  string
}

Stranici represents a Record in table stranici.

func ListStranici

func ListStranici(args StraniciArgs) (items []Stranici)

ListStranici returns a slice of pages which are children of the page with StraniciArgs.Alias.

func (*Stranici) FindForDisplay

func (s *Stranici) FindForDisplay(args StraniciArgs) (err error)

FindForDisplay returns a page from the database to be displayed. The page must have the given alias, readable by the given user, be in the given domain and published(=2). `args` is a struct containing the arguments for stmt.Get. It is put together in slovo.Binder.Bind().

func (*Stranici) IsDir

func (s *Stranici) IsDir() bool

IsDir returns true if the permissions field starts with `d`.

func (*Stranici) TemplatePath

func (s *Stranici) TemplatePath(defaultTemplate string) string

TemplatePath returns the path to the template file to be used for this page record or the given `defaultTemplate`.

type StraniciArgs

type StraniciArgs struct {
	// Alias for a page: "вѣра"
	Alias string `param:"stranica"`
	// Alias for an article/paragraph/book/product/content. Example: "чуждият-hôtel"
	Celina string `param:"celina"`
	// Box on the page where to be put  the body of a celina
	Box Box
	// Language for the content (for now only "bg")
	Lang string `param:"lang"`
	// Format of the content (for now only "html")
	Format string `param:"format"`
	// Required Published status (0:no|1:preview|2:yes) Default: 2
	Pub int
	// UserID - current user_id. Default 2(guest)
	// TODO: Implement authentication via some custom header or JWT - not Cookies
	UserID int32
	// Slovo is a multidomain CMS. Get it from c.Request().Host
	Domain string
	Now    int64
	Limit  int `query:"limit" form:"limit"`
	Offset int `query:"offset" form:"offset"`
}

StraniciArgs is a struct which we will populate by using the Echo binding mechanizm to pass these arguments to SQL queries and whereever needed. For binding these struct fields to values from different places, we use our custom [slovo.Binder].

type Table

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

Table is the base implementation for all tables in the database

type UserGroup

type UserGroup struct {
	UserID  int32
	GroupID int32
}

type Users

type Users struct {
	ID            int32
	LoginName     string
	LoginPassword string
	FirstName     string
	LastName      string
	Email         string
	Description   string
	Tstamp        int32
	RegTime       int32
	Disabled      int32
	StartDate     int32
	StopDate      int32
	GroupID       int32
	CreatedBy     int32
	ChangedBy     int32
}

type UsersInvoicesLastID

type UsersInvoicesLastID struct {
	UserID    int32
	InvoiceID int32
}

Jump to

Keyboard shortcuts

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