queries

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSettingByGroup added in v0.1.9

func GetSettingByGroup[T any](ctx context.Context, db *Base) (*T, error)

GetSettingByGroup is a generic function that retrieves a setting from the database. It takes a context and a pointer to the Base struct which holds the database methods. The function returns a pointer to the requested setting of type T or an error if any occurs.

func New added in v0.1.5

func New(embed embed.FS) (err error)

New initializes the application's database and returns an error if any occurs during the process. It takes an 'embed.FS' which represents the file system intended to be used with embedded files.

Types

type AuthQueries

type AuthQueries struct {
	*sql.DB
}

AuthQueries is a struct that embeds *sql.DB to provide database functionality. This structure can be used to create methods that will execute SQL queries related to authentication.

func (*AuthQueries) GetPasswordByEmail

func (q *AuthQueries) GetPasswordByEmail(ctx context.Context, email string) (string, error)

GetPasswordByEmail retrieves the password for a user by their email.

type Base

Define the structure 'Base' that aggregates various queries related to different modules like settings, authentication, installation, pages, products, and cart management.

func DB

func DB() *Base

DB is a function that ensures a singleton instance of 'Base' is always returned. If 'db' is not already initialized, it initializes it before returning.

type CartQueries

type CartQueries struct {
	*sql.DB
}

CartQueries is a struct that embeds a pointer to an sql.DB. This allows for direct access to all the methods of sql.DB through CartQueries.

func (*CartQueries) AddCart

func (q *CartQueries) AddCart(ctx context.Context, cart *models.Cart) error

AddCart inserts a new cart into the database.

func (*CartQueries) Cart added in v0.1.5

func (q *CartQueries) Cart(ctx context.Context, cartId string) (*models.Cart, error)

Cart retrieves a cart from the database using the provided cartId.

func (*CartQueries) CartLetterPayment added in v0.1.9

func (q *CartQueries) CartLetterPayment(ctx context.Context, email, amountPayment, paymentURL string) (*models.MessageMail, error)

CartLetterPayment is ...

func (*CartQueries) CartLetterPurchase added in v0.1.9

func (q *CartQueries) CartLetterPurchase(ctx context.Context, cartID string) (*models.MessageMail, error)

CartLetterPurchase is ...

func (*CartQueries) Carts

func (q *CartQueries) Carts(ctx context.Context) ([]*models.Cart, error)

Carts retrieves a list of carts from the database.

func (*CartQueries) PaymentList added in v0.1.5

func (q *CartQueries) PaymentList(ctx context.Context) (map[string]bool, error)

PaymentList retrieves the status of different payment methods from the database.

func (*CartQueries) UpdateCart

func (q *CartQueries) UpdateCart(ctx context.Context, cart *models.Cart) error

UpdateCart updates the cart details in the database.

type InstallQueries

type InstallQueries struct {
	*sql.DB
}

InstallQueries is a struct that embeds a pointer to an sql.DB. This allows for the struct to have all the methods of sql.DB, enabling it to perform database operations directly.

func (*InstallQueries) Install

func (q *InstallQueries) Install(ctx context.Context, i *models.Install) error

Install performs the installation process for the cart system.

type PageQueries

type PageQueries struct {
	*sql.DB
}

PageQueries is a struct that embeds a pointer to an sql.DB. This allows for direct access to database methods on the PageQueries struct, effectively extending it with all the methods of *sql.DB.

func (*PageQueries) AddPage

func (q *PageQueries) AddPage(ctx context.Context, page *models.Page) (*models.Page, error)

AddPage inserts a new page into the database and returns the created page or an error.

func (*PageQueries) DeletePage

func (q *PageQueries) DeletePage(ctx context.Context, id string) error

DeletePage method belongs to the PageQueries struct. This method is responsible for deleting a page from the database.

func (*PageQueries) IsPage

func (q *PageQueries) IsPage(ctx context.Context, slug string) bool

IsPage checks if a page with the given slug exists in the database. It uses the context provided for any query-related timeouts or cancellations.

func (*PageQueries) ListPages

func (q *PageQueries) ListPages(ctx context.Context, private bool, idList ...string) ([]models.Page, error)

ListPages retrieves a list of pages from the database. It filters out private pages unless `private` is set to true, and can also filter by a list of page IDs if provided.

func (*PageQueries) Page

func (q *PageQueries) Page(ctx context.Context, slug string) (*models.Page, error)

Page retrieves a single page from the database based on its slug.

func (*PageQueries) UpdatePage

func (q *PageQueries) UpdatePage(ctx context.Context, page *models.Page) error

UpdatePage updates the details of a page in the database.

func (*PageQueries) UpdatePageContent

func (q *PageQueries) UpdatePageContent(ctx context.Context, page *models.Page) error

UpdatePageContent updates the content of an existing page in the database.

type ProductQueries

type ProductQueries struct {
	*sql.DB
}

ProductQueries is a struct that embeds a pointer to an sql.DB. This allows for direct access to the database methods via the ProductQueries struct, effectively extending it with all the functionality of *sql.DB.

func (*ProductQueries) AddDigitalData

func (q *ProductQueries) AddDigitalData(ctx context.Context, productID, content string) (*models.Data, error)

AddDigitalData adds a new digital data record associated with a product.

func (*ProductQueries) AddDigitalFile

func (q *ProductQueries) AddDigitalFile(ctx context.Context, productID, fileUUID, fileExt, origName string) (*models.File, error)

AddDigitalFile associates a digital file with a product in the database.

func (*ProductQueries) AddImage

func (q *ProductQueries) AddImage(ctx context.Context, productID, fileUUID, fileExt, origName string) (*models.File, error)

AddImage attaches an image to a product by inserting a new record in the product_image table.

func (*ProductQueries) AddProduct

func (q *ProductQueries) AddProduct(ctx context.Context, product *models.Product) (*models.Product, error)

AddProduct inserts a new product into the database and returns the product with the created timestamp.

func (*ProductQueries) DeleteDigital

func (q *ProductQueries) DeleteDigital(ctx context.Context, productID, digitalID string) error

func (*ProductQueries) DeleteImage

func (q *ProductQueries) DeleteImage(ctx context.Context, productID, imageID string) error

DeleteImage handles the deletion of a product image.

func (*ProductQueries) DeleteProduct

func (q *ProductQueries) DeleteProduct(ctx context.Context, id string) error

DeleteProduct removes a product from the database based on its ID.

func (*ProductQueries) IsProduct

func (q *ProductQueries) IsProduct(ctx context.Context, slug string) bool

IsProduct checks if a product with the given slug exists and is active, and also has associated digital data or file that meets certain conditions.

func (*ProductQueries) ListProducts

func (q *ProductQueries) ListProducts(ctx context.Context, private bool, idList ...models.CartProduct) (*models.Products, error)

ListProducts retrieves a list of products from the database.

func (*ProductQueries) Product

func (q *ProductQueries) Product(ctx context.Context, private bool, id string) (*models.Product, error)

Product retrieves a product by its ID, with the option to fetch private or public data.

func (*ProductQueries) ProductDigital

func (q *ProductQueries) ProductDigital(ctx context.Context, productID string) (*models.Digital, error)

ProductDigital retrieves the digital content associated with a given product ID.

func (*ProductQueries) ProductImages

func (q *ProductQueries) ProductImages(ctx context.Context, id string) (*[]models.File, error)

ProductImages retrieves a list of images associated with a given product ID.

func (*ProductQueries) UpdateActive

func (q *ProductQueries) UpdateActive(ctx context.Context, id string) error

UpdateActive toggles the 'active' status of a product and updates its 'updated' timestamp. It takes a context and an ID as arguments, and returns an error if the operation fails.

func (*ProductQueries) UpdateDigital

func (q *ProductQueries) UpdateDigital(ctx context.Context, digital *models.Data) error

UpdateDigital updates the content of a digital data record in the database.

func (*ProductQueries) UpdatePageActive

func (q *ProductQueries) UpdatePageActive(ctx context.Context, id string) error

UpdatePageActive toggles the active status of a page with the given ID. It updates the 'active' field to its logical negation (i.e., if it was true, it becomes false and vice versa)

func (*ProductQueries) UpdateProduct

func (q *ProductQueries) UpdateProduct(ctx context.Context, product *models.Product) error

UpdateProduct updates an existing product in the database with new values.

type SettingQueries

type SettingQueries struct {
	*sql.DB
}

SettingQueries wraps a sql.DB connection allowing for easy querying and interaction with the database related to application settings.

func (*SettingQueries) AddSession

func (q *SettingQueries) AddSession(ctx context.Context, key, value string, expires int64) error

AddSession is a method on the SettingQueries struct that adds a new session to the database. It takes a context, a key-value pair representing the session data, and an expiration timestamp.

func (*SettingQueries) DeleteSession

func (q *SettingQueries) DeleteSession(ctx context.Context, key string) error

DeleteSession removes a session from the database based on the provided key.

func (*SettingQueries) GetSession

func (q *SettingQueries) GetSession(ctx context.Context, key string) (string, error)

GetSession retrieves the session value for a given key if it hasn't expired. It takes a context and key as arguments and returns the session value and an error if any.

func (*SettingQueries) GetSettingByGroup added in v0.1.9

func (q *SettingQueries) GetSettingByGroup(ctx context.Context, settings any) (any, error)

GetSettingByGroup retrieves settings based on the provided `settings` struct, populating it with values from the database.

func (*SettingQueries) GetSettingByKey added in v0.1.9

func (q *SettingQueries) GetSettingByKey(ctx context.Context, key ...string) (map[string]models.SettingName, error)

GetSettingByKey retrieves a setting by its key from the database. It accepts a context for cancellation and a string representing the key of the setting. Returns a pointer to a SettingName model if found, or an error if not found or any other issue occurs.

func (*SettingQueries) GroupFieldMap added in v0.1.9

func (q *SettingQueries) GroupFieldMap(settings any) map[string]any

GroupFieldMap generates a map of fields based on the type of settings.

func (*SettingQueries) UpdatePassword added in v0.1.9

func (q *SettingQueries) UpdatePassword(ctx context.Context, password *models.Password) error

UpdatePassword updates the current user's password in the database.

func (*SettingQueries) UpdateSession

func (q *SettingQueries) UpdateSession(ctx context.Context, key, value string, expires int64) error

UpdateSession updates the session with a new value and expiration time for a given key. It takes a context, a session key, the new value to be set, and the new expiration time as arguments.

func (*SettingQueries) UpdateSettingByGroup added in v0.1.9

func (q *SettingQueries) UpdateSettingByGroup(ctx context.Context, settings any) error

UpdateSettingByGroup updates the settings in the database using a transaction. It takes a context and a settings object of any type as arguments.

func (*SettingQueries) UpdateSettingByKey added in v0.1.9

func (q *SettingQueries) UpdateSettingByKey(ctx context.Context, setting *models.SettingName) error

UpdateSettingByKey updates the value of a setting in the database based on the provided key.

Jump to

Keyboard shortcuts

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