store

package
v0.0.0-...-b9b5e9f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(ctx context.Context, db *gorm.DB) error

Clear deletes everything from the database. Useful for development. Be careful in production...

func IsNotFoundErr

func IsNotFoundErr(err error) bool

IsNotFoundErr returns whether the error is a Record Not Found error

func IsUniqueConstraintErr

func IsUniqueConstraintErr(err error) bool

IsUniqueConstraintErr returns whether the error is a Unique Constraint Violation error or not

func Migrate

func Migrate(db *gorm.DB) error

Types

type Database

type Database struct {
	// ID corresponds to the types.Database ID
	ID string
	// Name corresponds to the types.Database Name
	Name string
	// CreatedAt corresponds to the types.Database CreatedAt
	CreatedAt time.Time
	// UpdatedAt corresponds to the types.Database UpdatedAt
	UpdatedAt time.Time
}

Database is the store model for types.Database

type DatabaseStore

type DatabaseStore interface {
	// Get a Database by ID
	Get(ctx context.Context, databaseID string) (*types.Database, error)
	// List databases
	List(ctx context.Context) (*types.DatabaseList, error)
	// Create a database
	Create(ctx context.Context, database *types.Database) (*types.Database, error)
	// Delete a database
	Delete(ctx context.Context, databaseID string) error
}

DatabaseStore is the store for types.Database

func NewDatabaseStore

func NewDatabaseStore(db Factory) DatabaseStore

NewDatabaseStore returns a new DatabaseStore

type Factory

type Factory interface {
	Get() (*gorm.DB, error)
}

Factory is the store.Factory that returns an instance of a gorm.DB This is useful because we can implement logic that allows us to renew a database connection, for example, when a connection string changes (credential rotation)

func NewDynamicFactory

func NewDynamicFactory(getDsn dsnFn) (Factory, error)

NewDynamicFactory returns a new dynamicFactory

func NewFactory

func NewFactory(dsn string) (Factory, error)

NewFactory returns a new instance of Factory

type Field

type Field struct {

	// ID stores the types.FieldDefinition ID
	ID string

	// DatabaseID stores the types.FieldDefinition DatabaseID
	DatabaseID string

	// FormID stores the types.FieldDefinition FormID
	FormID string

	// RootFormID stores the root form definition ID for this field.
	// See comment on Form.RootOwnerID
	RootFormID string

	// RootForm is the gorm hack to create a foreign key
	RootForm *Form

	// Name stores the types.FieldDefinition Name
	Name string

	// Description stores the types.FieldDefinition Description
	Description string

	// Code stores the types.FieldDefinition Code
	Code string

	// Key stores the types.FieldDefinition Key
	Key bool

	// Required stores the types.FieldDefinition Required
	Required bool

	// SubFormID stores the SubForm ID. This should be equal to the Field.ID.
	// Merely keeping a duplicate value so we can have a foreign key
	SubFormID *string

	// SubForm creates a gorm ForeignKey
	SubForm *Form

	// ReferencedDatabaseID stores the referenced DatabaseID when the field is a Reference field
	ReferencedDatabaseID *string

	// ReferencedDatabase allows gorm to create a foreign key
	ReferencedDatabase *Database

	// ReferencedFormID stores the referenced FormID when the field is a Reference field
	ReferencedFormID *string

	// ReferencedForm allows gorm to create a foreign key
	ReferencedForm *Form

	// Type stores the field type
	Type types.FieldKind

	// CreatedAt stores the time the Field was created
	CreatedAt time.Time

	// UpdatedAt stores the time the field was updated
	UpdatedAt time.Time
}

Field represents the data structure used to store a types.FieldDefinition

type Fields

type Fields []*Field

type FlatForms

type FlatForms struct {
	Fields  Fields
	Forms   Forms
	Options Options
}

func (FlatForms) Add

func (f FlatForms) Add(flatForm FlatForms) FlatForms

Add concatenates two FlatForms together

type Folder

type Folder struct {
	ID         string
	DatabaseID string
	Database   Database
	ParentID   *string
	Parent     *Folder `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	Name       string
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Folder is the store model for types.Folder

type FolderStore

type FolderStore interface {
	// Get a folder
	Get(ctx context.Context, folderID string) (*types.Folder, error)
	// List folders
	List(ctx context.Context) (*types.FolderList, error)
	// Create a folder
	Create(ctx context.Context, folder *types.Folder) (*types.Folder, error)
	// Delete a folder
	Delete(ctx context.Context, id string) error
}

FolderStore is the store for types.Folder

func NewFolderStore

func NewFolderStore(db Factory) FolderStore

NewFolderStore creates a FolderStore

type Form

type Form struct {

	// ID stores the types.FormDefinition ID
	ID string `gorm:"index:idx_form_id_database_id,unique"`

	// DatabaseID stores the types.FormDefinition DatabaseID
	DatabaseID string `gorm:"index:idx_form_id_database_id,unique"`

	// Database is used so that gorm creates a (not nullable) Foreign Key on the Database table
	Database Database

	// RootOwnerID is present because when we want to fetch the root form and all SubForms
	// for a given FormDefinition, we can simply query WHERE root_owner_id = <RootFormID>.
	// This will retrieve all the forms, subforms and nested subforms that are part
	// of the same FormDefinition
	RootOwnerID string

	// RootOwner is the gorm hack to create a (not nullable) Foreign Key on the Form table
	RootOwner *Form

	// OwnerID represents a SubForm owner OR, when the form is the root form (FormDefinition)
	// then the OwnerID == ID. It's nice like this because we can query all root FormDefinitions
	// with a query like "SELECT * FROM forms where id == owner_id"
	OwnerID string

	// Owner is the same gorm hack to create a (not nullable) foreign key on the Form table
	Owner *Form

	// FolderID stores the types.FormDefinition FolderID
	FolderID *string

	// Folder is the gorm hack to create a (nullable) foreign key on the Folder table
	Folder *Folder

	// Name stores the types.FormDefinition Name
	Name string

	// Type stores the types.FormDefinition Type
	Type string

	// CreatedAt represents when this form was created
	CreatedAt time.Time

	// UpdatedAt represents when this form was updated
	UpdatedAt time.Time
}

Form represents the data structure used to store a types.FormDefinition

type FormStore

type FormStore interface {
	// Get a single Form Definition
	Get(ctx context.Context, formID string) (*types.FormDefinition, error)
	// List FormDefinitions
	List(ctx context.Context) (*types.FormDefinitionList, error)
	// Create a FormDefinition
	Create(ctx context.Context, form *types.FormDefinition) (*types.FormDefinition, error)
	// Delete a FormDefinition
	Delete(ctx context.Context, id string) error
}

FormStore is the store implementation for types.FormDefinition

The responsibility of the FormStore is twofold.

When creating new forms, the FormStore must be able to "flatten" the structure of the FormDefinition into entities that are storable in SQL Tables. It must also be able to re-hydrate the entities into the tree-like structure of a FormDefinition. The "flatten-" and "hydrate-" method do that, respectively.

The next responsibility of the FormStore is the create the underlying SQL Tables that will store the records for the created FormDefinitions.

func NewFormStore

func NewFormStore(db Factory) FormStore

NewFormStore returns a new FormStore

type Forms

type Forms []*Form

type IdentityProvider

type IdentityProvider struct {

	// ID is the Identity provider ID
	ID string

	// OrganizationID is the OrganizationID that owns this IdentityProvider
	OrganizationID string

	// Organization is the Organization that owns this IdentityProvider.
	// We include this field here because gorm.DB creates the Foreign Key
	// constraints when this field is present.
	Organization Organization

	// Domain represents the OIDC Issuer for this Identity Provider
	Domain string

	// ClientID represents the OAuth2 ClientID for this IdentityProvider
	// For example, an Okta ClientID
	ClientID string

	// ClientSecret represents the OAuth2 ClientSecret for the IdentityProvider
	// For example, an Okta ClientSecret
	ClientSecret string

	// EmailDomain represents the Domain of email addresses that should be
	// using this identity provider.
	// e.g. if EmailDomain = "my-org.com", then johndoe@my-org.com would use
	// this IdentityProvider
	EmailDomain string

	// Name of this IdentityProvider
	Name string
}

IdentityProvider is a class that represents an Organization IdentityProvider. Organizations can register multiple IdentityProvider that they trust, through which their staff will be allowed to log in. For example, this could be an Okta, Auth0, GitHub identity provider.

This struct is only used for storing types.IdentityProvider. This store maps the types.IdentityProvider to and from the store.IdentityProvider. This allows us to have flexibility into how we store the IdentityProvider and how we present it to the API.

type IdentityProviderCreateOptions

type IdentityProviderCreateOptions struct {
	// ReturnClientSecret will include the IdentityProvider.ClientSecret in the response
	ReturnClientSecret bool
}

IdentityProviderCreateOptions represent the options when creating an IdentityProvider

type IdentityProviderGetOptions

type IdentityProviderGetOptions struct {
	// ReturnClientSecret will include the IdentityProvider.ClientSecret in the response
	ReturnClientSecret bool
}

IdentityProviderGetOptions represent the options when getting an IdentityProvider

type IdentityProviderListOptions

type IdentityProviderListOptions struct {
	// ReturnClientSecret will include the IdentityProvider.ClientSecret in the response
	ReturnClientSecret bool
}

IdentityProviderListOptions represent the options when Listing IdentityProviders

type IdentityProviderStore

type IdentityProviderStore interface {
	// List identity providers
	List(ctx context.Context, organizationID string, options IdentityProviderListOptions) ([]*types.IdentityProvider, error)
	// Get an IdentityProvider
	Get(ctx context.Context, identityProviderId string, options IdentityProviderGetOptions) (*types.IdentityProvider, error)
	// FindForEmailDomain finds IdentityProviders for the given email domain. Should only return one because we should not allow two
	// identityProvider to use the same email domain
	// TODO make this method return a single IdentityProvider
	FindForEmailDomain(ctx context.Context, emailDomain string, options IdentityProviderListOptions) ([]*types.IdentityProvider, error)
	// Create an IdentityProvider
	Create(ctx context.Context, identityProvider *types.IdentityProvider, options IdentityProviderCreateOptions) (*types.IdentityProvider, error)
	// Update an IdentityProvider
	Update(ctx context.Context, identityProvider *types.IdentityProvider, options IdentityProviderUpdateOptions) (*types.IdentityProvider, error)
}

IdentityProviderStore is the store for IdentityProviders

func NewIdentityProviderStore

func NewIdentityProviderStore(db Factory) IdentityProviderStore

NewIdentityProviderStore returns a new IdentityProviderStore

type IdentityProviderUpdateOptions

type IdentityProviderUpdateOptions struct {
	// ReturnClientSecret will include the IdentityProvider.ClientSecret in the response
	ReturnClientSecret bool
}

IdentityProviderUpdateOptions represent the options when updating an IdentityProvider

type IdentityProviders

type IdentityProviders []*IdentityProvider

IdentityProviders represent a list of IdentityProvider

type Option

type Option struct {

	// ID stores the types.SelectOption ID
	ID string `gorm:"primarykey"`

	// DatabaseID stores the Form's DatabaseID
	DatabaseID string

	// RootFormID stores the root FormID. See Form.RootOwnerID
	RootFormID string

	// FormID stores the FormID of the single/multi select field
	FormID string

	// FieldID stores the single/multi select Field.ID
	FieldID string

	// Name stores the types.SelectOption Name
	Name string
}

Option represents the data structure used to store options for a types.FieldTypeMultiSelect or types.FieldTypeSingleSelect

type Options

type Options []*Option

type Organization

type Organization struct {
	ID          string
	Name        string
	EmailDomain string
}

type OrganizationStore

type OrganizationStore interface {
	Get(ctx context.Context, id string) (*types.Organization, error)
	Create(ctx context.Context, organiztion *types.Organization) (*types.Organization, error)
	Update(ctx context.Context, organization *types.Organization) (*types.Organization, error)
	List(ctx context.Context) ([]*types.Organization, error)
}

func NewOrganizationStore

func NewOrganizationStore(db Factory) OrganizationStore

type Permission

type Permission string

type RecordStore

type RecordStore interface {
	Get(ctx context.Context, recordRef types.RecordRef) (*types.Record, error)
	List(ctx context.Context, options types.RecordListOptions) (*types.RecordList, error)
	Create(ctx context.Context, record *types.Record) (*types.Record, error)
	Update(ctx context.Context, record *types.Record) (*types.Record, error)
	Delete(ctx context.Context, recordRef types.RecordRef) error
}

func NewRecordStore

func NewRecordStore(db Factory, formStore FormStore) RecordStore

Jump to

Keyboard shortcuts

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