Help us shape the future of Go! Take the 2026 Go Developer Survey

db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 20 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 *slog.Logger) (*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"`

	// EncryptionKey, when set, enables transparent encryption-at-rest for
	// on-disk SQLite databases through the pure-Go adiantum VFS (available on
	// the default and wasm_sqlite builds). It is deliberately NOT serialized:
	// persisting the key next to the database it protects would defeat the
	// purpose. Applications supply it out-of-band (option, env, KMS, prompt).
	EncryptionKey string `json:"-"`
}

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 (an authenticated identity + its credentials). The teamserver stores no authorization/permission data: applications own their own role model, keyed by the user Name.

func (*User) BeforeCreate

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

BeforeCreate - GORM hook.

Jump to

Keyboard shortcuts

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