okrzejahauru.club/x/okrzeja/storage Index | Files | Directories

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

Types

type SQLite

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

SQLite implements repository interfaces for SQLite database.

func NewSQLite

func NewSQLite(ctx context.Context, filename string) (*SQLite, error)

NewSQLite is default constructor for SQLite storage adapter. Remember to close adapter after it's no longer used.

func (*SQLite) AccountCreate

CreateAccount creates new account for requested user.

func (*SQLite) AccountDelete

func (s *SQLite) AccountDelete(ctx context.Context, id uuid.UUID) error

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

func (s *SQLite) AccountsCreate(ctx context.Context, reqs []service.AccountCreateRequest) error

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

func (s *SQLite) ActivityPush(ctx context.Context, req service.ActivityPushRequest) error

ActivityPush saves activity in the storage.

func (*SQLite) AdminConfirm

func (s *SQLite) AdminConfirm(ctx context.Context, id uuid.UUID) (bool, error)

AdminConfirm returns true if user with given UUID is admin.

func (*SQLite) AdminCount

func (s *SQLite) AdminCount(ctx context.Context) (int, error)

AdminCount tracks number of admin accounts in the storage.

func (*SQLite) AdminMakeNow

func (s *SQLite) AdminMakeNow(ctx context.Context, id uuid.UUID) error

MakeAdminNow tags user with given ID as admin account with promotion date set to the current time.

func (*SQLite) AdminUsernames

func (s *SQLite) AdminUsernames(ctx context.Context) ([]string, error)

AdminUsernames returns list of all admin usernames.

func (*SQLite) CSRFTokenRead

func (s *SQLite) CSRFTokenRead(ctx context.Context, sessionID uuid.UUID) (token string, err error)

CSRFTokenRead returns token associated with given unique session ID.

func (*SQLite) CSRFTokenWrite

func (s *SQLite) CSRFTokenWrite(ctx context.Context, req httpx.CSRFWriteRequest) error

CSRFTokenWrite saves token associated with session in the CSRF token storage.

func (*SQLite) Close

func (s *SQLite) Close() error

Close closes SQLite storage adapter.

func (*SQLite) CountFiles

func (s *SQLite) CountFiles(ctx context.Context) (int, error)

CountFiles returns number of all files in the okrzeja's filesystem.

func (*SQLite) CountUsersSessions

func (s *SQLite) CountUsersSessions(ctx context.Context, username string) (int, error)

CountUsersSessions returns number of sessions owned by user with given username.

func (*SQLite) DeleteSession

func (s *SQLite) DeleteSession(ctx context.Context, id uuid.UUID) error

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

func (s *SQLite) FileDeleteWithRoles(ctx context.Context, id uuid.UUID) error

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

func (s *SQLite) FileOwnerRead(ctx context.Context, fileID uuid.UUID) (uuid.UUID, error)

FileOwnerRead returns unique user's ID of owner of file with given file ID.

func (*SQLite) FileRead

func (s *SQLite) FileRead(ctx context.Context, fileID uuid.UUID) (*service.FileReadResponse, error)

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

func (s *SQLite) FileWriteContent(ctx context.Context, req service.FileWriteContentRequest) error

FileWriteContent writes new content to the existing file with provided ID.

func (*SQLite) FileWriteName

func (s *SQLite) FileWriteName(ctx context.Context, req service.FileWriteNameRequest) error

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

func (s *SQLite) ReadLatestConfig(ctx context.Context) ([]byte, error)

ReadLatestConfig returns latest blob of bytes with encoded config as JSON document.

func (*SQLite) ReadSession

func (s *SQLite) ReadSession(ctx context.Context, id uuid.UUID) (*httpx.SessionState, error)

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

func (s *SQLite) RolesWrite(ctx context.Context, req service.RolesWriteRequest) error

RolesWrite writes rule based on the RolesWriteRequest to the roles storage.

func (*SQLite) WriteConfig

func (s *SQLite) WriteConfig(ctx context.Context, c config.WriteRequest) error

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

func (s *SQLite) WriteSession(ctx context.Context, session httpx.SessionState) error

WriteSession writes given session to session storage.

Source Files

adapter.go

Directories

PathSynopsis
storage/sqlitePackage 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.