database

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 13 Imported by: 1

README

Sphire Mantis::Database

The Database package of Mantis provides helper functions for MySQL, Redis, and Neo4j.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aerospike added in v1.4.7

type Aerospike struct {
	Client          *aerospike.Client       `json:"-"`
	Hostname        string                  `json:"hostname,omitempty"`
	Port            int                     `json:"port,omitempty"`
	TLSName         string                  `json:"TLSName,omitempty"`
	Policy          *aerospike.ClientPolicy `json:"-"`
	GlobalNamespace string                  `json:"globalNamespace,omitempty"`
	GlobalSetName   string                  `json:"globalSetName,omitempty"`
}

Aerospike is our primary struct

func (*Aerospike) Connect added in v1.4.7

func (a *Aerospike) Connect() error

Connect to the database

func (*Aerospike) Default added in v1.4.7

func (a *Aerospike) Default(hostname string, port int) error

Default creates a default config based on given parameters

func (*Aerospike) Get added in v1.4.7

func (a *Aerospike) Get(key *aerospike.Key) (*aerospike.Record, error)

Get a key value pair from our Redis DB

func (*Aerospike) Set added in v1.4.7

func (a *Aerospike) Set(namespace, setName, key, bin, value string) error

Set a key value pair in our Redis DB

func (*Aerospike) String added in v1.4.7

func (a *Aerospike) String() string

String returns our Aerospike struct as a JSON string

type AerospikeError added in v1.4.7

type AerospikeError struct {
	Name  string
	Error error
}

AerospikeError provides a common struct for Aerospike Errors

type CypherQuery

type CypherQuery struct {
	Results    interface{}
	Statement  string
	Parameters neoism.Props
}

CypherQuery is our query struct

func (*CypherQuery) String

func (c *CypherQuery) String() string

String returns our query struct as a JSON string

type MySQL

type MySQL struct {
	LastQuery          string
	Connection         *sqlx.DB
	Config             mysql.Config
	MaxOpenConnections int
	Connected          bool
}

MySQL is our primary struct

func (*MySQL) ConfigString

func (m *MySQL) ConfigString() string

ConfigString turns our configuration into a JSON string

func (*MySQL) Connect

func (m *MySQL) Connect() error

Connect to the database

func (*MySQL) Default added in v1.3.6

func (m *MySQL) Default(user, password, address, dbName string)

Default creates a default config based on given parameters

func (*MySQL) Delete

func (m *MySQL) Delete(namedQuery string, deleteStructs any) (int64, error)

Delete performs a deletion

persons := []Person{
	{Id: 0},
	{Id: 1},
}
err = db.NamedExec(`DELETE FROM persons WHERE id=:id`, persons)

func (*MySQL) DeleteOne added in v1.3.7

func (m *MySQL) DeleteOne(namedQuery string, deleteStruct any) error

DeleteOne performs a deletion

persons := Person{Id: 0}
err = db.NamedExec(`DELETE FROM persons WHERE id=:id`, persons)

func (*MySQL) Insert

func (m *MySQL) Insert(namedQuery string, insertStruct any) error

Insert many structs into a named query using sqlx standards

persons := []Person{
	{FirstName: "Ardie"},
	{FirstName: "Sonny"},
}
err = db.NamedExec(`INSERT INTO persons (first_name) VALUES (:first_name)`, persons)

func (*MySQL) InsertOne added in v1.3.7

func (m *MySQL) InsertOne(namedQuery string, insertStruct any) (int64, error)

InsertOne one struct into a named query using sqlx standards

person := Person{ FirstName: "Ardie" }
lastInsertId, err = db.NamedExec(`INSERT INTO persons (first_name) VALUES (:first_name)`, person)

func (*MySQL) MatchError added in v1.3.8

func (m *MySQL) MatchError(err error) MySQLError

MatchError matches a MySQL error with a given list of known errors (to be expanded) and returns a MySQLError

func (*MySQL) RawQuery added in v1.5.0

func (m *MySQL) RawQuery(query string, args ...any) (*sql.Rows, error)

RawQuery allows one to perform a raw query

func (*MySQL) Select

func (m *MySQL) Select(into any, query string, args ...any) (any, error)

Select for more than one result is expected

countries := []Countries{}
countries, err := db.Select(&countries, "SELECT * FROM countries ORDER BY name ASC")

func (*MySQL) SelectOne

func (m *MySQL) SelectOne(into any, query string, args ...any) (any, error)

SelectOne single result, stored within arg:into

country := Country{}
country, err := db.Select(&country, "SELECT * FROM countries WHERE name='Germany' ORDER BY name ASC")

func (*MySQL) String

func (m *MySQL) String() string

String returns our MySQL struct as a JSON string

func (*MySQL) Update

func (m *MySQL) Update(namedQuery string, updateStructs any) error

Update performs an update of many records

persons := []Person{
	{FirstName: "Ardie"},
	{FirstName: "Sonny"},
}
err = db.NamedExec(`UPDATE persons SET first_name=:first_name`, persons)

func (*MySQL) UpdateOne added in v1.3.7

func (m *MySQL) UpdateOne(namedQuery string, updateStruct any) (int64, error)

UpdateOne performs an update of one record

persons := Person{ FirstName: "Ardie" }
err = db.NamedExec(`UPDATE persons SET first_name=:first_name`, persons)

type MySQLError added in v1.3.8

type MySQLError struct {
	Name  string
	Error error
}

MySQLError provides a common struct for MySQL Errors

type Neo4j

type Neo4j struct {
	DSN url.URL
	// contains filtered or unexported fields
}

Neo4j is our primary struct

func (*Neo4j) Connect

func (n *Neo4j) Connect() error

Connect attempts to connect to the DB

func (*Neo4j) CypherQuery

func (n *Neo4j) CypherQuery(query CypherQuery) (interface{}, error)

CypherQuery perform a query - results will be populated with the query results - it must be a slice of structs.

func (*Neo4j) NewNode

func (n *Neo4j) NewNode(node neoism.Props) (*neoism.Node, error)

NewNode creates a new node

func (*Neo4j) String

func (n *Neo4j) String() string

String returns our Neo4j struct as a JSON string

func (*Neo4j) TransactCypherQuery

func (n *Neo4j) TransactCypherQuery(queries []CypherQuery) (interface{}, error)

TransactCypherQuery creates a CyperQuery Transaction

type Redis

type Redis struct {
	Options     *redis.Options
	IsConnected bool
	// contains filtered or unexported fields
}

Redis is our primary struct

func (*Redis) CheckIfConnected

func (r *Redis) CheckIfConnected() bool

CheckIfConnected Checks our connection status to our Redis DB

func (*Redis) Get

func (r *Redis) Get(key string) (string, error)

Get a key value pair from our Redis DB

func (*Redis) GetRawConnectionAndContext

func (r *Redis) GetRawConnectionAndContext() (*redis.Client, context.Context)

GetRawConnectionAndContext returns both our Redis Client and the latest context

func (*Redis) Init

func (r *Redis) Init() error

Init creates a new Redis connection

func (*Redis) Set

func (r *Redis) Set(key string, value string, expiration time.Duration) error

Set a key value pair in our Redis DB

Jump to

Keyboard shortcuts

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