Documentation
¶
Index ¶
- type ErrNotFound
- type Event
- type EventCallback
- type EventType
- type FilterTranslator
- type FilterTranslatorBuilder
- type GenericDAO
- func (d *GenericDAO[O]) Create(ctx context.Context, object O) (result O, err error)
- func (d *GenericDAO[O]) Delete(ctx context.Context, id string) (err error)
- func (d *GenericDAO[O]) Exists(ctx context.Context, id string) (ok bool, err error)
- func (d *GenericDAO[O]) Get(ctx context.Context, id string) (result O, err error)
- func (d *GenericDAO[O]) List(ctx context.Context, request ListRequest) (response ListResponse[O], err error)
- func (d *GenericDAO[O]) Update(ctx context.Context, object O) (result O, err error)
- type GenericDAOBuilder
- func (b *GenericDAOBuilder[O]) AddEventCallback(value EventCallback) *GenericDAOBuilder[O]
- func (b *GenericDAOBuilder[O]) Build() (result *GenericDAO[O], err error)
- func (b *GenericDAOBuilder[O]) SetAttributionLogic(value auth.AttributionLogic) *GenericDAOBuilder[O]
- func (b *GenericDAOBuilder[O]) SetDefaultLimit(value int) *GenericDAOBuilder[O]
- func (b *GenericDAOBuilder[O]) SetLogger(value *slog.Logger) *GenericDAOBuilder[O]
- func (b *GenericDAOBuilder[O]) SetMaxLimit(value int) *GenericDAOBuilder[O]
- func (b *GenericDAOBuilder[O]) SetTable(value string) *GenericDAOBuilder[O]
- func (b *GenericDAOBuilder[O]) SetTenancyLogic(value auth.TenancyLogic) *GenericDAOBuilder[O]
- type ListRequest
- type ListResponse
- type Object
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrNotFound ¶ added in v0.0.18
type ErrNotFound struct {
// ID is the identifier of the object that was not found.
ID string
}
ErrNotFound is an error type that indicates that a requested object doesn't exist.
func (*ErrNotFound) Error ¶ added in v0.0.18
func (e *ErrNotFound) Error() string
Error returns the error message.
type Event ¶
type Event struct {
// Type is the type of the event.
Type EventType
// Table is the name of the table.
Table string
// Object is the object that was created, updated or deleted.
Object proto.Message
}
Event represents a database event with a specific kind and associated object.
type EventCallback ¶
EventCallback is a function that will be called to process an event.
type FilterTranslator ¶ added in v0.0.3
FilterTranslator knows how to translate filter expressions into SQL where clauses.
type FilterTranslatorBuilder ¶ added in v0.0.3
FilterTranslatorBuilder contains the data and logic needed to create a filter translator. Don't create instances of this type directly, use the NewTranslationBuilder function instead.
func NewFilterTranslator ¶ added in v0.0.3
func NewFilterTranslator[O proto.Message]() *FilterTranslatorBuilder[O]
NewFilterTranslator creates a object that knows how to translate filter expressions into SQL where statements.
func (*FilterTranslatorBuilder[O]) Build ¶ added in v0.0.3
func (b *FilterTranslatorBuilder[O]) Build() (result *FilterTranslator[O], err error)
Build uses the data stored in the builder to create and configure a new filter translator.
func (*FilterTranslatorBuilder[O]) SetLogger ¶ added in v0.0.3
func (b *FilterTranslatorBuilder[O]) SetLogger(value *slog.Logger) *FilterTranslatorBuilder[O]
SetLogger sets the logger that will be used by the translator. This is mandatory.
type GenericDAO ¶
type GenericDAO[O Object] struct { // contains filtered or unexported fields }
GenericDAO provides generic data access operations for protocol buffers messages. It assumes that objects will be stored in tables with the following columns:
- `id` - The unique identifier of the object.
- `name` - The human friendly name of the object.
- `creation_timestamp` - The time the object was created.
- `deletion_timestamp` - The time the object was deleted.
- `finalizers` - The list of finalizers for the object.
- `creators` - The list of creators for the object.
- `tenants` - The list of tenants for the object.
- `data` - The serialized object, using the protocol buffers JSON serialization.
Objects must have field named `id` of string type.
func (*GenericDAO[O]) Create ¶
func (d *GenericDAO[O]) Create(ctx context.Context, object O) (result O, err error)
Create adds a new row to the table with a generated identifier and serialized data.
func (*GenericDAO[O]) Delete ¶
func (d *GenericDAO[O]) Delete(ctx context.Context, id string) (err error)
Delete removes a row from the table by its identifier.
func (*GenericDAO[O]) Exists ¶
Exists checks if a row with the given identifiers exists. Returns false and no error if there is no row with the given identifier.
func (*GenericDAO[O]) Get ¶
func (d *GenericDAO[O]) Get(ctx context.Context, id string) (result O, err error)
Get retrieves a single row by its identifier and deserializes it into a message. Returns nil and no error if there is no row with the given identifier.
func (*GenericDAO[O]) List ¶
func (d *GenericDAO[O]) List(ctx context.Context, request ListRequest) (response ListResponse[O], err error)
List retrieves all rows from the table and deserializes them into a slice of messages.
type GenericDAOBuilder ¶
type GenericDAOBuilder[O Object] struct { // contains filtered or unexported fields }
GenericDAOBuilder is a builder for creating generic data access objects.
func NewGenericDAO ¶
func NewGenericDAO[O Object]() *GenericDAOBuilder[O]
NewGenericDAO creates a builder that can then be used to configure and create a generic DAO.
func (*GenericDAOBuilder[O]) AddEventCallback ¶
func (b *GenericDAOBuilder[O]) AddEventCallback(value EventCallback) *GenericDAOBuilder[O]
AddEventCallback adds a function that will be called to process events when the DAO creates, updates or deletes an object.
The functions are called synchronously, in the same order they were added, and with the same context used by the DAO for its operations. If any of them returns an error the transaction will be rolled back.
func (*GenericDAOBuilder[O]) Build ¶
func (b *GenericDAOBuilder[O]) Build() (result *GenericDAO[O], err error)
Build creates a new generic DAO using the configuration stored in the builder.
func (*GenericDAOBuilder[O]) SetAttributionLogic ¶ added in v0.0.12
func (b *GenericDAOBuilder[O]) SetAttributionLogic(value auth.AttributionLogic) *GenericDAOBuilder[O]
SetAttributionLogic sets the attribution logic that will be used to determine the creators for objects. The logic receives the context as a parameter and should return the names of the creators. If not provided, a default logic that returns no creators will be recorded.
func (*GenericDAOBuilder[O]) SetDefaultLimit ¶
func (b *GenericDAOBuilder[O]) SetDefaultLimit(value int) *GenericDAOBuilder[O]
SetDefaultLimit sets the default number of items returned. It will be used when the value of the limit parameter of the list request is zero. This is optional, and the default is 100.
func (*GenericDAOBuilder[O]) SetLogger ¶
func (b *GenericDAOBuilder[O]) SetLogger(value *slog.Logger) *GenericDAOBuilder[O]
SetLogger sets the logger. This is mandatory.
func (*GenericDAOBuilder[O]) SetMaxLimit ¶
func (b *GenericDAOBuilder[O]) SetMaxLimit(value int) *GenericDAOBuilder[O]
SetMaxLimit sets the maximum number of items returned. This is optional and the default value is 1000.
func (*GenericDAOBuilder[O]) SetTable ¶
func (b *GenericDAOBuilder[O]) SetTable(value string) *GenericDAOBuilder[O]
SetTable sets the table name. This is mandatory.
func (*GenericDAOBuilder[O]) SetTenancyLogic ¶ added in v0.0.12
func (b *GenericDAOBuilder[O]) SetTenancyLogic(value auth.TenancyLogic) *GenericDAOBuilder[O]
SetTenancyLogic sets the tenancy logic that will be used to determine the tenants value for objects. The logic receives the context as a parameter and should return the names of the tenants. If not provided, a default logic that returns no tenants will be used.
type ListRequest ¶
type ListRequest struct {
// Offset specifies the starting point.
Offset int32
// Limit specifies the maximum number of items.
Limit int32
// Filter is the CEL expression that defines which objects should be returned.
Filter string
}
ListRequest represents the parameters for paginated queries.
type ListResponse ¶
type ListResponse[I any] struct { // Size is the actual number of items returned. Size int32 // Total is the total number of items available. Total int32 // Items is the list of items. Items []I }
ListResponse represents the result of a paginated query.