Commit b0be9a36 authored by Vijay Kumar Chauhan's avatar Vijay Kumar Chauhan
Browse files

Merge branch 'coreimmudb_examples' into 'coreimmudb'

Added coreimmudb package examples, and below fixes.

See merge request !271
parents aa5d0de4 91e7e7fc
3 merge requests!275#20 Add single database connection functionality added, unit test, added example and added go 1.20.8 support.,!274Add single database connection functionality added, unit test, example added...,!271Added coreimmudb package examples, and below fixes.
Showing with 511 additions and 23 deletions
......@@ -28,6 +28,7 @@ Port (`port`) - Port on which ImmuDB running.<br>
Database (`database`) - Database name.<br>
Username (`username`) - Database username<br>
Password (`password`) - Database password<br>
Dir (`dir`) - Storing .identity (database server identity) and .state file <br>
IsDefault (`isDefault`) - Default database selection<br>
IsDisabled (`isDisabled`) - Skip connection <br>
......@@ -55,6 +56,7 @@ Port (`port`) - Port on which ImmuDB running.<br>
Database (`database`) - Database name.<br>
Username (`username`) - Database username<br>
Password (`password`) - Database password<br>
Dir (`dir`) - Storing .identity (database server identity) and .state file <br>
IsDefault (`isDefault`) - Default database selection<br>
IsDisabled (`isDisabled`) - Skip connection <br>
<br>
......
......@@ -30,13 +30,13 @@ var (
)
type ImmuHost struct {
HostName string `json:"hostName"`
HostName string `json:"hostName"` // Connection name
Server string `json:"server"` // Database server address
Port int `json:"port"` // Database port
Database string `json:"database"` // Database name
Username string `json:"username"` // Database username
Password string `json:"password"` // Database password
Dir string `json:"dir"` // For saving .identity (server) and .state files
Dir string `json:"dir"` // Storing .identity (database server identity) and .state file
MaxRecvMsgSize int `json:"maxRecvMsgSize"` // Recieve message maximum size in MB (Default: 4MB)
IsDefault bool `json:"isDefault"` // Default ImmuDB connection
IsDisabled bool `json:"isDisabled"` // If true connection then connection to database server is skipped
......@@ -198,7 +198,7 @@ func DeleteImmuDbSession(hostName string) error {
return inst.CloseSession(context.TODO()) // Closing immudb connection if there are any errors then returning.
}
// TestImmuDbConnection - Connects to Immudb with provided Database host details, returns false - if not able to connect ImmuDB
// TestImmuDbConnection - Connects to Immudb with provided Database host details, if failed then error is returned or else nil.
func TestDbConnection(host ImmuHost) error {
var client immudb.ImmuClient
......@@ -266,7 +266,15 @@ func GetImmuDAOWithHost(hostname string) *ImmuDAO {
/* READ OPERATIONS */
// GetKeyData - Get single value for provided key
/*
GetKeyData - Get single value for provided key
Use GetOptions for advance filtering as show below;
immuDAO.MetaData.GetOpts = coreimmudb.GetOptions{AtTx: 0, AtRevision: 0, SinceTx: 0, NoWait: true}
NOTE: 'immuDAO' is Data access object; To get Data access object use coreimmudb.GetImmuDAOWithHost("hostname")
*/
func (i *ImmuDAO) GetKeyData(key []byte) (*schema.Entry, error) {
client, err := GetImmuDbConnection(i.HostName) // ImmuDB connection for the provided host
if err != nil {
......@@ -279,8 +287,17 @@ func (i *ImmuDAO) GetKeyData(key []byte) (*schema.Entry, error) {
return client.Get(context.TODO(), key, opts...)
}
// GetVerifiedKeyData - Get single value for provided key with additional server-provided proof validation.
/*
GetVerifiedKeyData - Get single value for provided key with additional server-provided proof validation.
Use GetOptions for advance filtering as show below;
immuDAO.MetaData.GetOpts = coreimmudb.GetOptions{AtTx: 0, AtRevision: 0, SinceTx: 0, NoWait: true}
NOTE: 'immuDAO' is Data access object; To get Data access object use coreimmudb.GetImmuDAOWithHost("hostname")
*/
func (i *ImmuDAO) GetVerifiedKeyData(key []byte) (*schema.Entry, error) {
client, err := GetImmuDbConnection(i.HostName) // ImmuDB connection for the provided host
if err != nil {
return nil, err
......@@ -345,19 +362,26 @@ func (i *ImmuDAO) GetKeyHistory(key []byte, offset uint64, limit int32, desc boo
return client.History(context.TODO(), req)
}
// GetActiveKeys - List all avaliable keys from active database, this function does not retrive deleted keys
/*
This call can have below options:-
SeekKey - List all keys which were inserted/saved after the specified key, include specified key in result if InclusiveSeek = True
EndKey - List all keys which were inserted/saved before the specified key, include specified key in result if InclusiveEnd = True
Prefix - List all keys which are perfixed with given character(s)
Desc - Sorting in descending order
Limit - Maximum numbers of entries to return
SinceTx - Used to avoid waiting for the indexer to be up-to-date with the most recent transaction
NoWait (True/False) - If set to true, then the server will not wait for the indexer to be up-to-date with the most recent transaction
InclusiveSeek (True/False)
InclusiveEnd (True/False)
Offset - Number of entries to skip
GetActiveKeys - List all avaliable keys from active database, this function does not retrive deleted keys
- Use scan options for advance filtering as shown below
immuDAO.MetaData.ScanOpts = schema.ScanRequest{Desc: true, Limit: 10}
NOTE: 'immuDAO' is Data access object; To get Data access object use coreimmudb.GetImmuDAOWithHost("hostname")
Scan options field description:
SeekKey - List all keys which were inserted/saved after the specified key, include specified key in result if InclusiveSeek = True
EndKey - List all keys which were inserted/saved before the specified key, include specified key in result if InclusiveEnd = True
Prefix - List all keys which are perfixed with given character(s)
Desc - Sorting in descending order
Limit - Maximum numbers of entries to return
SinceTx - Used to avoid waiting for the indexer to be up-to-date with the most recent transaction
NoWait (True/False) - If set to true, then the server will not wait for the indexer to be up-to-date with the most recent transaction
InclusiveSeek (True/False)
InclusiveEnd (True/False)
Offset - Number of entries to skip
*/
func (i *ImmuDAO) GetActiveKeys() (*schema.Entries, error) {
client, err := GetImmuDbConnection(i.HostName) // ImmuDB connection
......
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment