bdkeeper

package
v1.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bdkeeper provides functionalities to interact with a SQLite database and perform operations like user management, data manipulation, and synchronization.

Usage:

import "github.com/example.com/bdkeeper"

keeper := bdkeeper.NewKeeper()

// Example: Check if a user exists
exists, err := keeper.UserExists(context.Background(), "username")
if err != nil {
    log.Fatal(err)
}
fmt.Println("User exists:", exists)

// Example: Add a new user
err := keeper.AddUser(context.Background(), "username", "hashedPassword")
if err != nil {
    log.Fatal(err)
}

// Other functionalities are used similarly.

Data Structures:

Keeper - Represents a database keeper with methods to interact with the database.

SyncQueue - Represents a synchronization queue entry with pending operations.

Example Usage:

keeper := bdkeeper.NewKeeper()

// Check if a user exists
exists, err := keeper.UserExists(context.Background(), "username")
if err != nil {
    log.Fatal(err)
}
fmt.Println("User exists:", exists)

// Add a new user
err := keeper.AddUser(context.Background(), "username", "hashedPassword")
if err != nil {
    log.Fatal(err)
}

// Other functionalities are used similarly.

Thread Safety:

The methods provided by Keeper are not thread-safe. It is expected that
the user of the package ensures proper synchronization when used concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper represents a database keeper with methods to interact with the database.

func NewKeeper

func NewKeeper(db *sql.DB) *Keeper

NewKeeper creates a new instance of Keeper and initializes the database.

func (*Keeper) AddData

func (k *Keeper) AddData(ctx context.Context, table string, user_id int, entry_id string, data map[string]string) error

AddData adds data to the specified database table. Keys and values from the provided data map will be inserted into the specified table, along with the given user_id and entry_id.

func (*Keeper) AddUser

func (k *Keeper) AddUser(ctx context.Context, username string, hashedPassword string) error

AddUser adds a new user to the database.

func (*Keeper) ClearData

func (k *Keeper) ClearData(ctx context.Context, table string, userID int) error

ClearData deletes all records associated with the specified user_id from the specified table in the database.

func (*Keeper) CompareHashAndPassword

func (k *Keeper) CompareHashAndPassword(hashedPassword, password string) bool

CompareHashAndPassword compares a hashed password with a plaintext password.

func (*Keeper) CreateSyncEntry

func (k *Keeper) CreateSyncEntry(ctx context.Context, operation string, table string, user_id int, entry_id string, data map[string]string) error

CreateSyncEntry creates a synchronization queue entry in the database.

func (*Keeper) DeleteData

func (k *Keeper) DeleteData(ctx context.Context, table string, user_id int, entry_id string) error

DeleteData deletes a record from the specified table in the database. It checks for the existence of the specified user_id and entry_id, and then deletes the record if found.

func (*Keeper) GetAllData

func (k *Keeper) GetAllData(ctx context.Context, table string, user_id int, columns ...string) ([]map[string]string, error)

GetAllData retrieves all data from the specified table in the database for the given user_id. It returns a slice of maps, with each map containing column names as keys and corresponding values for each row.

func (*Keeper) GetData

func (k *Keeper) GetData(ctx context.Context, table string, user_id int, entry_id string) (map[string]string, error)

GetData retrieves data for a specific entry from the specified table in the database. It returns a map containing column names as keys and corresponding values for the entry.

func (*Keeper) GetPassword

func (k *Keeper) GetPassword(ctx context.Context, username string) (string, error)

GetPassword retrieves the hashed password of a user from the database.

func (*Keeper) GetSyncEntriesByStatus added in v1.3.2

func (k *Keeper) GetSyncEntriesByStatus(ctx context.Context, status string) ([]models.SyncQueue, error)

GetSyncEntriesByStatus returns all entries from the sync table with the given status.

func (*Keeper) GetUserID

func (k *Keeper) GetUserID(ctx context.Context, username string) (int, error)

GetUserID retrieves the user ID of a user from the database.

func (*Keeper) IsEmpty

func (k *Keeper) IsEmpty(ctx context.Context) (bool, error)

IsEmpty checks if the database is empty.

func (*Keeper) UpdateData

func (k *Keeper) UpdateData(ctx context.Context, table string, user_id int, entry_id string, data map[string]string) error

UpdateData updates data in the specified database table. Values from the provided data map will be used to update the record with the specified user_id and entry_id in the specified table.

func (*Keeper) UpdateSyncEntryStatus

func (k *Keeper) UpdateSyncEntryStatus(ctx context.Context, id int, status string) error

UpdateSyncEntryStatus updates the status of an entry in the sync table.

func (*Keeper) UserExists

func (k *Keeper) UserExists(ctx context.Context, username string) (bool, error)

UserExists checks if a user exists in the database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL