Documentation ¶
Overview ¶
This is a client for the HarperDB database. It mirrors the HTTP API as of version 2.2.0 and makes it very easy to get up and running with HarperDB and your Go application.
For more information see: https://docs.harperdb.io/
Basics ¶
Instantiate a new client:
client := harperdb.NewClient("http://localhost:9925", "username", "password")
Index ¶
- Constants
- Variables
- type AffectedResponse
- type Attribute
- type AttributeList
- type AttributePermissions
- type CPULoad
- type Client
- func (c *Client) AddNode(name, host string, port int, subscriptions []Subscription) error
- func (c *Client) AddRole(role string, perm Permission) (*Role, error)
- func (c *Client) AddUser(username, password, roleID string, active bool) error
- func (c *Client) AlterRole(id string, role string, perm Permission) (*Role, error)
- func (c *Client) AlterUser(username, password, roleID string, active bool) error
- func (c *Client) CSVDataLoad(schema, table string, update bool, data io.Reader) (string, error)
- func (c *Client) CSVFileLoad(schema, table string, update bool, filePath string) (string, error)
- func (c *Client) CSVURLLoad(schema, table string, update bool, csvURL string) (string, error)
- func (c *Client) ClusterStatus() (*ClusterStatusResponse, error)
- func (c *Client) CreateAttribute(schema, table, attribute string) error
- func (c *Client) CreateSchema(schema string) error
- func (c *Client) CreateTable(schema, table, hashAttribute string) error
- func (c *Client) Delete(schema, table string, hashValues AttributeList) (*AffectedResponse, error)
- func (c *Client) DeleteFilesBefore(schema, table string, date time.Time) error
- func (c Client) DeleteTransactionLogsBefore(schema, table string, timestamp time.Time) error
- func (c *Client) DescribeAll() (*DescribeAllResponse, error)
- func (c *Client) DescribeTable(schema, table string) (*DescribeTableResponse, error)
- func (c *Client) DropAttribute(schema, table, attribute string) error
- func (c *Client) DropRole(id string) error
- func (c *Client) DropSchema(schema string) error
- func (c *Client) DropTable(schema, table, hashAttribute string) error
- func (c *Client) DropUser(username string) error
- func (c *Client) ExportLocal(format, path string, searchOperation SearchOperation) error
- func (c *Client) ExportToS3(format string, s3creds S3Credentials, searchOperation SearchOperation) error
- func (c *Client) GetFingerprint() (*GetFingerprintResponse, error)
- func (c *Client) GetJob(jobID string) (*GetJobResponse, error)
- func (c *Client) Insert(schema, table string, records interface{}) (*AffectedResponse, error)
- func (c *Client) ListRoles() ([]Role, error)
- func (c *Client) ListUsers() ([]User, error)
- func (c *Client) ReadHarperDBLog(limit, start int, from, until time.Time, order string) (*LogResponse, error)
- func (c Client) ReadTransactionLog(schema, table, searchType string, searchValues interface{}) ([]TxLogEntry, error)
- func (c *Client) RegistrationInfo() (*RegistrationInfoResponse, error)
- func (c *Client) RemoveNode(name string) error
- func (c *Client) SQLExec(stmt string, args ...interface{}) (*AffectedResponse, error)
- func (c *Client) SQLGet(stmt string, args ...interface{}) (interface{}, error)
- func (c *Client) SQLSelect(v interface{}, stmt string, args ...interface{}) error
- func (c *Client) SearchByHash(schema, table string, v interface{}, hashValues AttributeList, ...) error
- func (c *Client) SearchByValue(schema, table string, v interface{}, searchAttribute Attribute, ...) error
- func (c *Client) SearchJobsByStartDate(fromDate, toDate time.Time) ([]GetJobResponse, error)
- func (c *Client) SetLicense(key, company string) error
- func (c *Client) SystemInformation() (*SysInfo, error)
- func (c *Client) Update(schema, table string, records interface{}) (*AffectedResponse, error)
- func (c *Client) UpdateNode(name, host string, port int, subscriptions []Subscription) error
- func (c *Client) UserInfo() (User, error)
- type ClusterStatusResponse
- type Connection
- type DescribeAllResponse
- type DescribeSchemaResponse
- type DescribeTableResponse
- type DiskSize
- type ErrorResponse
- type GetFingerprintResponse
- type GetJobResponse
- type JobResponse
- type LogEntry
- type LogResponse
- type MessageResponse
- type NetworkConnection
- type NetworkInterface
- type NetworkStats
- type OperationError
- type Permission
- type Record
- type RegistrationInfoResponse
- type Role
- type S3Credentials
- type SchemaPermission
- type SearchOperation
- type Subscription
- type SysInfo
- type TableAttribute
- type TablePermission
- type TableSize
- type Timestamp
- type TxLogEntry
- type User
Examples ¶
Constants ¶
const ( CSV_ACTION_INSERT = "insert" CSV_ACTION_UPDATE = "update" )
const ( JobStatusCompleted = "COMPLETE" JobStatusInProgress = "IN_PROGRESS" DATE_FORMAT = "2006-01-02" )
const ( LogOrderAsc = "asc" LogOrderDesc = "desc" LogSearchTypeAll = "" LogSearchTypeTimestamp = "timestamp" LogSearchTypeUsername = "username" LogSearchTypeHashValue = "hash_value" )
const ( OP_ADD_NODE = "add_node" OP_ADD_ROLE = "add_role" OP_ADD_USER = "add_user" OP_ALTER_ROLE = "alter_role" OP_ALTER_USER = "alter_user" OP_CLUSTER_STATUS = "cluster_status" OP_CREATE_ATTRIBUTE = "create_attribute" OP_CREATE_SCHEMA = "create_schema" OP_CREATE_TABLE = "create_table" OP_CSV_DATA_LOAD = "csv_data_load" OP_CSV_FILE_LOAD = "csv_file_load" OP_CSV_URL_LOAD = "csv_url_load" OP_DELETE_FILES_BEFORE = "delete_files_before" OP_DELETE_TRANSACTION_LOG = "delete_transaction_logs_before" OP_DESCRIBE_ALL = "describe_all" OP_DESCRIBE_SCHEMA = "describe_schema" OP_DESCRIBE_TABLE = "describe_table" OP_DELETE = "delete" OP_DROP_ATTRIBUTE = "drop_attribute" OP_DROP_ROLE = "drop_role" OP_DROP_SCHEMA = "drop_schema" OP_DROP_TABLE = "drop_table" OP_DROP_USER = "drop_user" OP_EXPORT_LOCAL = "export_local" OP_EXPORT_TO_S3 = "export_to_s3" OP_GET_FINGERPRINT = "get_fingerprint" OP_GET_JOB = "get_job" OP_INSERT = "insert" OP_LIST_ROLES = "list_roles" OP_LIST_USERS = "list_users" OP_READ_LOG = "read_log" OP_READ_TRANSACTION_LOG = "read_transaction_log" OP_REGISTRATION_INFO = "registration_info" OP_REMOVE_NODE = "remove_node" OP_SEARCH_BY_HASH = "search_by_hash" OP_SEARCH_BY_VALUE = "search_by_value" OP_SEARCH_JOBS = "search_jobs_by_start_date" OP_SET_LICENSE = "set_license" OP_SQL = "sql" OP_SYSTEM_INFORMATION = "system_information" OP_UPDATE = "update" OP_UPDATE_NODE = "update_node" OP_USER_INFO = "user_info" )
const ( SearchBySQL = "sql" SearchByHash = "search_by_hash" SearchByValue = "search_by_value" )
Variables ¶
var ( ErrJobStatusUnknown = errors.New("unknown job status") ErrJobNotFound = errors.New("job not found") ErrNoRows = errors.New("did not return any rows") ErrTooManyRows = errors.New("did return more than one row") ErrNotSingleColumn = errors.New("expected a single column return") )
var AllAttributes = FromStringSlice([]string{"*"})
Functions ¶
This section is empty.
Types ¶
type AffectedResponse ¶
type AffectedResponse struct { MessageResponse SkippedHashes []interface{} `json:"skipped_hashes"` InsertedHashes []interface{} `json:"inserted_hashes"` UpdatedHashes []interface{} `json:"update_hashes"` // (sic) not updated_hashes DeletedHashes []interface{} `json:"deleted_hashes"` }
type AttributeList ¶
type AttributeList interface{}
func FromStringSlice ¶
func FromStringSlice(ss []string) AttributeList
type AttributePermissions ¶
type Client ¶
type Client struct { HttpClient *resty.Client // contains filtered or unexported fields }
func NewClient ¶
Example ¶
// Connecting to a HarperDB instance c := NewClient("http://localhost:9925", "HDB_ADMIN", "password") // (optional) set some proxy c.HttpClient.SetProxy("http://localhost:8888")
Output:
Example (Https) ¶
// Connecting to a HarperDB instance c := NewClient("https://localhost:31283", "HDB_ADMIN", "password") // with a self-signed certificate // will most likely fail so disable security check (https) c.HttpClient.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
Output:
func (*Client) AddNode ¶
func (c *Client) AddNode(name, host string, port int, subscriptions []Subscription) error
func (*Client) CSVDataLoad ¶
CSVDataLoad takes a Reader and executes the CSV Load Data operation if "update" is true, it will not insert but update existing records If successfull, returns the Job ID
func (*Client) CSVFileLoad ¶
CSVFileLoad takes a path of a file which must exist on the server and executes the CSV Load Data operation if "update" is true, it will not insert but update existing records If successfull, returns the Job ID
func (*Client) CSVURLLoad ¶
CSVURLLoad takes a public URL and executes the CSV Load Data operation if "update" is true, it will not insert but update existing records If successfull, returns the Job ID
func (*Client) ClusterStatus ¶
func (c *Client) ClusterStatus() (*ClusterStatusResponse, error)
func (*Client) CreateAttribute ¶
func (*Client) CreateSchema ¶
CreateSchema creates a new schema. Returns "AlreadyExistsError" if schema already existed.
func (*Client) CreateTable ¶
func (*Client) Delete ¶
func (c *Client) Delete(schema, table string, hashValues AttributeList) (*AffectedResponse, error)
Delete delete one or more JSON objects from a table. hashValues must be an array of slice
func (*Client) DeleteFilesBefore ¶
func (Client) DeleteTransactionLogsBefore ¶
func (*Client) DescribeAll ¶
func (c *Client) DescribeAll() (*DescribeAllResponse, error)
func (*Client) DescribeTable ¶
func (c *Client) DescribeTable(schema, table string) (*DescribeTableResponse, error)
func (*Client) DropAttribute ¶
func (*Client) DropSchema ¶
DropSchema drops a schema. Returns "DoesNotExistError" if schema did not exist.
func (*Client) DropUser ¶
DropUser deletes a user. Note: this operation is idempotent, it will not throw an error if the user doesn't exist
func (*Client) ExportLocal ¶
func (c *Client) ExportLocal(format, path string, searchOperation SearchOperation) error
func (*Client) ExportToS3 ¶
func (c *Client) ExportToS3(format string, s3creds S3Credentials, searchOperation SearchOperation) error
func (*Client) GetFingerprint ¶
func (c *Client) GetFingerprint() (*GetFingerprintResponse, error)
func (*Client) Insert ¶
func (c *Client) Insert(schema, table string, records interface{}) (*AffectedResponse, error)
Insert inserts one or more JSON objects into a table Hash value of the inserted JSON record MUST be present.
func (*Client) ReadHarperDBLog ¶
func (Client) ReadTransactionLog ¶
func (c Client) ReadTransactionLog(schema, table, searchType string, searchValues interface{}) ([]TxLogEntry, error)
ReadTransactionLog requests the transaction log for a table. Use LogSearchType* constants to filter the log entries by searchValues, which should be an array/slice of searchType. Leave searchType empty (LogSearchTypeAll) to get all entries.
func (*Client) RegistrationInfo ¶
func (c *Client) RegistrationInfo() (*RegistrationInfoResponse, error)
func (*Client) RemoveNode ¶
func (*Client) SQLExec ¶
func (c *Client) SQLExec(stmt string, args ...interface{}) (*AffectedResponse, error)
SQLExec executes UPDATE/INSERT/DELETE statements and returns a struct with the affected row hash values. You can use format verbs (%s, %d) in the stmt and an pass the arguments at the end of the function, like in fmt.Printf
func (*Client) SQLGet ¶
SQLGet is to query a scalar value from the database. This function is not part of the official HarperDB API. It executes a SQL statement and expects exactly one object with one key. I.e. SELECT CURRENT_TIMESTAMP Will return the following errors: - ErrNoRows - ErrTooManyRows - ErrNotSingleColumn
func (*Client) SQLSelect ¶
SQLSelect executes SELECT statements and returns a record set. You can use format verbs (%s, %d) in the stmt and an pass the arguments at the end of the function, like in fmt.Printf
func (*Client) SearchByHash ¶
func (c *Client) SearchByHash(schema, table string, v interface{}, hashValues AttributeList, getAttributes AttributeList) error
SearchByHash fetches records based on the table's hash field (i.e. primary key).
func (*Client) SearchByValue ¶
func (c *Client) SearchByValue(schema, table string, v interface{}, searchAttribute Attribute, searchValue interface{}, getAttributes AttributeList) error
SearchByValue fetches records based on the value of an attribute Wilcards are allowed in `searchValue`
func (*Client) SearchJobsByStartDate ¶
func (c *Client) SearchJobsByStartDate(fromDate, toDate time.Time) ([]GetJobResponse, error)
func (*Client) SetLicense ¶
func (*Client) SystemInformation ¶
func (*Client) Update ¶
func (c *Client) Update(schema, table string, records interface{}) (*AffectedResponse, error)
Update updates one or more JSON objects in a table. Hash value of the inserted JSON record MUST be present.
func (*Client) UpdateNode ¶
func (c *Client) UpdateNode(name, host string, port int, subscriptions []Subscription) error
type ClusterStatusResponse ¶
type ClusterStatusResponse struct { IsEnabled bool `json:"is_enabled"` NodeName interface{} `json:"node_name"` // (sic) this is an int if cluster is not enabled Status struct { ID string `json:"id"` Type string `json:"type"` OutboundConnections []Connection `json:"outbound_connections"` InboundConnections []Connection `json:"inbound_connections"` } `json:"status"` }
type Connection ¶
type DescribeAllResponse ¶
type DescribeAllResponse map[string]map[string]DescribeTableResponse
type DescribeSchemaResponse ¶
type DescribeSchemaResponse struct { }
type DescribeTableResponse ¶
type DescribeTableResponse struct { Record HashAttribute string `json:"hash_attribute"` ID string `json:"id"` Name string `json:"name"` Residence string `json:"residence"` // TODO Not verified Schema string `json:"schema"` Attributes []TableAttribute `json:"attributes"` RecordCount int `json:"record_count"` }
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
type GetFingerprintResponse ¶
type GetFingerprintResponse struct {
Message string `json:"message"`
}
type GetJobResponse ¶
type GetJobResponse struct { Record MessageResponse CreatedDateTime Timestamp `json:"created_datetime"` EndDateTime Timestamp `json:"end_datetime"` StartDateTime Timestamp `json:"start_datetime"` ID string `json:"id"` JobBody string `json:"job_body"` // TODO Not verified Status string `json:"status"` Type string `json:"type"` User string `json:"user"` StartDateTimeConverted time.Time `json:"start_datetime_converted"` EndDateTimeConverted time.Time `json:"end_datetime_converted"` }
type JobResponse ¶
type JobResponse struct {
JobID string
}
type LogResponse ¶
type LogResponse struct {
File []LogEntry `json:"file"`
}
type MessageResponse ¶
type MessageResponse struct {
Message string `json:"message"`
}
type NetworkConnection ¶
type NetworkInterface ¶
type NetworkInterface struct { Iface string `json:"iface"` IfaceName string `json:"ifaceName"` IP4 string `json:"ip4"` IP6 string `json:"ip6"` Mac string `json:"mac"` OperState string `json:"operstate"` Type string `json:"virtual"` Duplex string `json:"duplex"` Speed int64 `json:"speed"` CarrierChanges int64 `json:"carrierChanges"` }
type NetworkStats ¶
type OperationError ¶
func (*OperationError) Error ¶
func (e *OperationError) Error() string
func (*OperationError) IsAlreadyExistsError ¶
func (e *OperationError) IsAlreadyExistsError() bool
func (*OperationError) IsDoesNotExistError ¶
func (e *OperationError) IsDoesNotExistError() bool
func (*OperationError) IsNotAuthorizedError ¶
func (e *OperationError) IsNotAuthorizedError() bool
type Permission ¶
type Permission map[string]interface{}
func (Permission) AddSchemaPermission ¶
func (p Permission) AddSchemaPermission(schema string, sp SchemaPermission)
func (Permission) SetClusterUser ¶
func (p Permission) SetClusterUser(su bool)
func (Permission) SetSuperUser ¶
func (p Permission) SetSuperUser(su bool)
type Record ¶
type Record struct { CreatedTime Timestamp `json:"__createdtime__"` UpdatedTime Timestamp `json:"__updatedtime__"` }
Record type gives you convenient access to HarperDB's meta data fields which are automatically added to every record. Currently these are "__createdtime__" and "__updatedtime__".
Meta data fields are read-only. Overwriting .CreatedTime and .UpdatedTime will have no effect.
Example ¶
type Player struct { Record // embed the Record type in your custom types ID int `json:"id"` Name string `json:"name"` Age int `json:"age"` }
Output:
type Role ¶
type Role struct { Record Role string `json:"role"` ID string `json:"id"` Permission Permission `json:"permission"` }
type S3Credentials ¶
type SchemaPermission ¶
type SchemaPermission struct {
Tables map[string]TablePermission
}
func (SchemaPermission) AddTablePermission ¶
func (p SchemaPermission) AddTablePermission(table string, tp TablePermission)
type SearchOperation ¶
type Subscription ¶
type SysInfo ¶
type SysInfo struct { System struct { Platform string `json:"platform"` Distro string `json:"distro"` Release string `json:"release"` Codename string `json:"codename"` Kernel string `json:"kernel"` Arch string `json:"arch"` Hostname string `json:"hostname"` NodeVersion string `json:"node_version"` NPMVersion string `json:"npm_version"` } `json:"system"` Time struct { Current Timestamp `json:"current"` Uptime int64 `json:"uptime"` Timezone string `json:"timezone"` TimezoneName string `json:"timezoneName"` } `json:"time"` CPU struct { Manufacturer string `json:"manufacturer"` Brand string `json:"brand"` Vendor string `json:"vendor"` Speed string `json:"speed"` Cores int `json:"cores"` PhysicalCores int `json:"physicalCores"` Processors int `json:"processors"` CPUSpeed struct { Min float64 `json:"min"` Max float64 `json:"max"` Avg float64 `json:"avg"` Cores []float64 `json:"cores"` } `json:"cpu_speed"` CurrentLoad struct { AvgLoag float64 `json:"avgload"` CurrentLoad float64 `json:"currentload"` CurrentLoadUser float64 `json:"currentload_user"` CurrentLoadSystem float64 `json:"currentload_system"` CurrentLoadNice float64 `json:"currentload_nice"` CurrentLoadIdle float64 `json:"currentload_idle"` CurrentLoadIRQ float64 `json:"currentload_irq"` } `json:"current_load"` CPUs []CPULoad `json:"cpus"` } `json:"cpu"` Memory struct { Total int64 `json:"total"` Free int64 `json:"free"` Used int64 `json:"used"` Active int64 `json:"active"` Available int64 `json:"available"` SwapTotal int64 `json:"swaptotal"` SwapUsed int64 `json:"swapused"` SwapFree int64 `json:"swapfree"` } `json:"memory"` Disk struct { IO struct { RIO int64 `json:"rIO"` WIO int64 `json:"wIO"` TIO int64 `json:"tIO"` } `json:"io"` ReadWrite struct { RX int64 `json:"rx"` WX int64 `json:"wx"` TX int64 `json:"tx"` MS int64 `json:"ms"` } `json:"read_write"` Size []DiskSize `json:"size"` } `json:"disk"` Network struct { DefaultInterface string `json:"default_interface"` Latency struct { URL string `json:"url"` Ok bool `json:"ok"` Status int64 `json:"status"` MS int64 `json:"ms"` } `json:"latency"` Interfaces []NetworkInterface `json:"interfaces"` Stats []NetworkStats `json:"stats"` Connections []NetworkConnection `json:"connections"` } `json:"network"` HarperDBProcesses struct { Core interface{} `json:"core"` // TODO Unknown Clustering interface{} `json:"clustering"` // TODO Unknown } `json:"harperdb_processes"` TableSize []TableSize `json:"table_size"` }
type TableAttribute ¶
type TableAttribute struct {
Attribute string `json:"attribute"`
}
type TablePermission ¶
type TablePermission struct { Read bool `json:"read"` Insert bool `json:"insert"` Update bool `json:"update"` Delete bool `json:"delete"` AttributePermissions []AttributePermissions `json:"attribute_permissions"` }