database

package
v0.0.0-...-2f68d35 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Insert(ctx context.Context, value interface{}) error
	Update(ctx context.Context, key string, value interface{}) error
	Delete(ctx context.Context, key string) error
	Get(ctx context.Context, key string, result interface{}) error
	GetAll(ctx context.Context, model interface{}, limit, offset int) ([]interface{}, error)
}

Database interface defines the operations for any database (Insert, Update, Delete, Get, and GetAll)

type PostgresDatabase

type PostgresDatabase struct {
	// contains filtered or unexported fields
}

PostgresDatabase struct represents a connection to a PostgreSQL database

func InitPostgres

func InitPostgres(addr, user, password, dbName string) (*PostgresDatabase, error)

InitPostgres initializes the PostgreSQL connection and ensures the connection is active

func NewPostgresDatabase

func NewPostgresDatabase(addr, user, password, dbName string) (*PostgresDatabase, error)

func (*PostgresDatabase) Close

func (p *PostgresDatabase) Close() error

func (*PostgresDatabase) Delete

func (p *PostgresDatabase) Delete(ctx context.Context, key string, model interface{}) error

Delete implements the Delete method of the Database interface Delete implements the Delete method of the Database interface

func (*PostgresDatabase) Get

func (p *PostgresDatabase) Get(ctx context.Context, key string, result interface{}) error

Get implements the Get method of the Database interface

func (*PostgresDatabase) GetAll

func (p *PostgresDatabase) GetAll(ctx context.Context, model interface{}, limit, offset int) ([]interface{}, error)

GetAll retrieves all records of the given model with optional pagination

func (*PostgresDatabase) Insert

func (p *PostgresDatabase) Insert(ctx context.Context, value interface{}) error

Insert implements the Insert method of the Database interface

func (*PostgresDatabase) Update

func (p *PostgresDatabase) Update(ctx context.Context, key string, value interface{}) error

Update implements the Update method of the Database interface

Jump to

Keyboard shortcuts

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