Documentation ¶
Overview ¶
Package model is where we keep our database tables representations as structures.
Index ¶
- Variables
- func DB() *sqlx.DB
- func GetByID[T Record](r *T, id int32) error
- func Record2Table[T Record](record *T) string
- func SQLFor(query, table string) string
- type Aliases
- type Box
- type CelDataType
- type Celini
- type Domove
- type FirstLogin
- type Groups
- type Invoices
- type Orders
- type PageType
- type PasswLogin
- type Products
- type Record
- type SQLMap
- type StrMenuItem
- type Stranici
- type StraniciArgs
- type Table
- type UserGroup
- type Users
- type UsersInvoicesLastID
Constants ¶
This section is empty.
Variables ¶
var DSN string
DSN must be set before using DB() function.
var Logger *log.Logger
Logger must be instantiated before using any function from this package.
Functions ¶
func Record2Table ¶
Record2Table converts struct type name like *model.UsersInvoicesLastID to users_invoices_last_id and returns it. Caches the converted name for subsequent calls.
Types ¶
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 ¶
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.
type FirstLogin ¶
type PasswLogin ¶
type Record ¶
type Record interface { Aliases | Celini | Domove | FirstLogin | Groups | Invoices | Orders | PasswLogin | Products | Stranici | UserGroup | Users | UsersInvoicesLastID }
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 ¶
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) TemplatePath ¶
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