model

package module
v0.0.0-...-7d97bcb Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 8 Imported by: 0

README

What

It is a poor man ORM :). It makes use of the simple sqlstruct to save typing column name

Support golang idiomatic OOP or sort of.

Should be very fast as it does not put any heavy layer on top of standard sql driver. The sqlstruct uses a little of refect package but they are all lightweight.

Usage

  • One table, one file, one struct
  • Copy the existing file to new one and
  • Edit search/replace

Pay attention to the Update function you have to change the switch/case to match the real table column name.

The file should be short enough for easy to read/modify and adapt.

Why not use sqlx ?

I don't know how to get column list in sqlx. I need it for the update and save typing the update stmt. Anyway it is less flexible and it enforce a new way to do things rather than sql standard.

Also sqlx is a bit more heavyweight (but not much really)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GitLabToken, SearchStr, ConfigFile, Logdbpath string
	AppConfig                                     map[string]interface{} = map[string]interface{}{}
)

Functions

func GetContainerRegistryBaseLocation

func GetContainerRegistryBaseLocation(git *gitlab.Client, gitlabProjectId int) string

func GetDBConn

func GetDBConn() *sql.DB

GetDBConn -

func GitlabNamespaceDeleteOne

func GitlabNamespaceDeleteOne(gID int)

func GroupmemberDeleteOne

func GroupmemberDeleteOne(gID int)

func SetUpLogDatabase

func SetUpLogDatabase()

Types

type Domain

type Domain struct {
	ID                int    `sql:"id"`
	Name              string `sql:"name"`
	Keyword           string `sql:"keyword"`
	Note              string `sql:"note"`
	GitlabNamespaceId int    `sql:"gitlab_ns_id"`
	CreatedAt         string `sql:"created_at"`
	HasTeam           int    `sql:"has_team"`
	TS                string `sql:"ts"`
}

func DomainGet

func DomainGet(inputmap map[string]string) []Domain

func DomainNew

func DomainNew(name string) Domain

func (*Domain) Delete

func (p *Domain) Delete(inputmap map[string]string)

func (*Domain) GetOne

func (p *Domain) GetOne(inputmap map[string]string)

func (*Domain) New

func (p *Domain) New(domainname string, update bool)

func (*Domain) Update

func (p *Domain) Update()

type EventLog

type EventLog struct {
	ID          int    `sql:"id"`
	Host        string `sql:"host"`
	Application string `sql:"application"`
	Message     string `sql:"message"`
	Logfile     string `sql:"logfile"`
	TS          string `sql:"ts"`
}

func EventLogGet

func EventLogGet(inputmap map[string]string) []EventLog

func EventLogNew

func EventLogNew(message string) EventLog

func (*EventLog) Delete

func (p *EventLog) Delete(inputmap map[string]string)

func (*EventLog) GetOne

func (p *EventLog) GetOne(inputmap map[string]string)

func (*EventLog) New

func (p *EventLog) New(message string, update bool)

func (*EventLog) Update

func (p *EventLog) Update()

type GitlabNamespace

type GitlabNamespace struct {
	ID                          int    `sql:"id"`
	Name                        string `sql:"name"`
	ParentId                    int    `sql:"parent_id"`
	Path                        string `sql:"path"`
	Kind                        string `sql:"kind"`
	FullPath                    string `sql:"full_path"`
	MembersCountWithDescendants int    `sql:"members_count_with_descendants"`
	GitlabNamespaceId           int    `sql:"gitlab_ns_id"`
	DomainOwnershipConfirmed    int8   `sql:"domain_ownership_confirmed"`
	WebUrl                      string `sql:"web_url"`
	AvatarUrl                   string `sql:"avatar_url"`
	BillableMembersCount        int    `sql:"billable_members_count"`
	Seats_in_use                int    `sql:"seats_in_use"`
	Max_seats_used              int    `sql:"max_seats_used"`
	Plan                        string `sql:"plan"`
	Trial_ends_on               string `sql:"trial_ends_on"`
	Trial                       int    `sql:"trial"`
	Labels                      string `sql:"labels"`
	TS                          string `sql:"ts"`
}

func GitlabNamespaceGet

func GitlabNamespaceGet(inputmap map[string]string) []GitlabNamespace

func GitlabNamespaceNew

func GitlabNamespaceNew(full_path string) GitlabNamespace

func (*GitlabNamespace) Delete

func (p *GitlabNamespace) Delete(inputmap map[string]string)

func (*GitlabNamespace) GetOne

func (p *GitlabNamespace) GetOne(inputmap map[string]string)

func (*GitlabNamespace) New

func (p *GitlabNamespace) New(full_path string, update bool)

func (*GitlabNamespace) Update

func (p *GitlabNamespace) Update()

type Groupmember

type Groupmember struct {
	ID            int    `sql:"id"`
	GroupId       int    `sql:"group_id"`
	MemberGroupId int    `sql:"member_group_id"`
	TS            string `sql:"ts"`
}

func GroupmemberGet

func GroupmemberGet(inputmap map[string]string) []Groupmember

func GroupmemberNew

func GroupmemberNew(group_id, member_group_id int) Groupmember

func (*Groupmember) Delete

func (p *Groupmember) Delete(inputmap map[string]string)

func (*Groupmember) GetOne

func (p *Groupmember) GetOne(inputmap map[string]string)

func (*Groupmember) New

func (p *Groupmember) New(group_id, member_group_id int, update bool)

func (*Groupmember) Update

func (p *Groupmember) Update()

type Project

type Project struct {
	ID                       int    `sql:"id"`
	Pid                      int    `sql:"pid"`
	Weburl                   string `sql:"weburl"`
	OwnerId                  int    `sql:"owner_id"`
	OwnerName                string `sql:"owner_name"`
	Name                     string `sql:"name"`
	NameWithSpace            string `sql:"name_with_space"`
	Path                     string `sql:"path"`
	PathWithNamespace        string `sql:"path_with_namespace"`
	NamespaceKind            string `sql:"namespace_kind"`
	NamespaceName            string `sql:"namespace_name"`
	NamespaceId              int    `sql:"namespace_id"`
	TagList                  string `sql:"tag_list"`
	GitlabCreatedAt          string `sql:"gitlab_created_at"`
	IsActive                 int8   `sql:"is_active"`
	DomainOwnershipConfirmed int8   `sql:"domain_ownership_confirmed"`
	Labels                   string `sql:"labels"`
	TS                       string `sql:"ts"`
	//Non sql field
	NewDomainName string `sql:"-"`
	RootNameSpace string `sql:"-"`
}

func ProjectGet

func ProjectGet(inputmap map[string]string) []Project

func ProjectNew

func ProjectNew(path_with_namespace string) Project

func (*Project) Delete

func (p *Project) Delete(inputmap map[string]string)

func (*Project) GetDomainList

func (p *Project) GetDomainList(git *gitlab.Client) []*gitlab.Group

func (*Project) GetOne

func (p *Project) GetOne(inputmap map[string]string)

func (*Project) New

func (p *Project) New(path_with_namespace string, update bool)

func (*Project) Update

func (p *Project) Update()

func (*Project) UpdateNonSQLFields

func (p *Project) UpdateNonSQLFields()

Non standard function for the model, specific to project

type ProjectDomain

type ProjectDomain struct {
	ID        int    `sql:"id"`
	ProjectId int    `sql:"project_id"`
	DomainId  int    `sql:"domain_id"`
	TS        string `sql:"ts"`
}

func ProjectDomainGet

func ProjectDomainGet(inputmap map[string]string) []ProjectDomain

func ProjectDomainNew

func ProjectDomainNew(project_id, domain_id int) ProjectDomain

func (*ProjectDomain) Delete

func (p *ProjectDomain) Delete(inputmap map[string]string)

func (*ProjectDomain) GetOne

func (p *ProjectDomain) GetOne(inputmap map[string]int)

func (*ProjectDomain) New

func (p *ProjectDomain) New(project_id, domain_id int, update bool)

func (*ProjectDomain) Update

func (p *ProjectDomain) Update()

type Team

type Team struct {
	ID                int    `sql:"id"`
	Name              string `sql:"name"`
	Keyword           string `sql:"keyword"`
	Note              string `sql:"note"`
	GitlabNamespaceId int    `sql:"gitlab_ns_id"`
	CreatedAt         string `sql:"created_at"`
	TS                string `sql:"ts"`
}

func TeamGet

func TeamGet(inputmap map[string]string) []Team

func TeamNew

func TeamNew(name string) Team

func (*Team) Delete

func (p *Team) Delete(inputmap map[string]string)

func (*Team) GetOne

func (p *Team) GetOne(inputmap map[string]string)

func (*Team) New

func (p *Team) New(teamname string, update bool)

func (*Team) Update

func (p *Team) Update()

type TeamDomain

type TeamDomain struct {
	ID         int    `sql:"id"`
	TeamId     int    `sql:"team_id"`
	DomainId   int    `sql:"domain_id"`
	Permission string `sql:"permission"`
	TS         string `sql:"ts"`
}

func TeamDomainGet

func TeamDomainGet(inputmap map[string]string) []TeamDomain

func TeamDomainNew

func TeamDomainNew(team_id, domain_id int) TeamDomain

func (*TeamDomain) Delete

func (p *TeamDomain) Delete(inputmap map[string]string)

func (*TeamDomain) GetOne

func (p *TeamDomain) GetOne(inputmap map[string]int)

func (*TeamDomain) New

func (p *TeamDomain) New(team_id, domain_id int, update bool)

func (*TeamDomain) Update

func (p *TeamDomain) Update()

type TeamProject

type TeamProject struct {
	ID         int    `sql:"id"`
	TeamId     int    `sql:"team_id"`
	ProjectId  int    `sql:"project_id"`
	Domain     string `sql:"domain"`
	Permission string `sql:"permission"`
	TS         string `sql:"ts"`
}

func TeamProjectGet

func TeamProjectGet(inputmap map[string]string) []TeamProject

func TeamProjectNew

func TeamProjectNew(team_id, project_id int) TeamProject

func (*TeamProject) Delete

func (p *TeamProject) Delete(inputmap map[string]string)

func (*TeamProject) GetOne

func (p *TeamProject) GetOne(inputmap map[string]int)

func (*TeamProject) New

func (p *TeamProject) New(team_id, project_id int, update bool)

func (*TeamProject) Update

func (p *TeamProject) Update()

type TeamUser

type TeamUser struct {
	ID             int    `sql:"id"`
	TS             string `sql:"ts"`
	TeamId         int    `sql:"team_id"`
	UserId         int    `sql:"user_id"`
	Max_role       string `sql:"max_role"`
	Access_expires string `sql:"access_expires"`
	Source         string `sql:"source"`
	Expiration     string `sql:"expiration"`
	Access_granted string `sql:"access_granted"`
}

func TeamUserGet

func TeamUserGet(inputmap map[string]string) []TeamUser

func TeamUserNew

func TeamUserNew(team_id, user_id int) TeamUser

func (*TeamUser) Delete

func (p *TeamUser) Delete(inputmap map[string]string)

func (*TeamUser) GetOne

func (p *TeamUser) GetOne(inputmap map[string]int)

func (*TeamUser) New

func (p *TeamUser) New(team_id, user_id int, update bool)

func (*TeamUser) Update

func (p *TeamUser) Update()

type User

type User struct {
	ID                                 int    `sql:"id"`
	TS                                 string `sql:"ts"`
	GitlabNsID                         int    `sql:"gitlab_ns_id"`
	GitlabUserId                       int    `sql:"gitlab_user_id"`
	GitlabUserName                     string `sql:"username"`
	Email                              string `sql:"email"`
	Name                               string `sql:"name"`
	State                              int    `sql:"state"`
	WebUrl                             string `sql:"web_url"`
	CreatedAt                          string `sql:"created_at"`
	Bio                                string `sql:"bio"`
	Location                           string `sql:"location"`
	PublicEmail                        string `sql:"public_email"`
	Skype                              string `sql:"skype"`
	Linkedin                           string `sql:"linkedin"`
	Twitter                            string `sql:"twitter"`
	Website_url                        string `sql:"website_url"`
	Organization                       string `sql:"organization"`
	Extern_uid                         string `sql:"extern_uid"`
	Provider                           string `sql:"provider"`
	Theme_id                           int    `sql:"theme_id"`
	Last_activity_on                   string `sql:"last_activity_on"`
	Color_scheme_id                    int    `Sql:"Color_scheme_id"`
	Is_admin                           int    `sql:"is_admin"`
	Avatar_url                         string `sql:"avatar_url"`
	Can_create_group                   int    `sql:"can_create_group"`
	Can_create_project                 int    `sql:"can_create_project"`
	Projects_limit                     int    `sql:"projects_limit"`
	Current_sign_in_at                 string `sql:"current_sign_in_at"`
	Last_sign_in_at                    string `sql:"last_sign_in_at"`
	Confirmed_at                       string `sql:"confirmed_at"`
	Two_factor_enabled                 int    `sql:"two_factor_enabled"`
	Note                               string `sql:"note"`
	Identities                         string `sql:"identities"`
	External                           int    `sql:"external"`
	Private_profile                    int    `sql:"private_profile"`
	Shared_runners_minutes_limit       int    `sql:"shared_runners_minutes_limit"`
	Extra_shared_runners_minutes_limit int    `sql:"extra_shared_runners_minutes_limit"`
	Using_license_seat                 int    `sql:"using_license_seat"`
	Custom_attributes                  string `sql:"custom_attributes"`
}

func UserGet

func UserGet(inputmap map[string]string) []User

func UserNew

func UserNew(email string) User

func (*User) Delete

func (p *User) Delete(inputmap map[string]string)

func (*User) GetOne

func (p *User) GetOne(inputmap map[string]string)

func (*User) New

func (p *User) New(email string, update bool)

func (*User) Update

func (p *User) Update()

Jump to

Keyboard shortcuts

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