Documentation ¶
Index ¶
- Variables
- type Collection
- type Column
- type Iterable
- type Member
- type MemberFilter
- type MemberId
- type MemberUpdater
- type Paging
- type PasswordUpdater
- type Projector
- type Scount
- type ScountFilter
- type ScountId
- type ScountUpdater
- type Sorter
- type Store
- type User
- type UserFilter
- type UserId
- type UserUpdater
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoRows = errors.New("db: no rows in result") ErrConflict = errors.New("db: database state violation") ErrSyntaxPrivilege = errors.New("db: syntax error or insufficient privilege") ErrInvalidData = errors.New("db: invalid data for database operation") ErrNil = errors.New("db: nil pointer") ErrEncoding = errors.New("db: invalid data encoding") ErrInvalidColumn = errors.New("db: invalid or non-permissible column") )
some common errors.
var MemberAllowedCols = []Column{"sid", "uid"}
MemberAllowedCols is a list of columns allowed for sorting.
var UserAllowedCols = []Column{"uid", "email", "username"}
UserAllowedCols is a list of columns allowed for sorting.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection[Item, Filter, Updater, Id any] interface { // Insert adds multiple items to the database. If no items, then ErrNoRows. Insert(ctx context.Context, items ...Item) error // DeleteOne removes exactly one record from the database. // If not found, then ErrNoRows. If nil id passed, then ErrNil. DeleteOne(ctx context.Context, id *Id) error // UpdateOne modifies exactly one record in the database. // If no records match then ErrNoRows. UpdateOne(context.Context, *Id, *Updater) error // Find fetches all the records that match the given filter and projects // them as a list. If no records match, then empty list. Find(context.Context, *Filter, *Projector) (*Iterable[Item], error) // FindOne fetches exactly one matching record. If no such record exist // in the database, then ErrNoRows. FindOne(ctx context.Context, id *Id) (Item, error) }
Collection is a generic implementation of a collection with support for basic CRUD operations. It is assumed to be thread-safe.
type Column ¶
type Column string
Column defines the column names over which sorting and filtering can be performed for a collection.
type Iterable ¶
type Iterable[T any] struct { // contains filtered or unexported fields }
Iterable is a list of generic items being iterable. Iteration is provided via a closure function.
Note: If the `GOEXPERIMENT=range` in go version 1.22 becomes supported, then such (push) iterator pattern will have compiler support for the `for range` loops.
func NewIterable ¶
NewIterable is the construct for list from a closure that yields successive values of T and reports the total items or error.
func (*Iterable[T]) Err ¶
Err reports any errors that occurred during the iteration over the list. It is supposed to be called after iteration, otherwise the call panics.
type MemberFilter ¶
type MemberFilter Member
MemberFilter provides fields for filtering the members.
type MemberId ¶
type MemberId Member
MemberId is the 'id' type for member collection. Both sid and uid determine a member uniquely.
type MemberUpdater ¶
type MemberUpdater struct{}
MemberUpdater provides fields necessary for update operation for member record.
type PasswordUpdater ¶
PasswordUpdater provides fields necessary for update password operation for a user record.
type Projector ¶
type Projector struct { Order []Sorter // column order matters Paging *Paging // pagination options }
Projector provides projection options for fetching the data from a collection.
type ScountFilter ¶
ScountFilter provides fields for filtering the users.
type ScountId ¶
type ScountId struct {
Sid string
}
ScountId is the 'id' type for scount collection. Sid is the primary key or object identifier in the database.
type ScountUpdater ¶
ScountUpdater provides fields for updating scounts.
type Store ¶
type Store struct { Users interface { Collection[User, UserFilter, UserUpdater, UserId] FindByEmail(ctx context.Context, email string) (User, error) UpdatePassword(context.Context, *PasswordUpdater) error } Scounts Collection[Scount, ScountFilter, ScountUpdater, ScountId] Members Collection[Member, MemberFilter, MemberUpdater, MemberId] }
Store provides an interface for all datastore operations in one place.
type UserFilter ¶
UserFilter provides fields for filtering the users.
type UserId ¶
type UserId struct {
Uid string
}
UserId is the 'id' type for user collection. Uid is primary key or object identifier in the database.
type UserUpdater ¶
type UserUpdater struct {
Username string
}
UserUpdater provides fields for updating users.