database

package
v0.0.0-...-ba70d0f Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

Storage repository

Documentation

Overview

Package database provides the database interface.

Index

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

func (db *Database[T, ID]) Count(ctx context.Context) (int64, error)

Count returns the total number of entities from the search layer (Elasticsearch).

func (*Database[T, ID]) Create

func (db *Database[T, ID]) Create(ctx context.Context, entity T) (T, error)

Create inserts a new entity into both storage (PostgresSQL) and search (Elasticsearch). If Elasticsearch fails after PostgresSQL succeeds,

func (*Database[T, ID]) Delete

func (db *Database[T, ID]) Delete(ctx context.Context, id ID) error

Delete removes an entity from both storage (PostgresSQL) and search (Elasticsearch). If Elasticsearch fails after PostgresSQL succeeds,

func (*Database[T, ID]) Exists

func (db *Database[T, ID]) Exists(ctx context.Context, id ID) (bool, error)

Exists checks if an entity exists in the search layer (Elasticsearch).

func (*Database[T, ID]) Get

func (db *Database[T, ID]) Get(ctx context.Context, id ID) (T, error)

Get retrieves an entity by ID from the search layer (Elasticsearch).

func (*Database[T, ID]) GetAll

func (db *Database[T, ID]) GetAll(ctx context.Context) ([]T, error)

GetAll retrieves all entities from the search layer (Elasticsearch).

func (*Database[T, ID]) Update

func (db *Database[T, ID]) Update(ctx context.Context, id ID, entity T) (T, error)

Update modifies an existing entity in both storage (PostgresSQL) and search (Elasticsearch).If Elasticsearch fails after PostgresSQL succeeds,

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.

Jump to

Keyboard shortcuts

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