database

package
v0.0.0-...-b7b9879 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 13 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan(structMap map[string]any, fields []string, scan ScanFunc) error

Types

type InMemoryKV

type InMemoryKV[K int, V any] struct {
	// contains filtered or unexported fields
}

func NewInMemoryKV

func NewInMemoryKV[K int, V any]() *InMemoryKV[K, V]

func (*InMemoryKV[K, V]) Delete

func (kv *InMemoryKV[K, V]) Delete(key K) error

func (*InMemoryKV[K, V]) Get

func (kv *InMemoryKV[K, V]) Get(key K) (V, error)

func (*InMemoryKV[K, V]) Set

func (kv *InMemoryKV[K, V]) Set(key K, val V) error

type Model

type Model interface {
	// Primary returns the name of the column used as the primary key for the Model, and the value for that column if any.
	Primary() (string, any)
	// Scan the given fields using the ScanFunc.
	Scan(fields []string, scan ScanFunc) error
	// Params return the parameters of the Model to be used during create and update operations.
	Params() map[string]any
}

type MongoDB

type MongoDB[T any] struct {
	Client       *mongo.Client
	DatabaseName string
}

func NewMongoDB

func NewMongoDB[T any]() (MongoDB[T], error)

NewMongoDB takes an env file and returns mongo client

func (*MongoDB[T]) All

func (m *MongoDB[T]) All(ctx context.Context, collectionName string, opts *options.FindOptions) ([]T, error)

func (*MongoDB[T]) Count

func (m *MongoDB[T]) Count(ctx context.Context, collectionName string) (int64, error)

func (*MongoDB[T]) Delete

func (m *MongoDB[T]) Delete(ctx context.Context, collectionName string, filter bson.D, opts *options.DeleteOptions) error

func (*MongoDB[T]) Drop

func (m *MongoDB[T]) Drop(ctx context.Context, collectionName string) error

func (*MongoDB[T]) FindByID

func (m *MongoDB[T]) FindByID(ctx context.Context, collectionName string, id uuid.UUID) (T, error)

func (*MongoDB[T]) Insert

func (m *MongoDB[T]) Insert(ctx context.Context, collectionName string, document T) error

func (*MongoDB[T]) Search

func (m *MongoDB[T]) Search(ctx context.Context, collectionName string, filter bson.D, opts *options.FindOptions) ([]T, error)

func (*MongoDB[T]) Update

func (m *MongoDB[T]) Update(ctx context.Context, collectionName string, id uuid.UUID, document T) (*mongo.UpdateResult, error)

type PosgresDB

type PosgresDB[M Model] struct {
	*pgxpool.Pool
	// contains filtered or unexported fields
}

func NewPostgresDB

func NewPostgresDB[M Model](table string, new func() M) (PosgresDB[M], error)

NewPostgresDB takes a .env config file, table name and new func. .env file example

POSTGRES_HOST=postgres POSTGRES_PORT=5432 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=changeme

func (PosgresDB[M]) All

func (p PosgresDB[M]) All(ctx context.Context) (*structures.Array[M], error)

func (PosgresDB[M]) Create

func (p PosgresDB[M]) Create(ctx context.Context, m M) (any, error)

Create a new entity M in the database and return the primary key.

func (PosgresDB[M]) Delete

func (p PosgresDB[M]) Delete(ctx context.Context, m M) error

func (PosgresDB[M]) Get

func (p PosgresDB[M]) Get(ctx context.Context, opts ...query.Option) (M, bool, error)

func (PosgresDB[M]) Select

func (p PosgresDB[M]) Select(ctx context.Context, cols []string, opts ...query.Option) (*structures.Array[M], error)

func (PosgresDB[M]) Update

func (p PosgresDB[M]) Update(ctx context.Context, m M) error

type ScanFunc

type ScanFunc func(dest ...any) error

Jump to

Keyboard shortcuts

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