database

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver   string
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
	Path     string // For SQLite
}

Config holds database configuration

func NewConfig

func NewConfig() *Config

NewConfig creates a new database configuration from environment variables

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB represents the database connection

func InitDB

func InitDB(dbPath string) (*DB, error)

InitDB initializes the database connection and performs migrations

func InitDBWithConfig

func InitDBWithConfig(config *Config) (*DB, error)

InitDBWithConfig initializes the database with the provided configuration

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) CreateService

func (db *DB) CreateService(service *models.ServiceConfiguration) error

CreateService creates a new service configuration

func (*DB) CreateUser

func (db *DB) CreateUser(user *types.User) error

CreateUser creates a new user in the database

func (*DB) DeleteService

func (db *DB) DeleteService(instanceID string) error

DeleteService deletes a service configuration by its instance ID

func (*DB) GetAllServices

func (db *DB) GetAllServices() ([]models.ServiceConfiguration, error)

GetAllServices retrieves all service configurations

func (*DB) GetServiceByInstanceID

func (db *DB) GetServiceByInstanceID(instanceID string) (*models.ServiceConfiguration, error)

GetServiceByInstanceID retrieves a service configuration by its instance ID

func (*DB) GetServiceByInstancePrefix

func (db *DB) GetServiceByInstancePrefix(prefix string) (*models.ServiceConfiguration, error)

GetServiceByInstancePrefix retrieves a service configuration by its instance ID prefix

func (*DB) GetServiceByURL

func (db *DB) GetServiceByURL(url string) (*models.ServiceConfiguration, error)

GetServiceByURL retrieves a service configuration by its URL

func (*DB) GetUserByEmail

func (db *DB) GetUserByEmail(email string) (*types.User, error)

GetUserByEmail retrieves a user by their email

func (*DB) GetUserByID

func (db *DB) GetUserByID(id int64) (*types.User, error)

GetUserByID retrieves a user by their ID

func (*DB) GetUserByUsername

func (db *DB) GetUserByUsername(username string) (*types.User, error)

GetUserByUsername retrieves a user by their username

func (*DB) HasUsers

func (db *DB) HasUsers() (bool, error)

HasUsers checks if any users exist in the database

func (*DB) Path added in v0.2.0

func (db *DB) Path() string

Path returns the database file path (for SQLite)

func (*DB) UpdateService

func (db *DB) UpdateService(service *models.ServiceConfiguration) error

UpdateService updates an existing service configuration

func (*DB) UpdateUserPassword

func (db *DB) UpdateUserPassword(userID int64, newPasswordHash string) error

UpdateUserPassword updates a user's password hash and updated_at timestamp

Jump to

Keyboard shortcuts

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