db

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package db provides a simplistic ORM to communicate with an SQL database for storage

Index

Constants

View Source
const (
	DefaultMcc           = "001"
	DefaultMnc           = "01"
	DefaultOperatorCode  = "0123456789ABCDEF0123456789ABCDEF"
	DefaultSupportedTACs = `["001"]`
	DefaultOperatorSst   = 1
	DefaultOperatorSd    = 1056816
)
View Source
const OperatorTableName = "operator"
View Source
const ProfilesTableName = "profiles"
View Source
const QueryCreateOperatorTable = `` /* 230-byte string literal not displayed */
View Source
const QueryCreateProfilesTable = `` /* 295-byte string literal not displayed */
View Source
const QueryCreateRadiosTable = `
	CREATE TABLE IF NOT EXISTS %s (
 		id INTEGER PRIMARY KEY AUTOINCREMENT,

		name TEXT NOT NULL
)`
View Source
const QueryCreateSubscribersTable = `` /* 287-byte string literal not displayed */
View Source
const QueryCreateUsersTable = `` /* 131-byte string literal not displayed */
View Source
const RadiosTableName = "radios"
View Source
const SubscribersTableName = "subscribers"
View Source
const UsersTableName = "users"

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database is the object used to communicate with the established repository.

func NewDatabase

func NewDatabase(databasePath string) (*Database, error)

NewDatabase connects to a given table in a given database, stores the connection information and returns an object containing the information. The database path must be a valid file path or ":memory:". The table will be created if it doesn't exist in the format expected by the package.

func (*Database) AllocateIP

func (db *Database) AllocateIP(imsi string) (net.IP, error)

func (*Database) Backup

func (db *Database) Backup() (string, error)

func (*Database) Close

func (db *Database) Close() error

Close closes the connection to the repository cleanly.

func (*Database) CreateProfile

func (db *Database) CreateProfile(profile *Profile) error

func (*Database) CreateRadio

func (db *Database) CreateRadio(radio *Radio) error

func (*Database) CreateSubscriber

func (db *Database) CreateSubscriber(subscriber *Subscriber) error

func (*Database) CreateUser

func (db *Database) CreateUser(user *User) error

func (*Database) DeleteProfile

func (db *Database) DeleteProfile(name string) error

func (*Database) DeleteRadio

func (db *Database) DeleteRadio(name string) error

func (*Database) DeleteSubscriber

func (db *Database) DeleteSubscriber(imsi string) error

func (*Database) DeleteUser

func (db *Database) DeleteUser(email string) error

func (*Database) GetIPAddressesAllocated

func (db *Database) GetIPAddressesAllocated() (int, error)

func (*Database) GetIPAddressesTotal

func (db *Database) GetIPAddressesTotal() (int, error)

func (*Database) GetOperator added in v0.0.5

func (db *Database) GetOperator() (*Operator, error)

func (*Database) GetOperatorCode

func (db *Database) GetOperatorCode() (string, error)

func (*Database) GetProfile

func (db *Database) GetProfile(name string) (*Profile, error)

func (*Database) GetProfileByID

func (db *Database) GetProfileByID(id int) (*Profile, error)

func (*Database) GetRadio

func (db *Database) GetRadio(name string) (*Radio, error)

func (*Database) GetSize

func (db *Database) GetSize() (int64, error)

func (*Database) GetSubscriber

func (db *Database) GetSubscriber(imsi string) (*Subscriber, error)

func (*Database) GetUser

func (db *Database) GetUser(email string) (*User, error)

func (*Database) InitializeOperator

func (db *Database) InitializeOperator() error

func (*Database) ListProfiles

func (db *Database) ListProfiles() ([]Profile, error)

func (*Database) ListRadios

func (db *Database) ListRadios() ([]Radio, error)

func (*Database) ListSubscribers

func (db *Database) ListSubscribers() ([]Subscriber, error)

ListSubscribers returns all of the subscribers and their fields available in the database.

func (*Database) ListUsers

func (db *Database) ListUsers() ([]User, error)

func (*Database) NumUsers

func (db *Database) NumUsers() (int, error)

func (*Database) ReleaseIP

func (db *Database) ReleaseIP(imsi string) error

func (*Database) Restore

func (db *Database) Restore(backupFilePath string) error

func (*Database) SubscribersInProfile added in v0.0.5

func (db *Database) SubscribersInProfile(name string) (bool, error)

func (*Database) UpdateOperator added in v0.0.5

func (db *Database) UpdateOperator(operator *Operator) error

func (*Database) UpdateOperatorCode

func (db *Database) UpdateOperatorCode(operatorCode string) error

func (*Database) UpdateProfile

func (db *Database) UpdateProfile(profile *Profile) error

func (*Database) UpdateSubscriber

func (db *Database) UpdateSubscriber(subscriber *Subscriber) error

func (*Database) UpdateUser

func (db *Database) UpdateUser(user *User) error

type NumUsers

type NumUsers struct {
	Count int `db:"count"`
}

type Operator

type Operator struct {
	ID            int    `db:"id"`
	Mcc           string `db:"mcc"`
	Mnc           string `db:"mnc"`
	OperatorCode  string `db:"operatorCode"`
	SupportedTACs string `db:"supportedTACs"` // JSON-encoded list of strings
	Sst           int32  `db:"sst"`
	Sd            int    `db:"sd"`
}

func (*Operator) GetHexSd added in v0.0.5

func (operator *Operator) GetHexSd() string

func (*Operator) GetSupportedTacs added in v0.0.5

func (operator *Operator) GetSupportedTacs() []string

func (*Operator) SetSupportedTacs added in v0.0.5

func (operator *Operator) SetSupportedTacs(supportedTACs []string)

type Profile

type Profile struct {
	ID              int    `db:"id"`
	Name            string `db:"name"`
	UeIpPool        string `db:"ueIpPool"`
	Dns             string `db:"dns"`
	Mtu             int32  `db:"mtu"`
	BitrateUplink   string `db:"bitrateUplink"`
	BitrateDownlink string `db:"bitrateDownlink"`
	Var5qi          int32  `db:"var5qi"`
	PriorityLevel   int32  `db:"priorityLevel"`
}

type Radio

type Radio struct {
	ID   int    `db:"id"`
	Name string `db:"name"`
}

type Subscriber

type Subscriber struct {
	ID             int    `db:"id"`
	Imsi           string `db:"imsi"`
	IpAddress      string `db:"ipAddress"`
	SequenceNumber string `db:"sequenceNumber"`
	PermanentKey   string `db:"permanentKey"`
	Opc            string `db:"opc"`
	ProfileID      int    `db:"profileID"`
}

type User

type User struct {
	ID             int    `db:"id"`
	Email          string `db:"email"`
	HashedPassword string `db:"hashedPassword"`
}

Jump to

Keyboard shortcuts

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