database

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// == Table Names ==
	// NETWORKS_TABLE_NAME - networks table
	NETWORKS_TABLE_NAME = "networks"
	// NODES_TABLE_NAME - nodes table
	NODES_TABLE_NAME = "nodes"
	// DELETED_NODES_TABLE_NAME - deleted nodes table
	DELETED_NODES_TABLE_NAME = "deletednodes"
	// USERS_TABLE_NAME - users table
	USERS_TABLE_NAME = "users"
	// CERTS_TABLE_NAME - certificates table
	CERTS_TABLE_NAME = "certs"
	// DNS_TABLE_NAME - dns table
	DNS_TABLE_NAME = "dns"
	// EXT_CLIENT_TABLE_NAME - ext client table
	EXT_CLIENT_TABLE_NAME = "extclients"
	// PEERS_TABLE_NAME - peers table
	PEERS_TABLE_NAME = "peers"
	// SERVERCONF_TABLE_NAME - stores server conf
	SERVERCONF_TABLE_NAME = "serverconf"
	// SERVER_UUID_TABLE_NAME - stores unique netmaker server data
	SERVER_UUID_TABLE_NAME = "serveruuid"
	// SERVER_UUID_RECORD_KEY - telemetry thing
	SERVER_UUID_RECORD_KEY = "serveruuid"
	// DATABASE_FILENAME - database file name
	DATABASE_FILENAME = "netmaker.db"
	// GENERATED_TABLE_NAME - stores server generated k/v
	GENERATED_TABLE_NAME = "generated"
	// NODE_ACLS_TABLE_NAME - stores the node ACL rules
	NODE_ACLS_TABLE_NAME = "nodeacls"
	// SSO_STATE_CACHE - holds sso session information for OAuth2 sign-ins
	SSO_STATE_CACHE = "ssostatecache"
	// METRICS_TABLE_NAME - stores network metrics
	METRICS_TABLE_NAME = "metrics"
	// NETWORK_USER_TABLE_NAME - network user table tracks stats for a network user per network
	NETWORK_USER_TABLE_NAME = "networkusers"
	// USER_GROUPS_TABLE_NAME - table for storing usergroups
	USER_GROUPS_TABLE_NAME = "usergroups"
	// CACHE_TABLE_NAME - caching table
	CACHE_TABLE_NAME = "cache"
	// HOSTS_TABLE_NAME - the table name for hosts
	HOSTS_TABLE_NAME = "hosts"
	// ENROLLMENT_KEYS_TABLE_NAME - table name for enrollmentkeys
	ENROLLMENT_KEYS_TABLE_NAME = "enrollmentkeys"
	// HOST_ACTIONS_TABLE_NAME - table name for enrollmentkeys
	HOST_ACTIONS_TABLE_NAME = "hostactions"
	// PENDING_USERS_TABLE_NAME - table name for pending users
	PENDING_USERS_TABLE_NAME = "pending_users"
	// == ERROR CONSTS ==
	// NO_RECORD - no singular result found
	NO_RECORD = "no result found"
	// NO_RECORDS - no results found
	NO_RECORDS = "could not find any records"

	// == DB Constants ==
	// INIT_DB - initialize db
	INIT_DB = "init"
	// CREATE_TABLE - create table const
	CREATE_TABLE = "createtable"
	// INSERT - insert into db const
	INSERT = "insert"
	// INSERT_PEER - insert peer into db const
	INSERT_PEER = "insertpeer"
	// DELETE - delete db record const
	DELETE = "delete"
	// DELETE_ALL - delete a table const
	DELETE_ALL = "deleteall"
	// FETCH_ALL - fetch table contents const
	FETCH_ALL = "fetchall"
	// CLOSE_DB - graceful close of db const
	CLOSE_DB = "closedb"
)

Variables

View Source
var PGDB *sql.DB

PGDB - database object for PostGreSQL

View Source
var PG_FUNCTIONS = map[string]interface{}{
	INIT_DB:      initPGDB,
	CREATE_TABLE: pgCreateTable,
	INSERT:       pgInsert,
	INSERT_PEER:  pgInsertPeer,
	DELETE:       pgDeleteRecord,
	DELETE_ALL:   pgDeleteAllRecords,
	FETCH_ALL:    pgFetchRecords,
	CLOSE_DB:     pgCloseDB,
	// contains filtered or unexported fields
}

PG_FUNCTIONS - map of db functions for PostGreSQL

View Source
var RQLITE_FUNCTIONS = map[string]interface{}{
	INIT_DB:      initRqliteDatabase,
	CREATE_TABLE: rqliteCreateTable,
	INSERT:       rqliteInsert,
	INSERT_PEER:  rqliteInsertPeer,
	DELETE:       rqliteDeleteRecord,
	DELETE_ALL:   rqliteDeleteAllRecords,
	FETCH_ALL:    rqliteFetchRecords,
	CLOSE_DB:     rqliteCloseDB,
	// contains filtered or unexported fields
}

RQLITE_FUNCTIONS - all the functions to run with rqlite

View Source
var RQliteDatabase gorqlite.Connection

RQliteDatabase - the rqlite db connection

View Source
var SQLITE_FUNCTIONS = map[string]interface{}{
	INIT_DB:      initSqliteDB,
	CREATE_TABLE: sqliteCreateTable,
	INSERT:       sqliteInsert,
	INSERT_PEER:  sqliteInsertPeer,
	DELETE:       sqliteDeleteRecord,
	DELETE_ALL:   sqliteDeleteAllRecords,
	FETCH_ALL:    sqliteFetchRecords,
	CLOSE_DB:     sqliteCloseDB,
	// contains filtered or unexported fields
}

SQLITE_FUNCTIONS - contains a map of the functions for sqlite

View Source
var SqliteDB *sql.DB

SqliteDB is the db object for sqlite database connections

Functions

func CloseDB

func CloseDB()

CloseDB - closes a database gracefully

func CreateTable added in v0.23.0

func CreateTable(tableName string) error

func DeleteAllRecords

func DeleteAllRecords(tableName string) error

DeleteAllRecords - removes a table and remakes

func DeleteRecord

func DeleteRecord(tableName string, key string) error

DeleteRecord - deletes a record from db

func FetchRecord

func FetchRecord(tableName string, key string) (string, error)

FetchRecord - fetches a record

func FetchRecords

func FetchRecords(tableName string) (map[string]string, error)

FetchRecords - fetches all records in given table

func GetPeers

func GetPeers(networkName string) (map[string]string, error)

GetPeers - gets peers for a given network

func InitializeDatabase

func InitializeDatabase() error

InitializeDatabase - initializes database

func Insert

func Insert(key string, value string, tableName string) error

Insert - inserts object into db

func InsertPeer

func InsertPeer(key string, value string) error

InsertPeer - inserts peer into db

func IsConnected

func IsConnected() bool

IsConnected - tell if the database is connected or not

func IsEmptyRecord

func IsEmptyRecord(err error) bool

IsEmptyRecord - checks for if it's an empty record error or not

func IsJSONString

func IsJSONString(value string) bool

IsJSONString - checks if valid json

func PeersAreEqual

func PeersAreEqual(toCompare map[string]string, networkName string) bool

PeersAreEqual - checks if peers are the same

func SetPeers

func SetPeers(newPeers map[string]string, networkName string) bool

SetPeers - sets peers for a network

Types

This section is empty.

Jump to

Keyboard shortcuts

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