package storage
import "hauru.club/x/okrzeja/storage"
Package storage contains repository adapters for database interfaces.
Right now SQLite is the only one supported database (storage option).
Index ¶
- type SQLite
- func NewSQLite(ctx context.Context, filename string) (*SQLite, error)
- func (s *SQLite) AccountCreate( ctx context.Context, req service.AccountCreateRequest, ) (*service.AccountCreateResponse, error)
- func (s *SQLite) AccountDelete(ctx context.Context, id uuid.UUID) error
- func (s *SQLite) AccountUpdatePassword(ctx context.Context, req service.AccountUpdatePasswordRequest) error
- func (s *SQLite) AccountsCreate(ctx context.Context, reqs []service.AccountCreateRequest) error
- func (s *SQLite) AccountsRead( ctx context.Context, limit int, query string, ) ([]service.ReadAccountResponse, error)
- func (s *SQLite) AccountsReadFrom( ctx context.Context, req service.AccountsReadFromRequest, ) ([]service.ReadAccountResponse, error)
- func (s *SQLite) ActivitiesRead( ctx context.Context, req rest.ActivitiesReadRequest, ) ([]rest.ActivitiesReadResponse, error)
- func (s *SQLite) ActivitiesReadInit( ctx context.Context, userID uuid.UUID, ) ([]rest.ActivitiesReadResponse, error)
- func (s *SQLite) ActivityPush(ctx context.Context, req service.ActivityPushRequest) error
- func (s *SQLite) AdminConfirm(ctx context.Context, id uuid.UUID) (bool, error)
- func (s *SQLite) AdminCount(ctx context.Context) (int, error)
- func (s *SQLite) AdminMakeNow(ctx context.Context, id uuid.UUID) error
- func (s *SQLite) AdminUsernames(ctx context.Context) ([]string, error)
- func (s *SQLite) CSRFTokenRead(ctx context.Context, sessionID uuid.UUID) (token string, err error)
- func (s *SQLite) CSRFTokenWrite(ctx context.Context, req httpx.CSRFWriteRequest) error
- func (s *SQLite) Close() error
- func (s *SQLite) CountFiles(ctx context.Context) (int, error)
- func (s *SQLite) CountUsersSessions(ctx context.Context, username string) (int, error)
- func (s *SQLite) DeleteSession(ctx context.Context, id uuid.UUID) error
- func (s *SQLite) FileCreateWithOwner(ctx context.Context, req service.FileCreateWithOwnerRequest) error
- func (s *SQLite) FileDeleteWithRoles(ctx context.Context, id uuid.UUID) error
- func (s *SQLite) FileOwnerRead(ctx context.Context, fileID uuid.UUID) (uuid.UUID, error)
- func (s *SQLite) FileRead(ctx context.Context, fileID uuid.UUID) (*service.FileReadResponse, error)
- func (s *SQLite) FileReadOfUser(ctx context.Context, owner, path string) (*service.FileReadResponse, error)
- func (s *SQLite) FileWriteContent(ctx context.Context, req service.FileWriteContentRequest) error
- func (s *SQLite) FileWriteName(ctx context.Context, req service.FileWriteNameRequest) error
- func (s *SQLite) FilesReadFromDirectory(ctx context.Context, dirID uuid.UUID) ([]service.FileReadResponse, error)
- func (s *SQLite) ReadAccount(ctx context.Context, uid uuid.UUID) (*service.ReadAccountResponse, error)
- func (s *SQLite) ReadAccountByUsername( ctx context.Context, username string, ) (*service.ReadAccountResponse, error)
- func (s *SQLite) ReadLatestConfig(ctx context.Context) ([]byte, error)
- func (s *SQLite) ReadSession(ctx context.Context, id uuid.UUID) (*httpx.SessionState, error)
- func (s *SQLite) RolesRead( ctx context.Context, req service.RolesReadRequest, ) ([]service.Role, error)
- func (s *SQLite) RolesWrite(ctx context.Context, req service.RolesWriteRequest) error
- func (s *SQLite) WriteConfig(ctx context.Context, c config.WriteRequest) error
- func (s *SQLite) WriteSession(ctx context.Context, session httpx.SessionState) error
Types ¶
type SQLite ¶
type SQLite struct {
// contains filtered or unexported fields
}
SQLite implements repository interfaces for SQLite database.
func NewSQLite ¶
NewSQLite is default constructor for SQLite storage adapter. Remember to close adapter after it's no longer used.
func (*SQLite) AccountCreate ¶
func (s *SQLite) AccountCreate( ctx context.Context, req service.AccountCreateRequest, ) (*service.AccountCreateResponse, error)
CreateAccount creates new account for requested user.
func (*SQLite) AccountDelete ¶
AccountDelete removes account and all its dependencies (like files, roles etc), for user with given ID, from the system.
This method can return ErrUserNotFound if there is no user with given ID.
func (*SQLite) AccountUpdatePassword ¶
func (s *SQLite) AccountUpdatePassword(ctx context.Context, req service.AccountUpdatePasswordRequest) error
AccountUpdatePassword updates password of existing user.
This method can return ErrUserNotFound if there is no user with given ID.
func (*SQLite) AccountsCreate ¶
AccountsCreate creates new accounts for requested users. It should return ErrUsernameAlreadyTaken error if there is already user with username from requested batch of users.
func (*SQLite) AccountsRead ¶
func (s *SQLite) AccountsRead( ctx context.Context, limit int, query string, ) ([]service.ReadAccountResponse, error)
AccountsRead returns limited group of accounts.
func (*SQLite) AccountsReadFrom ¶
func (s *SQLite) AccountsReadFrom( ctx context.Context, req service.AccountsReadFromRequest, ) ([]service.ReadAccountResponse, error)
AccountsReadFrom returns limited group of accounts that had been created after creation date of account of user with given ID.
func (*SQLite) ActivitiesRead ¶
func (s *SQLite) ActivitiesRead( ctx context.Context, req rest.ActivitiesReadRequest, ) ([]rest.ActivitiesReadResponse, error)
ActivitiesRead returns list of activities owned by user with given user ID that were created before activity with given last ID.
func (*SQLite) ActivitiesReadInit ¶
func (s *SQLite) ActivitiesReadInit( ctx context.Context, userID uuid.UUID, ) ([]rest.ActivitiesReadResponse, error)
ActivitiesReadInit initializes querying user activities. It returns limited number of user activities. You can use last user's activity ID from given slice and ActivitiesReadFrom method to query for more entries.
func (*SQLite) ActivityPush ¶
ActivityPush saves activity in the storage.
func (*SQLite) AdminConfirm ¶
AdminConfirm returns true if user with given UUID is admin.
func (*SQLite) AdminCount ¶
AdminCount tracks number of admin accounts in the storage.
func (*SQLite) AdminMakeNow ¶
MakeAdminNow tags user with given ID as admin account with promotion date set to the current time.
func (*SQLite) AdminUsernames ¶
AdminUsernames returns list of all admin usernames.
func (*SQLite) CSRFTokenRead ¶
CSRFTokenRead returns token associated with given unique session ID.
func (*SQLite) CSRFTokenWrite ¶
CSRFTokenWrite saves token associated with session in the CSRF token storage.
func (*SQLite) Close ¶
Close closes SQLite storage adapter.
func (*SQLite) CountFiles ¶
CountFiles returns number of all files in the okrzeja's filesystem.
func (*SQLite) CountUsersSessions ¶
CountUsersSessions returns number of sessions owned by user with given username.
func (*SQLite) DeleteSession ¶
DeleteSession removes completely information about session with given ID from storage.
func (*SQLite) FileCreateWithOwner ¶
func (s *SQLite) FileCreateWithOwner(ctx context.Context, req service.FileCreateWithOwnerRequest) error
FileCreateWithOwner creates new file or directory with provided user ID as owner. It returns ErrFilenameTaken, if there is already file with given name and the same parent ID.
func (*SQLite) FileDeleteWithRoles ¶
FileDeleteWithRoles removes file or directory with its children and all roles assigned to the given file. It removes children roles also in case of directory.
func (*SQLite) FileOwnerRead ¶
FileOwnerRead returns unique user's ID of owner of file with given file ID.
func (*SQLite) FileRead ¶
FileRead returns all the content and metadata associated with file stored in the Okrzeja's storage with given file ID.
func (*SQLite) FileReadOfUser ¶
func (s *SQLite) FileReadOfUser(ctx context.Context, owner, path string) (*service.FileReadResponse, error)
FileReadOfUser returns file data of file owned by user with given username. If there is no such file or user, it returns ErrFileNotFound error.
func (*SQLite) FileWriteContent ¶
FileWriteContent writes new content to the existing file with provided ID.
func (*SQLite) FileWriteName ¶
FileWriteName updates name of the already existing file with provided ID. Returns ErrFileNotFound if there is no file with given ID.
func (*SQLite) FilesReadFromDirectory ¶
func (s *SQLite) FilesReadFromDirectory(ctx context.Context, dirID uuid.UUID) ([]service.FileReadResponse, error)
FilesFromDirectory returns all files being stored currently in the directory with provided unique identifier.
func (*SQLite) ReadAccount ¶
func (s *SQLite) ReadAccount(ctx context.Context, uid uuid.UUID) (*service.ReadAccountResponse, error)
ReadAccount returns account data of user with given unique user ID.
func (*SQLite) ReadAccountByUsername ¶
func (s *SQLite) ReadAccountByUsername( ctx context.Context, username string, ) (*service.ReadAccountResponse, error)
ReadAccountByUsername returns account data of user with given username.
func (*SQLite) ReadLatestConfig ¶
ReadLatestConfig returns latest blob of bytes with encoded config as JSON document.
func (*SQLite) ReadSession ¶
ReadSession reads session's state with provided uuid from session's storage.
func (*SQLite) RolesRead ¶
func (s *SQLite) RolesRead( ctx context.Context, req service.RolesReadRequest, ) ([]service.Role, error)
RolesRead returns slice of roles assigned to given resource and owned by user with provided unique identifier.
func (*SQLite) RolesWrite ¶
RolesWrite writes rule based on the RolesWriteRequest to the roles storage.
func (*SQLite) WriteConfig ¶
WriteConfig writes new version of configuration to the storage.
It shouldn't purge the current version of config, instead, new entry should be added to the storage and previous kept in some kid of archive.
func (*SQLite) WriteSession ¶
WriteSession writes given session to session storage.
Source Files ¶
adapter.go
Directories ¶
Path | Synopsis |
---|---|
storage/sqlite | Package sqlite implements storage interface for embedded sqlite3 database. |
- Version
- v0.0.0-20231010043146-4292577f982b (latest)
- Published
- Oct 10, 2023
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 2 days ago –
Tools for package owners.