store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RepositoryStore

type RepositoryStore interface {
	CreateTable() error
	CreateRepository(repo *pb.CreateRepositoryRequest) (pb.RepositoryResponse, error)
	GetRepository(id string) (*pb.RepositoryResponse, error)
	GetRepositoryByName(name string) (*pb.RepositoryResponse, error)
	UpdateRepository(repo *pb.UpdateRepositoryRequest) (pb.RepositoryResponse, error)
	ListRepositories() (pb.ListRepositoryResponse, error)
	DeleteRepository(id string) error
}

type SQLRepositoryStore

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

func NewSQLRepositoryStore

func NewSQLRepositoryStore(db *sql.DB) *SQLRepositoryStore

NewSQLRepositoryStore creates a new SQLRepositoryStore given a database connection.

If the repositories table does not exist in the database, it will be created.

The function will log a fatal error if there is an issue creating the table.

func (*SQLRepositoryStore) CreateRepository

CreateRepository creates a new repository with the given information.

The request must contain the repository name and description. The ID is generated by the server. The LastUpdate is set to the current timestamp by the server.

The response will contain the created repository information.

Parameters: - repo: The request containing the repository information.

Returns: - *pb.RepositoryResponse: The response containing the created repository information. - error: An error if there is an issue creating the repository.

func (*SQLRepositoryStore) CreateTable

func (s *SQLRepositoryStore) CreateTable() error

CreateTable creates the repositories table in the SQLite database if it does not exist.

The repositories table has the following columns: - id: the ID of the repository, which is the primary key - name: the name of the repository - description: the description of the repository - last_update: the timestamp when the repository was last updated

Returns an error if there is an issue creating the table.

func (*SQLRepositoryStore) DeleteRepository

func (s *SQLRepositoryStore) DeleteRepository(id string) (err error)

DeleteRepository deletes a repository with the specified ID from the database.

Parameters: - id: The ID of the repository to be deleted.

Returns: - error: An error if there is an issue deleting the repository.

func (*SQLRepositoryStore) GetRepository

func (s *SQLRepositoryStore) GetRepository(id string) (*pb.RepositoryResponse, error)

GetRepository gets a repository by ID.

The request must contain the repository ID.

The response will contain the repository information.

Parameters: - id: The ID of the repository to retrieve.

Returns: - *pb.RepositoryResponse: The response containing the repository information. - error: An error if there is an issue retrieving the repository.

func (*SQLRepositoryStore) GetRepositoryByName

func (s *SQLRepositoryStore) GetRepositoryByName(name string) (*pb.RepositoryResponse, error)

GetRepositoryByName retrieves a repository by its name from the database.

Parameters: - name: The name of the repository to retrieve.

Returns: - *pb.RepositoryResponse: The response containing the repository information. - error: An error if there is an issue retrieving the repository.

func (*SQLRepositoryStore) ListRepositories

func (s *SQLRepositoryStore) ListRepositories() (repos pb.ListRepositoryResponse, err error)

ListRepositories lists all existing repositories in the database.

The response will contain a list of existing repositories.

Returns: - *pb.ListRepositoryResponse: The response containing the list of repositories. - error: An error if there is an issue listing repositories.

func (*SQLRepositoryStore) UpdateRepository

UpdateRepository updates an existing repository with the given information.

The request must contain the repository ID, name and description. The ID is used to identify the repository to be updated. The name and description are used to update the repository information.

The response will contain the updated repository information.

Parameters: - repo: The request containing the repository ID, name and description.

Returns: - *pb.RepositoryResponse: The response containing the updated repository information. - error: An error if there is an issue updating the repository.

type SQLUserStore

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

func NewSQLUserStore

func NewSQLUserStore(db *sql.DB) *SQLUserStore

NewSQLUserStore creates a new SQLUserStore given a database connection.

If the users table does not exist in the database, it will be created.

The function will log a fatal error if there is an issue creating the table.

func (*SQLUserStore) CreateTable

func (s *SQLUserStore) CreateTable() error

CreateTable creates the users table in the SQLite database if it does not exist.

The users table has the following columns: - id: the ID of the user, which is the primary key - username: the username of the user - public_key: the public key of the user - created_at: the timestamp when the user was created - updated_at: the timestamp when the user was last updated

Returns an error if there is an issue creating the table.

func (*SQLUserStore) CreateUser

func (s *SQLUserStore) CreateUser(user *pb.CreateUserRequest) (*pb.UserResponse, error)

CreateUser creates a new user with the given information.

The request must contain the username and public key of the user to be created. The username is used to identify the user. The public key is used to store the user's public key.

The response will contain the created user information.

Parameters: - user: The request containing the username and public key.

Returns: - *pb.UserResponse: The response containing the created user information. - error: An error if there is an issue creating the user.

func (*SQLUserStore) DeleteUser

func (s *SQLUserStore) DeleteUser(id string) error

DeleteUser deletes the user with the specified ID from the database.

Parameters: - id: The ID of the user to be deleted.

Returns: - error: An error if the user cannot be deleted.

func (*SQLUserStore) GetPublicKeyByUsername

func (s *SQLUserStore) GetPublicKeyByUsername(username string) (string, error)

func (*SQLUserStore) GetUser

func (s *SQLUserStore) GetUser(id string) (*pb.UserResponse, error)

GetUser retrieves a user by ID from the database.

Parameters: - id: The ID of the user to be retrieved.

Returns: - *pb.UserResponse: The response containing the user information. - error: An error if there is an issue retrieving the user.

func (*SQLUserStore) GetUserByUsername

func (s *SQLUserStore) GetUserByUsername(username string) (*pb.UserResponse, error)

GetUserByUsername retrieves a user by username from the database.

Parameters: - username: The username of the user to be retrieved.

Returns: - *pb.UserResponse: The response containing the user information. - error: An error if there is an issue retrieving the user.

func (*SQLUserStore) ListUsers

func (s *SQLUserStore) ListUsers() (*pb.ListUserResponse, error)

ListUsers lists all existing users in the database.

The response will contain a list of existing users.

Returns: - *pb.ListUserResponse: The response containing the list of users. - error: An error if there is an issue listing users.

func (*SQLUserStore) UpdateUser

func (s *SQLUserStore) UpdateUser(user *pb.UpdateUserRequest) (*pb.UserResponse, error)

UpdateUser updates an existing user with the given information.

The request must contain the user ID, username and public key. The ID is used to identify the user to be updated. The username and public key are used to update the user information.

The response will contain the user information.

Parameters: - user: The request containing the user ID, username and public key.

Returns: - *pb.UserResponse: The response containing the updated user information. - error: An error if there is an issue updating the user.

type UserStore

type UserStore interface {
	CreateUser(user *pb.CreateUserRequest) (*pb.UserResponse, error)
	GetUser(id string) (*pb.UserResponse, error)
	GetUserByUsername(name string) (*pb.UserResponse, error)
	UpdateUser(user *pb.UpdateUserRequest) (*pb.UserResponse, error)
	ListUsers() (*pb.ListUserResponse, error)
	DeleteUser(id string) error
	GetPublicKeyByUsername(username string) (string, error)
}

Jump to

Keyboard shortcuts

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