Documentation
¶
Overview ¶
Package database provides the database interface.
Index ¶
- type Database
- func (db *Database[T, ID]) Count(ctx context.Context) (int64, error)
- func (db *Database[T, ID]) Create(ctx context.Context, entity T) (T, error)
- func (db *Database[T, ID]) Delete(ctx context.Context, id ID) error
- func (db *Database[T, ID]) Exists(ctx context.Context, id ID) (bool, error)
- func (db *Database[T, ID]) Get(ctx context.Context, id ID) (T, error)
- func (db *Database[T, ID]) GetAll(ctx context.Context) ([]T, error)
- func (db *Database[T, ID]) Update(ctx context.Context, id ID, entity T) (T, error)
- type Repository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database[T any, ID comparable] struct { // contains filtered or unexported fields }
Database multilayer with postgres & elasticsearch
func (*Database[T, ID]) Count ¶
Count returns the total number of entities from the search layer (Elasticsearch).
func (*Database[T, ID]) Create ¶
Create inserts a new entity into both storage (PostgresSQL) and search (Elasticsearch). If Elasticsearch fails after PostgresSQL succeeds,
func (*Database[T, ID]) Delete ¶
Delete removes an entity from both storage (PostgresSQL) and search (Elasticsearch). If Elasticsearch fails after PostgresSQL succeeds,
func (*Database[T, ID]) Exists ¶
Exists checks if an entity exists in the search layer (Elasticsearch).
type Repository ¶
type Repository[T any, ID comparable] interface { Create(ctx context.Context, entity T) (T, error) Get(ctx context.Context, id ID) (T, error) GetAll(ctx context.Context) ([]T, error) Update(ctx context.Context, id ID, entity T) (T, error) Delete(ctx context.Context, id ID) error Exists(ctx context.Context, id ID) (bool, error) Count(ctx context.Context) (int64, error) }
Repository provides the interface for the database.
func New ¶
func New[T any, ID comparable]( searchLayer Repository[T, ID], storageLayer Repository[T, ID]) Repository[T, ID]
New create multi-layer database instance
Directories
¶
| Path | Synopsis |
|---|---|
|
Package es provides an implementation of the database using elasticsearch.
|
Package es provides an implementation of the database using elasticsearch. |
|
Package internal not share external module
|
Package internal not share external module |
|
Package kv implement key-value storage base on postgresql
|
Package kv implement key-value storage base on postgresql |
|
Package sql provides an implementation of the database using PostgreSQL.
|
Package sql provides an implementation of the database using PostgreSQL. |
Click to show internal directories.
Click to hide internal directories.