Documentation ¶
Index ¶
- Constants
- Variables
- func AddDBConnection(host ImmuHost) error
- func DeleteImmuDbSession(hostName string) error
- func GetImmuDbConnection(hostName string) (immudb.ImmuClient, error)
- func InitImmuDBConnections(hosts []ImmuHost) error
- func InitUsingJson(filePath string) error
- func TestDbConnection(host ImmuHost) error
- type GetOptions
- type ImmuDAO
- func (i *ImmuDAO) CreateDatabase(dbName string, dbSettings *schema.DatabaseNullableSettings) (*schema.CreateDatabaseResponse, error)
- func (i *ImmuDAO) CreateUser(username, password, dbName string, permission int) error
- func (i *ImmuDAO) DeleteDatabase(dbName string) (*schema.DeleteDatabaseResponse, error)
- func (i *ImmuDAO) DeleteKey(keys [][]byte) (*schema.TxHeader, error)
- func (i *ImmuDAO) ExpirableKeySet(key, value []byte, expiresAt time.Time) (*schema.TxHeader, error)
- func (i *ImmuDAO) GetActiveKeys() (*schema.Entries, error)
- func (i *ImmuDAO) GetAllKeysData(keys [][]byte) (*schema.Entries, error)
- func (i *ImmuDAO) GetKeyData(key []byte) (*schema.Entry, error)
- func (i *ImmuDAO) GetKeyHistory(key []byte, offset uint64, limit int32, desc bool) (*schema.Entries, error)
- func (i *ImmuDAO) GetVerifiedKeyData(key []byte) (*schema.Entry, error)
- func (i *ImmuDAO) ListDatabases() (*schema.DatabaseListResponseV2, error)
- func (i *ImmuDAO) ListUsers() (*schema.UserList, error)
- func (i *ImmuDAO) SetAllKeysData(kv []KeyValue) (*schema.TxHeader, error)
- func (i *ImmuDAO) SetKeyData(key, value []byte) (*schema.TxHeader, error)
- func (i *ImmuDAO) SetVerifiedKeyData(key, value []byte) (*schema.TxHeader, error)
- type ImmuHost
- type KeyValue
- type MetaData
Examples ¶
Constants ¶
const ( AdminPermission = auth.PermissionAdmin ReadPermission = auth.PermissionR ReadWritePermission = auth.PermissionRW )
Variables ¶
var (
DefaultHostName string // Holds default hostname
)
Functions ¶
func AddDBConnection ¶ added in v1.2.11
AddDBConnection - Initializes single connection of ImmuDB server using ImmuHost data
Example ¶
host1 := ImmuHost{HostName: "Host1", Server: "127.0.0.1", Port: 3322, Database: "defaultdb", Username: "username", Password: "password", Dir: "./immudb", IsDefault: true} // Establishing database connection for above host details err := AddDBConnection(host1) if err != nil { loggermdl.LogError(err) return } loggermdl.LogInfo("Immudb single connection successfully established!")
Output:
func DeleteImmuDbSession ¶
DeleteImmuDbSession - Disconnecting Immu Database connection
Example ¶
// Connecting to the Immudb host1 := ImmuHost{HostName: "Host1", Server: "127.0.0.1", Port: 3322, Database: "defaultdb", Username: "username", Password: "password", Dir: "./immudb", IsDefault: true} // Establishing database connection err := InitImmuDBConnections([]ImmuHost{host1}) if err != nil { loggermdl.LogError(err) return } // Closing database connection (session) err = DeleteImmuDbSession(host1.HostName) if err != nil { loggermdl.LogError(err) return } loggermdl.LogInfo(host1.HostName + " connection closed!")
Output:
func GetImmuDbConnection ¶
func GetImmuDbConnection(hostName string) (immudb.ImmuClient, error)
Get ImmuDB connection - immudb.ImmuClient
Example ¶
// Establishing connection to Immudb host1 := ImmuHost{HostName: "Host1", Server: "127.0.0.1", Port: 3322, Database: "defaultdb", Username: "username", Password: "password", Dir: "./immudb", IsDefault: true} err := InitImmuDBConnections([]ImmuHost{host1}) if err != nil { loggermdl.LogError(err) return } // Getting immudb.ImmuClient client, err := GetImmuDbConnection(host1.HostName) if err != nil { loggermdl.LogError(err) return } _ = client
Output:
func InitImmuDBConnections ¶
InitNewImmuDbSession - Initializes connection to ImmuDB server using []ImmuHost data
Example ¶
host1 := ImmuHost{HostName: "Host1", Server: "127.0.0.1", Port: 3322, Database: "defaultdb", Username: "username", Password: "password", Dir: "./immudb", IsDefault: true} host2 := ImmuHost{HostName: "Host2", Server: "127.0.0.1", Port: 3322, Database: "database1", Username: "username", Password: "password", Dir: "./immudb"} // Establishing database connection err := InitImmuDBConnections([]ImmuHost{host1, host2}) if err != nil { loggermdl.LogError(err) return } loggermdl.LogInfo("Immudb connection established!")
Output:
func InitUsingJson ¶
InitUsingJsonFile - Initializes connection to ImmuDB server using json config file
Example ¶
filePath := "./dbconfig.json" // Establishing connection using JSON file err := InitUsingJson(filePath) if err != nil { loggermdl.LogError(err) return } loggermdl.LogInfo("Immudb connection successfully established!")
Output:
func TestDbConnection ¶
TestImmuDbConnection - Connects to Immudb with provided Database host details, if failed then error is returned or else nil.
Example ¶
host1 := ImmuHost{HostName: "Host1", Server: "127.0.0.1", Port: 3322, Database: "defaultdb", Username: "username", Password: "password", Dir: "./immudb", IsDefault: true} err := TestDbConnection(host1) if err != nil { loggermdl.LogError(err) return } loggermdl.LogInfo("Test connection successful!")
Output:
Types ¶
type GetOptions ¶
type ImmuDAO ¶
func GetImmuDAOWithHost ¶
GetImmuDAOWithHost - return Immu DAO instance for provided host
For default ImmuDB DAO: Pass empty string - coreimmudb.GetImmuDAOWithHost("") OR Use DefaultHostName - coreimmudb.DefaultHostName
Example ¶
// Establishing connection to Immudb host1 := ImmuHost{HostName: "Host1", Server: "127.0.0.1", Port: 3322, Database: "defaultdb", Username: "username", Password: "password", Dir: "./immudb", IsDefault: true} err := InitImmuDBConnections([]ImmuHost{host1}) if err != nil { loggermdl.LogError(err) return } // For getting specific connection immudb Data Access Object(DAO), just provide connection hostname. immuDAO := GetImmuDAOWithHost(host1.HostName) // For getting default connection Data Access Object(DAO) immuDAO = GetImmuDAOWithHost(DefaultHostName) _ = immuDAO
Output:
func (*ImmuDAO) CreateDatabase ¶
func (i *ImmuDAO) CreateDatabase(dbName string, dbSettings *schema.DatabaseNullableSettings) (*schema.CreateDatabaseResponse, error)
CreateDatabase - Creates new database in ImmuDB, current database user requires SysAdmin permission level.
func (*ImmuDAO) CreateUser ¶
CreateUser - Creates new user
username - Username of the new user password - Password of the new user (Password must have between 8 and 32 letters, digits and special characters of which at least 1 uppercase letter, 1 digit and 1 special character.) dbName - Database name
permission: 1 (coreimmudb.ReadPermission) - read-only access 2 (coreimmudb.ReadWritePermission) - read-write access 254 (coreimmudb.AdminPermission) - read-write with admin rights
func (*ImmuDAO) DeleteDatabase ¶
func (i *ImmuDAO) DeleteDatabase(dbName string) (*schema.DeleteDatabaseResponse, error)
DeleteDatabase - Removes existing database from ImmuDB
func (*ImmuDAO) DeleteKey ¶
DeleteKey - Key is deleted logically from Database, physically it is present in database
func (*ImmuDAO) ExpirableKeySet ¶
ExpirableKeySet - Sets value for the key with expiration time
func (*ImmuDAO) GetActiveKeys ¶
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 (*ImmuDAO) GetAllKeysData ¶
GetAllKeysData - Getting all keys data
GetAllKeysData retrives value for provided keys, values will be nil, for those keys which are not present in immudb
func (*ImmuDAO) GetKeyData ¶
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 (*ImmuDAO) GetKeyHistory ¶
func (i *ImmuDAO) GetKeyHistory(key []byte, offset uint64, limit int32, desc bool) (*schema.Entries, error)
GetKeyHistory - Get history of single key
Offset - Number of entries to skip Limit - Maximum numbers of entries to return Desc - Sorting in descending order
func (*ImmuDAO) GetVerifiedKeyData ¶
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 (*ImmuDAO) ListDatabases ¶
func (i *ImmuDAO) ListDatabases() (*schema.DatabaseListResponseV2, error)
ListDatabases - returns a list of databases the user has access.
func (*ImmuDAO) ListUsers ¶
ListUsers - List all database of user
This call requires Admin or SysAdmin permission level.
When called as a SysAdmin user, all users in the database are returned. When called as an Admin user, users for currently selected database are returned.
func (*ImmuDAO) SetAllKeysData ¶
SetAllKeysData - Set multiple keys with their values in a single transaction.
func (*ImmuDAO) SetKeyData ¶
SetKeyData - Commits provided value for provided key
type ImmuHost ¶
type ImmuHost struct { 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"` // 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 }
type MetaData ¶
type MetaData struct { GetOpts GetOptions ScanOpts schema.ScanRequest }