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 ¶
- type Keeper
- func (k *Keeper) AddData(ctx context.Context, table string, user_id int, entry_id string, ...) error
- func (k *Keeper) AddUser(ctx context.Context, username string, hashedPassword string) error
- func (k *Keeper) ClearData(ctx context.Context, table string, userID int) error
- func (k *Keeper) CompareHashAndPassword(hashedPassword, password string) bool
- func (k *Keeper) CreateSyncEntry(ctx context.Context, operation string, table string, user_id int, ...) error
- func (k *Keeper) DeleteData(ctx context.Context, table string, user_id int, entry_id string) error
- func (k *Keeper) GetAllData(ctx context.Context, table string, user_id int, columns ...string) ([]map[string]string, error)
- func (k *Keeper) GetData(ctx context.Context, table string, user_id int, entry_id string) (map[string]string, error)
- func (k *Keeper) GetPassword(ctx context.Context, username string) (string, error)
- func (k *Keeper) GetSyncEntriesByStatus(ctx context.Context, status string) ([]models.SyncQueue, error)
- func (k *Keeper) GetUserID(ctx context.Context, username string) (int, error)
- func (k *Keeper) IsEmpty(ctx context.Context) (bool, error)
- func (k *Keeper) UpdateData(ctx context.Context, table string, user_id int, entry_id string, ...) error
- func (k *Keeper) UpdateSyncEntryStatus(ctx context.Context, id int, status string) error
- func (k *Keeper) UserExists(ctx context.Context, username string) (bool, error)
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 (*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) ClearData ¶
ClearData deletes all records associated with the specified user_id from the specified table in the database.
func (*Keeper) CompareHashAndPassword ¶
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 ¶
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 ¶
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) 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 ¶
UpdateSyncEntryStatus updates the status of an entry in the sync table.