postgres

package
v0.0.0-...-f94e68e Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCollection

func AddCollection(c *models.Collection) error

AddCollection inserts a new collection into the collections table.

func AddCollectionFilm

func AddCollectionFilm(c *models.CollectionFilm) error

AddCollectionFilm adds a film to a collection.

func AddFilm

func AddFilm(f *models.Film) error

AddFilm inserts a new film into the database and returns its ID, creation, and update timestamps.

func AddPermission

func AddPermission(code string) error

AddPermission inserts a new permission into the permissions table.

func AddUserByTelegramID

func AddUserByTelegramID(c *models.Credentials) (*models.User, error)

AddUserByTelegramID inserts a new user with telegram_id and username into the database.

func AddUserPermissions

func AddUserPermissions(userID int, codes ...string) error

AddUserPermissions adds multiple permissions for a specific user.

func AddUserWithCredentials

func AddUserWithCredentials(c *models.Credentials) (*models.User, error)

AddUserWithCredentials inserts a new user with a username and password into the database.

func CloseDB

func CloseDB()

func DeleteCollection

func DeleteCollection(id int) error

DeleteCollection removes a collection by its ID.

func DeleteCollectionFilm

func DeleteCollectionFilm(c *models.CollectionFilm) error

DeleteCollectionFilm removes a film from a collection by collection ID and film ID.

func DeleteFilm

func DeleteFilm(id int) error

DeleteFilm removes a film by its ID.

func DeletePermissions

func DeletePermissions(codes ...string) error

DeletePermissions deletes permission codes.

func DeleteUser

func DeleteUser(id int) error

DeleteUser removes a user from the database by their ID.

func GetCollection

func GetCollection(collectionID int) (*models.Collection, error)

GetCollection retrieves a collection by its ID.

func GetCollectionFilm

func GetCollectionFilm(c *models.CollectionFilm) error

GetCollectionFilm retrieves the association of a film in a collection by collection ID and film ID.

func GetCollectionFilms

func GetCollectionFilms(c *models.CollectionFilms, input *models.FilmsQueryInput) (filters.Metadata, error)

GetCollectionFilms retrieves all films in a collection with optional pagination and sorting.

func GetCollections

func GetCollections(userID int, name string, filmID int, excludeFilmID int, f filters.Filters) ([]*models.Collection, filters.Metadata, error)

GetCollections retrieves collections for a user with optional filtering and pagination.

func GetDB

func GetDB() *sql.DB

func GetFilm

func GetFilm(id int) (*models.Film, error)

GetFilm retrieves a film by its ID.

func GetFilms

func GetFilms(userID int, input *models.FilmsQueryInput) ([]models.Film, filters.Metadata, error)

GetFilms retrieves films for a specific user based on filters and pagination.

func GetIdFromRefreshToken

func GetIdFromRefreshToken(refreshToken string) (int, error)

GetIdFromRefreshToken retrieves the user ID associated with a refresh token.

func GetUserById

func GetUserById(id int) (*models.User, error)

GetUserById retrieves a user by their ID.

func GetUserByTelegramID

func GetUserByTelegramID(telegramID int) (*models.User, error)

GetUserByTelegramID retrieves a user by their telegram ID.

func GetUserByUsername

func GetUserByUsername(username string) (*models.User, error)

GetUserByUsername retrieves a user by their username.

func GetUsers

func GetUsers() ([]*models.User, error)

GetUsers retrieves all users from the database.

func IsRefreshTokenRevoked

func IsRefreshTokenRevoked(refreshToken string) (bool, error)

IsRefreshTokenRevoked checks if a refresh token has been revoked.

func IsUsernameExists

func IsUsernameExists(username string) bool

func OpenDB

func OpenDB()

OpenDB opens a PostgreSQL database connection and applies any pending migrations. It initializes a connection using the DSN from `config.Dsn`, verifies the connection with a ping, and applies migrations if a path is specified in `config.Migrations`.

func PingDB

func PingDB() error

func RevokeRefreshToken

func RevokeRefreshToken(refreshToken string) error

RevokeRefreshToken marks a refresh token as revoked in the database.

func SaveRefreshToken

func SaveRefreshToken(refreshToken string, userID int, expiresAt time.Time) error

SaveRefreshToken stores a refresh token, its associated user ID, and its expiration time in the database.

func UpdateCollection

func UpdateCollection(c *models.Collection) error

UpdateCollection updates an existing collection's details.

func UpdateCollectionFilm

func UpdateCollectionFilm(c *models.CollectionFilm) error

UpdateCollectionFilm updates the association of a film in a collection.

func UpdateFilm

func UpdateFilm(film *models.Film) error

UpdateFilm updates the details of an existing film.

func UpdateUser

func UpdateUser(u *models.User) error

UpdateUser updates a user's details based on their ID and version.

Types

type Permissions

type Permissions []string

Permissions represents a slice of permission codes.

func GetUserPermissions

func GetUserPermissions(userID int) (Permissions, error)

GetUserPermissions retrieves all permission codes for a specific user.

func (Permissions) Include

func (p Permissions) Include(code string) bool

Include checks if a given permission code is present in the Permissions slice.

Jump to

Keyboard shortcuts

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