db

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Sqlite - SQLite protocol.
	Sqlite = "sqlite3"
	// Postgres - Postgresql protocol.
	Postgres = "postgresql"
	// MySQL - MySQL protocol.
	MySQL = "mysql"
)
View Source
const (
	// SQLiteInMemoryHost is the default string used by SQLite
	// as a host when ran in memory (string value is ":memory:").
	SQLiteInMemoryHost = ":memory:"
)

Variables

View Source
var (
	// ErrRecordNotFound - Record not found error.
	ErrRecordNotFound = gorm.ErrRecordNotFound

	// ErrUnsupportedDialect - An invalid dialect was specified.
	ErrUnsupportedDialect = errors.New("Unknown/unsupported DB Dialect")
)

Functions

func NewClient

func NewClient(dbConfig *Config, dbLogger *logrus.Entry) (*gorm.DB, error)

NewClient initializes a database client connection to a backend specified in config.

func Schema

func Schema() []any

Schema returns all objects which should be registered to the teamserver database backend.

Types

type Certificate

type Certificate struct {
	ID             uuid.UUID `gorm:"primaryKey;->;<-:create;type:uuid;"`
	CreatedAt      time.Time `gorm:"->;<-:create;"`
	CommonName     string
	CAType         string
	KeyType        string
	CertificatePEM string
	PrivateKeyPEM  string
}

Certificate - Certificate database model.

func (*Certificate) BeforeCreate

func (c *Certificate) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate - GORM hook to automatically set values.

type Config

type Config struct {
	Dialect  string `json:"dialect"`
	Database string `json:"database"`
	Username string `json:"username"`
	Password string `json:"password"`
	Host     string `json:"host"`
	Port     uint16 `json:"port"`

	Params map[string]string `json:"params"`

	MaxIdleConns int `json:"max_idle_conns"`
	MaxOpenConns int `json:"max_open_conns"`

	LogLevel string `json:"log_level"`
}

Config - Server database configuration.

func (*Config) DSN

func (c *Config) DSN() (string, error)

DSN - Get the db connections string https://github.com/go-sql-driver/mysql#examples

type User

type User struct {
	ID        uuid.UUID `gorm:"primaryKey;->;<-:create;type:uuid;"`
	CreatedAt time.Time `gorm:"->;<-:create;"`
	LastSeen  time.Time
	Name      string
	Token     string `gorm:"uniqueIndex"`
}

User - A teamserver user.

func (*User) BeforeCreate

func (o *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate - GORM hook.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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