postgres

package
v0.0.0-...-d215556 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package postgres contains Postgres-specific implementation of the Apollo domain models and services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertPgError

func ConvertPgError(err error) error

ConvertPgError will convert known postgres errors to their core variant. Unknown or unhandled errors will be returned as-is. Converting nil will simply return nil.

Types

type AddressService

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

Postgres implementation of the core AddressService interface.

func NewAddressService

func NewAddressService(DB *DB) *AddressService

func (*AddressService) CreateAddress

func (a *AddressService) CreateAddress(
	ctx context.Context,
	addressCreate core.Address,
) (*core.Address, error)

CreateAddress implements core.AddressService.CreateAddress

func (*AddressService) CreateAddressTx

func (a *AddressService) CreateAddressTx(
	ctx context.Context,
	dbtx sqlc.DBTX,
	addressCreate core.Address,
) (*core.Address, error)

func (*AddressService) DeleteAddress

func (a *AddressService) DeleteAddress(ctx context.Context, id core.AddressID) error

DeleteAddress implements core.AddressService.DeleteAddress

func (*AddressService) GetAddress

func (a *AddressService) GetAddress(ctx context.Context, id core.AddressID) (*core.Address, error)

GetAddress implements core.AddressService.GetAddress

func (*AddressService) ListAddresses

func (a *AddressService) ListAddresses(ctx context.Context) ([]core.Address, error)

ListAddresses implements core.AddressService.ListAddresses

func (*AddressService) UpdateAddress

func (a *AddressService) UpdateAddress(
	ctx context.Context,
	id core.AddressID,
	data core.AddressUpdateData,
) (*core.Address, error)

UpdateAddress implements core.AddressService.UpdateAddress

type DB

type DB struct {
	*pgxpool.Pool
}

func NewDB

func NewDB(ctx context.Context, connString, schema string) (*DB, error)

Initialise a new database connection. connString should be a valid postgres connection string (such as a postgres-url). The database will use the specified schema, if it exists. If the schema doesn't exist yet, it will be created.

func (*DB) DeleteSchema

func (db *DB) DeleteSchema(ctx context.Context, schema string) error

Delete the specified database schema, beware that this will delete all tables and data in the schema. The schema string here is not sanitised, as such this could be used to do SQL injection and should never pass on unsanitised user input!

func (*DB) Migrate

func (db *DB) Migrate(migrations *embed.FS, folder string, isDebug bool) error

Migrate the database using the specified embedded migration folder. "folder" specifies the location of the folder containing sql files within the embed.FS To only run the Apollo migrations, set migrations to nil

func (*DB) MigrateDown

func (db *DB) MigrateDown(migrations *embed.FS, folder string, isDebug bool) error

Migrate the database down a single step using the specified embedded migration folder. "folder" specifies the location of the folder containing sql files within the embed.FS To only run the Apollo migrations, set migrations to nil

func (*DB) SetSearchPath

func (db *DB) SetSearchPath(ctx context.Context, path string) error

Set the search path to the specified value. If the search path contains non-existent schemas, this will error. Beware that the schema here is not sanitised, as such this could be used to do SQL injection and should never pass on unsanitised user input!

func (*DB) SwitchSchema

func (db *DB) SwitchSchema(ctx context.Context, schema string) error

Switch the database schema. If the specified schema does not exist already, this will create it. Beware that the schema here is not sanitised, as such this could be used to do SQL injection and should never pass on unsanitised user input!

type OrganisationService

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

Postgres implementation of the core OrganisationService interface.

func NewOrganisationService

func NewOrganisationService(DB *DB) *OrganisationService

func (*OrganisationService) AddUser

func (o *OrganisationService) AddUser(
	ctx context.Context,
	UserID core.UserID,
	OrgID core.OrganisationID,
) error

AddUser implements core.OrganisationService.AddUser

func (*OrganisationService) AddUserTx

func (o *OrganisationService) AddUserTx(
	ctx context.Context,
	dbtx sqlc.DBTX,
	UserID core.UserID,
	OrgID core.OrganisationID,
) error

func (*OrganisationService) CreateOrganisation

func (o *OrganisationService) CreateOrganisation(
	ctx context.Context,
	name string,
	parentID *core.OrganisationID,
) (*core.Organisation, error)

CreateOrganisation implements core.OrganisationService.CreateOrganisation

func (*OrganisationService) CreateOrganisationTx

func (o *OrganisationService) CreateOrganisationTx(
	ctx context.Context,
	dbtx sqlc.DBTX,
	name string,
	parentID *core.OrganisationID,
) (*core.Organisation, error)

Calls CreateOrganisation query using as a regular query or as a transaction

func (*OrganisationService) DeleteOrganisation

func (o *OrganisationService) DeleteOrganisation(
	ctx context.Context,
	id core.OrganisationID,
) error

DeleteOrganisation implements core.OrganisationService.DeleteOrganisation

func (*OrganisationService) GetAmountOfOrganisations

func (o *OrganisationService) GetAmountOfOrganisations(ctx context.Context) (uint64, error)

GetAmountOfOrganisations implements core.OrganisationService.GetAmountOfOrganisations

func (*OrganisationService) GetMemberByEmail

func (o *OrganisationService) GetMemberByEmail(
	ctx context.Context,
	orgID core.OrganisationID,
	email core.EmailAddress,
) (*core.User, error)

func (*OrganisationService) GetOrganisation

func (o *OrganisationService) GetOrganisation(
	ctx context.Context,
	id core.OrganisationID,
) (*core.Organisation, error)

GetOrganisation implements core.OrganisationService.GetOrganisation

func (*OrganisationService) ListOrganisationChildren

func (o *OrganisationService) ListOrganisationChildren(
	ctx context.Context,
	parentID core.OrganisationID,
) ([]core.Organisation, error)

ListOrganisationChildren implements core.OrganisationService.ListOrganisationChildren

func (*OrganisationService) ListOrganisations

func (o *OrganisationService) ListOrganisations(ctx context.Context) ([]core.Organisation, error)

ListOrganisations implements core.OrganisationService.ListOrganisations

func (*OrganisationService) ListOrganisationsForUser

func (o *OrganisationService) ListOrganisationsForUser(
	ctx context.Context,
	id core.UserID,
) ([]core.Organisation, error)

ListOrganisationsForUser implements core.OrganisationService.ListOrganisationsForUser

func (*OrganisationService) ListUsersInOrganisation

func (o *OrganisationService) ListUsersInOrganisation(
	ctx context.Context,
	id core.OrganisationID,
) ([]core.User, error)

ListUsersInOrganisation implements core.OrganisationService.ListUsersInOrganisation

func (*OrganisationService) RemoveUser

func (o *OrganisationService) RemoveUser(
	ctx context.Context,
	UserID core.UserID,
	OrgID core.OrganisationID,
) error

RemoveUser implements core.OrganisationService.RemoveUser

func (*OrganisationService) UpdateOrganisation

func (o *OrganisationService) UpdateOrganisation(
	ctx context.Context,
	organisationID core.OrganisationID,
	name string,
) (*core.Organisation, error)

Calls UpdateOrganisation query

type PermissionService

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

Postgres implementation of the core UserService interface.

func NewPermissionService

func NewPermissionService(DB *DB) *PermissionService

func (*PermissionService) AddUserToPermissionGroup

func (p *PermissionService) AddUserToPermissionGroup(
	ctx context.Context,
	UserID core.UserID,
	GroupID permissions.PermissionGroupID,
) error

AddUserToPermissionGroup implements permissions.Service.

func (*PermissionService) AddUserToPermissionGroupForOrganisation

func (p *PermissionService) AddUserToPermissionGroupForOrganisation(
	ctx context.Context,
	UserID core.UserID,
	OrgID core.OrganisationID,
	GroupID permissions.PermissionGroupID,
) error

AddUserToPermissionGroup implements permissions.Service.

func (*PermissionService) CreatePermissionGroup

func (p *PermissionService) CreatePermissionGroup(
	ctx context.Context,
	Group *permissions.PermissionGroup,
) (*permissions.PermissionGroup, error)

CreatePermissionGroup implements permissions.Service.

func (*PermissionService) DeletePermissionGroup

func (p *PermissionService) DeletePermissionGroup(
	ctx context.Context,
	GroupID permissions.PermissionGroupID,
) error

DeletePermissionGroup implements permissions.Service.

func (*PermissionService) GetPermissionGroup

GetPermissionGroup implements permissions.Service.

func (*PermissionService) GetUserPermissions

func (p *PermissionService) GetUserPermissions(
	ctx context.Context,
	UserID core.UserID,
) (map[permissions.Permission]bool, error)

GetUserPermissions implements permissions.Service.

func (*PermissionService) GetUserPermissionsForOrganisation

func (p *PermissionService) GetUserPermissionsForOrganisation(
	ctx context.Context,
	UserID core.UserID,
	OrgID core.OrganisationID,
) (map[permissions.Permission]bool, error)

GetUserPermissionsForOrganisation implements permissions.Service.

func (*PermissionService) HasAny

func (p *PermissionService) HasAny(
	ctx context.Context,
	UserID core.UserID,
	permission permissions.Permission,
) (bool, error)

HasAny implements permissions.Service.

func (*PermissionService) HasAnyForOrg

func (p *PermissionService) HasAnyForOrg(
	ctx context.Context,
	UserID core.UserID,
	OrgID core.OrganisationID,
	permission permissions.Permission,
) (bool, error)

HasAnyForOrg implements permissions.Service.

func (*PermissionService) HasAnyForOrgTree

func (p *PermissionService) HasAnyForOrgTree(
	ctx context.Context,
	userID core.UserID,
	orgID core.OrganisationID,
	permission permissions.Permission,
) (bool, error)

HasAnyForOrgTree implements permissions.Service.

func (*PermissionService) ListPermissionGroups

func (p *PermissionService) ListPermissionGroups(
	ctx context.Context,
) ([]permissions.PermissionGroup, error)

ListPermissionGroups implements permissions.Service.

func (*PermissionService) ListPermissionGroupsForUser

func (p *PermissionService) ListPermissionGroupsForUser(
	ctx context.Context,
	UserID core.UserID,
) ([]permissions.PermissionGroup, error)

ListPermissionGroupsForUser implements permissions.Service.

func (*PermissionService) ListPermissionGroupsForUserForOrganisation

func (p *PermissionService) ListPermissionGroupsForUserForOrganisation(
	ctx context.Context,
	UserID core.UserID,
	OrgID core.OrganisationID,
) ([]permissions.PermissionGroup, error)

ListPermissionGroupsForUserForOrganisation implements permissions.Service.

func (*PermissionService) ListPermissions

func (p *PermissionService) ListPermissions(ctx context.Context) ([]permissions.Permission, error)

ListPermissions implements permissions.Service.

func (*PermissionService) RegisterPermission

func (p *PermissionService) RegisterPermission(
	ctx context.Context,
	permission permissions.Permission,
) error

RegisterPermission implements permissions.Service.

func (*PermissionService) RenamePermissionGroup

func (p *PermissionService) RenamePermissionGroup(
	ctx context.Context,
	ID permissions.PermissionGroupID,
	Name string,
) error

RenamePermissionGroup implements permissions.Service.

func (*PermissionService) UpdatePermissionGroup

func (p *PermissionService) UpdatePermissionGroup(
	ctx context.Context,
	Group *permissions.PermissionGroup,
) error

UpdatePermissionGroup implements permissions.Service.

type PgOauthAccountService

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

Postgres implementation of the core UserService interface.

func NewOauthAccountService

func NewOauthAccountService(db *DB) *PgOauthAccountService

func (*PgOauthAccountService) CacheUserData

func (s *PgOauthAccountService) CacheUserData(
	ctx context.Context,
	data *login.UserData,
) (*login.UserDataCacheID, error)

func (*PgOauthAccountService) CreateUserAccount

func (s *PgOauthAccountService) CreateUserAccount(
	ctx context.Context,
	data *login.UserData,
) (*core.User, error)

func (*PgOauthAccountService) DeleteOldCacheEntries

func (s *PgOauthAccountService) DeleteOldCacheEntries(
	ctx context.Context,
	age time.Duration,
) error

func (*PgOauthAccountService) FindUser

func (s *PgOauthAccountService) FindUser(
	ctx context.Context,
	data *login.UserData,
) (*core.User, error)

func (*PgOauthAccountService) GetCachedUserData

func (s *PgOauthAccountService) GetCachedUserData(
	ctx context.Context,
	id *login.UserDataCacheID,
) (*login.UserData, error)

type UserService

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

Postgres implementation of the core UserService interface.

func NewUserService

func NewUserService(DB *DB) *UserService

func (*UserService) CreateUser

func (u *UserService) CreateUser(
	ctx context.Context,
	name string,
	email core.EmailAddress,
	lang string,
) (*core.User, error)

CreateUser implements core.UserService.

func (*UserService) DeleteUser

func (u *UserService) DeleteUser(ctx context.Context, id core.UserID) error

DeleteUser implements core.UserService.

func (*UserService) GetAmountOfUsers

func (u *UserService) GetAmountOfUsers(ctx context.Context) (uint64, error)

GetAmountOfUsers implements core.UserService.

func (*UserService) GetUser

func (u *UserService) GetUser(ctx context.Context, id core.UserID) (*core.User, error)

GetUser implements core.UserService.

func (*UserService) ListUsers

func (u *UserService) ListUsers(ctx context.Context) ([]core.User, error)

ListUsers implements core.UserService.

func (*UserService) UpdateUser

func (u *UserService) UpdateUser(
	ctx context.Context,
	id core.UserID,
	data core.UserUpdate,
) (*core.User, error)

UpdateUser implements core.UserService.

func (*UserService) UpdateUserAdmin

func (u *UserService) UpdateUserAdmin(ctx context.Context, id core.UserID, admin bool) error

UpdateUserAdmin implements core.UserService.

Directories

Path Synopsis
internal
sqlc
Package sqlc contains auto-generated SQL bindings.
Package sqlc contains auto-generated SQL bindings.

Jump to

Keyboard shortcuts

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