database

package
v0.0.0-...-50f59c0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver          string
	Source          string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	MigrationPath   string
}

holds database configuration

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

db.sql configuration with additional configurations

func Initialize

func Initialize(ctx context.Context, config Config) (*DB, error)

creates a new connection and applies configuration

func (*DB) Close

func (db *DB) Close() error

close the database connection

func (*DB) RunDBMigration

func (db *DB) RunDBMigration(ctx context.Context) error

applies database migrations

type Message

type Message struct {
	ID      int
	ChatID  int
	UserID  int
	Content string
	SentAt  time.Time
	IsRead  bool
}

Message represents a chat message in the system

type MessageRepository

type MessageRepository interface {
	SaveMessage(ctx context.Context, message *Message) error
	GetMessageHistory(ctx context.Context, chatID int, limit, offset int) ([]Message, error)
}

defines the interface for message storage operations

type PostgresMessageRepository

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

implements MessageRepository for PostGresSQL

func NewPostgresMessageRepository

func NewPostgresMessageRepository(db *sql.DB) *PostgresMessageRepository

creates a new instance of PostGresMessageRepository

func (*PostgresMessageRepository) Close

func (repo *PostgresMessageRepository) Close() error

closes the repository connection

func (*PostgresMessageRepository) GetMessageHistory

func (rep *PostgresMessageRepository) GetMessageHistory(ctx context.Context, chatID int, limit, offset int) ([]Message, error)

retrieves the message history for a given chat

func (*PostgresMessageRepository) SaveMessage

func (rep *PostgresMessageRepository) SaveMessage(ctx context.Context, message *Message) error

stores a new message in the database

type User

type User struct {
	ID           int64
	Username     string
	PasswordHash string
	Email        string
	CreatedBy    int64
	CreatedAt    time.Time
	UpdatedBy    int64
	UpdatedAt    time.Time
}

Jump to

Keyboard shortcuts

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