Sphire Mantis API Documentation

Sphire Mantis' API Documentation

View the Project on GitHub sphireinc/Mantis

Go Report Card Go Reference

database

import "github.com/sphireinc/mantis/database"

Index

Constants

const mysqlErrorDuplicate = "duplicate"

type Aerospike

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 (*Aerospike) Connect

func (a *Aerospike) Connect() error

Connect to the database

func (*Aerospike) Default

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

Default creates a default config based on given parameters

func (*Aerospike) Get

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

Get a key value pair from our Redis DB

func (*Aerospike) Set

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

Set a key value pair in our Redis DB

func (*Aerospike) String

func (a *Aerospike) String() string

String returns our Aerospike struct as a JSON string

type AerospikeError

AerospikeError provides a common struct for Aerospike Errors

type AerospikeError struct {
    Name  string
    Error error
}

type CypherQuery

CypherQuery is our query struct

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

func (*CypherQuery) String

func (c *CypherQuery) String() string

String returns our query struct as a JSON string

type MySQL

MySQL is our primary struct

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

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

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

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

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

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

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

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

MySQLError provides a common struct for MySQL Errors

type MySQLError struct {
    Name  string
    Error error
}

type Neo4j

Neo4j is our primary struct

type Neo4j struct {
    conn *neoism.Database
    DSN  url.URL
}

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

Redis is our primary struct

type Redis struct {
    client      *redis.Client
    context     context.Context
    Options     *redis.Options
    IsConnected bool
}

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

Generated by gomarkdoc