Sphire Mantis' API Documentation
import "github.com/sphireinc/mantis/database"
const mysqlErrorDuplicate = "duplicate"
Aerospike is our primary struct
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"`
}
func (a *Aerospike) Connect() error
Connect to the database
func (a *Aerospike) Default(hostname string, port int) error
Default creates a default config based on given parameters
func (a *Aerospike) Get(key *aerospike.Key) (*aerospike.Record, error)
Get a key value pair from our Redis DB
func (a *Aerospike) Set(namespace, setName, key, bin, value string) error
Set a key value pair in our Redis DB
func (a *Aerospike) String() string
String returns our Aerospike struct as a JSON string
AerospikeError provides a common struct for Aerospike Errors
type AerospikeError struct {
Name string
Error error
}
CypherQuery is our query struct
type CypherQuery struct {
Results interface{}
Statement string
Parameters neoism.Props
}
func (c *CypherQuery) String() string
String returns our query struct as a JSON string
MySQL is our primary struct
type MySQL struct {
LastQuery string
Connection *sqlx.DB
Config mysql.Config
MaxOpenConnections int
Connected bool
}
func (m *MySQL) ConfigString() string
ConfigString turns our configuration into a JSON string
func (m *MySQL) Connect() error
Connect to the database
func (m *MySQL) Default(user, password, address, dbName string)
Default creates a default config based on given parameters
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 (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 (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 (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 (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 (m *MySQL) RawQuery(query string, args ...any) (*sql.Rows, error)
RawQuery allows one to perform a raw query
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 (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 (m *MySQL) String() string
String returns our MySQL struct as a JSON string
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 (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)
MySQLError provides a common struct for MySQL Errors
type MySQLError struct {
Name string
Error error
}
Neo4j is our primary struct
type Neo4j struct {
conn *neoism.Database
DSN url.URL
}
func (n *Neo4j) Connect() error
Connect attempts to connect to the DB
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 (n *Neo4j) NewNode(node neoism.Props) (*neoism.Node, error)
NewNode creates a new node
func (n *Neo4j) String() string
String returns our Neo4j struct as a JSON string
func (n *Neo4j) TransactCypherQuery(queries []CypherQuery) (interface{}, error)
TransactCypherQuery creates a CyperQuery Transaction
Redis is our primary struct
type Redis struct {
client *redis.Client
context context.Context
Options *redis.Options
IsConnected bool
}
func (r *Redis) CheckIfConnected() bool
CheckIfConnected Checks our connection status to our Redis DB
func (r *Redis) Get(key string) (string, error)
Get a key value pair from our Redis DB
func (r *Redis) GetRawConnectionAndContext() (*redis.Client, context.Context)
GetRawConnectionAndContext returns both our Redis Client and the latest context
func (r *Redis) Init() error
Init creates a new Redis connection
func (r *Redis) Set(key string, value string, expiration time.Duration) error
Set a key value pair in our Redis DB
Generated by gomarkdoc