Documentation ¶
Overview ¶
Package postgres contains Postgres-specific implementation of the Apollo domain models and services.
Index ¶
- func ConvertPgError(err error) error
- type AddressService
- func (a *AddressService) CreateAddress(ctx context.Context, addressCreate core.Address) (*core.Address, error)
- func (a *AddressService) CreateAddressTx(ctx context.Context, dbtx sqlc.DBTX, addressCreate core.Address) (*core.Address, error)
- func (a *AddressService) DeleteAddress(ctx context.Context, id core.AddressID) error
- func (a *AddressService) GetAddress(ctx context.Context, id core.AddressID) (*core.Address, error)
- func (a *AddressService) ListAddresses(ctx context.Context) ([]core.Address, error)
- func (a *AddressService) UpdateAddress(ctx context.Context, id core.AddressID, data core.AddressUpdateData) (*core.Address, error)
- type DB
- func (db *DB) DeleteSchema(ctx context.Context, schema string) error
- func (db *DB) Migrate(migrations *embed.FS, folder string, isDebug bool) error
- func (db *DB) MigrateDown(migrations *embed.FS, folder string, isDebug bool) error
- func (db *DB) SetSearchPath(ctx context.Context, path string) error
- func (db *DB) SwitchSchema(ctx context.Context, schema string) error
- type OrganisationService
- func (o *OrganisationService) AddUser(ctx context.Context, UserID core.UserID, OrgID core.OrganisationID) error
- func (o *OrganisationService) AddUserTx(ctx context.Context, dbtx sqlc.DBTX, UserID core.UserID, ...) error
- func (o *OrganisationService) CreateOrganisation(ctx context.Context, name string, parentID *core.OrganisationID) (*core.Organisation, error)
- func (o *OrganisationService) CreateOrganisationTx(ctx context.Context, dbtx sqlc.DBTX, name string, ...) (*core.Organisation, error)
- func (o *OrganisationService) DeleteOrganisation(ctx context.Context, id core.OrganisationID) error
- func (o *OrganisationService) GetAmountOfOrganisations(ctx context.Context) (uint64, error)
- func (o *OrganisationService) GetMemberByEmail(ctx context.Context, orgID core.OrganisationID, email core.EmailAddress) (*core.User, error)
- func (o *OrganisationService) GetOrganisation(ctx context.Context, id core.OrganisationID) (*core.Organisation, error)
- func (o *OrganisationService) ListOrganisationChildren(ctx context.Context, parentID core.OrganisationID) ([]core.Organisation, error)
- func (o *OrganisationService) ListOrganisations(ctx context.Context) ([]core.Organisation, error)
- func (o *OrganisationService) ListOrganisationsForUser(ctx context.Context, id core.UserID) ([]core.Organisation, error)
- func (o *OrganisationService) ListUsersInOrganisation(ctx context.Context, id core.OrganisationID) ([]core.User, error)
- func (o *OrganisationService) RemoveUser(ctx context.Context, UserID core.UserID, OrgID core.OrganisationID) error
- func (o *OrganisationService) UpdateOrganisation(ctx context.Context, organisationID core.OrganisationID, name string) (*core.Organisation, error)
- type PermissionService
- func (p *PermissionService) AddUserToPermissionGroup(ctx context.Context, UserID core.UserID, GroupID permissions.PermissionGroupID) error
- func (p *PermissionService) AddUserToPermissionGroupForOrganisation(ctx context.Context, UserID core.UserID, OrgID core.OrganisationID, ...) error
- func (p *PermissionService) CreatePermissionGroup(ctx context.Context, Group *permissions.PermissionGroup) (*permissions.PermissionGroup, error)
- func (p *PermissionService) DeletePermissionGroup(ctx context.Context, GroupID permissions.PermissionGroupID) error
- func (p *PermissionService) GetPermissionGroup(ctx context.Context, ID permissions.PermissionGroupID) (*permissions.PermissionGroup, error)
- func (p *PermissionService) GetUserPermissions(ctx context.Context, UserID core.UserID) (map[permissions.Permission]bool, error)
- func (p *PermissionService) GetUserPermissionsForOrganisation(ctx context.Context, UserID core.UserID, OrgID core.OrganisationID) (map[permissions.Permission]bool, error)
- func (p *PermissionService) HasAny(ctx context.Context, UserID core.UserID, permission permissions.Permission) (bool, error)
- func (p *PermissionService) HasAnyForOrg(ctx context.Context, UserID core.UserID, OrgID core.OrganisationID, ...) (bool, error)
- func (p *PermissionService) HasAnyForOrgTree(ctx context.Context, userID core.UserID, orgID core.OrganisationID, ...) (bool, error)
- func (p *PermissionService) ListPermissionGroups(ctx context.Context) ([]permissions.PermissionGroup, error)
- func (p *PermissionService) ListPermissionGroupsForUser(ctx context.Context, UserID core.UserID) ([]permissions.PermissionGroup, error)
- func (p *PermissionService) ListPermissionGroupsForUserForOrganisation(ctx context.Context, UserID core.UserID, OrgID core.OrganisationID) ([]permissions.PermissionGroup, error)
- func (p *PermissionService) ListPermissions(ctx context.Context) ([]permissions.Permission, error)
- func (p *PermissionService) RegisterPermission(ctx context.Context, permission permissions.Permission) error
- func (p *PermissionService) RenamePermissionGroup(ctx context.Context, ID permissions.PermissionGroupID, Name string) error
- func (p *PermissionService) UpdatePermissionGroup(ctx context.Context, Group *permissions.PermissionGroup) error
- type PgOauthAccountService
- func (s *PgOauthAccountService) CacheUserData(ctx context.Context, data *login.UserData) (*login.UserDataCacheID, error)
- func (s *PgOauthAccountService) CreateUserAccount(ctx context.Context, data *login.UserData) (*core.User, error)
- func (s *PgOauthAccountService) DeleteOldCacheEntries(ctx context.Context, age time.Duration) error
- func (s *PgOauthAccountService) FindUser(ctx context.Context, data *login.UserData) (*core.User, error)
- func (s *PgOauthAccountService) GetCachedUserData(ctx context.Context, id *login.UserDataCacheID) (*login.UserData, error)
- type UserService
- func (u *UserService) CreateUser(ctx context.Context, name string, email core.EmailAddress, lang string) (*core.User, error)
- func (u *UserService) DeleteUser(ctx context.Context, id core.UserID) error
- func (u *UserService) GetAmountOfUsers(ctx context.Context) (uint64, error)
- func (u *UserService) GetUser(ctx context.Context, id core.UserID) (*core.User, error)
- func (u *UserService) ListUsers(ctx context.Context) ([]core.User, error)
- func (u *UserService) UpdateUser(ctx context.Context, id core.UserID, data core.UserUpdate) (*core.User, error)
- func (u *UserService) UpdateUserAdmin(ctx context.Context, id core.UserID, admin bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertPgError ¶
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 (*AddressService) DeleteAddress ¶
DeleteAddress implements core.AddressService.DeleteAddress
func (*AddressService) GetAddress ¶
GetAddress implements core.AddressService.GetAddress
func (*AddressService) ListAddresses ¶
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 ¶
func NewDB ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (p *PermissionService) GetPermissionGroup( ctx context.Context, ID permissions.PermissionGroupID, ) (*permissions.PermissionGroup, error)
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 (*PgOauthAccountService) DeleteOldCacheEntries ¶
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 ¶
DeleteUser implements core.UserService.
func (*UserService) GetAmountOfUsers ¶
func (u *UserService) GetAmountOfUsers(ctx context.Context) (uint64, error)
GetAmountOfUsers 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 ¶
UpdateUserAdmin implements core.UserService.