Documentation ¶
Index ¶
- func GetSettingByGroup[T any](ctx context.Context, db *Base) (*T, error)
- func New(embed embed.FS) (err error)
- type AuthQueries
- type Base
- type CartQueries
- func (q *CartQueries) AddCart(ctx context.Context, cart *models.Cart) error
- func (q *CartQueries) Cart(ctx context.Context, cartId string) (*models.Cart, error)
- func (q *CartQueries) CartLetterPayment(ctx context.Context, email, amountPayment, paymentURL string) (*models.MessageMail, error)
- func (q *CartQueries) CartLetterPurchase(ctx context.Context, cartID string) (*models.MessageMail, error)
- func (q *CartQueries) Carts(ctx context.Context) ([]*models.Cart, error)
- func (q *CartQueries) PaymentList(ctx context.Context) (map[string]bool, error)
- func (q *CartQueries) UpdateCart(ctx context.Context, cart *models.Cart) error
- type InstallQueries
- type PageQueries
- func (q *PageQueries) AddPage(ctx context.Context, page *models.Page) (*models.Page, error)
- func (q *PageQueries) DeletePage(ctx context.Context, id string) error
- func (q *PageQueries) IsPage(ctx context.Context, slug string) bool
- func (q *PageQueries) ListPages(ctx context.Context, private bool, idList ...string) ([]models.Page, error)
- func (q *PageQueries) Page(ctx context.Context, slug string) (*models.Page, error)
- func (q *PageQueries) UpdatePage(ctx context.Context, page *models.Page) error
- func (q *PageQueries) UpdatePageContent(ctx context.Context, page *models.Page) error
- type ProductQueries
- func (q *ProductQueries) AddDigitalData(ctx context.Context, productID, content string) (*models.Data, error)
- func (q *ProductQueries) AddDigitalFile(ctx context.Context, productID, fileUUID, fileExt, origName string) (*models.File, error)
- func (q *ProductQueries) AddImage(ctx context.Context, productID, fileUUID, fileExt, origName string) (*models.File, error)
- func (q *ProductQueries) AddProduct(ctx context.Context, product *models.Product) (*models.Product, error)
- func (q *ProductQueries) DeleteDigital(ctx context.Context, productID, digitalID string) error
- func (q *ProductQueries) DeleteImage(ctx context.Context, productID, imageID string) error
- func (q *ProductQueries) DeleteProduct(ctx context.Context, id string) error
- func (q *ProductQueries) IsProduct(ctx context.Context, slug string) bool
- func (q *ProductQueries) ListProducts(ctx context.Context, private bool, idList ...models.CartProduct) (*models.Products, error)
- func (q *ProductQueries) Product(ctx context.Context, private bool, id string) (*models.Product, error)
- func (q *ProductQueries) ProductDigital(ctx context.Context, productID string) (*models.Digital, error)
- func (q *ProductQueries) ProductImages(ctx context.Context, id string) (*[]models.File, error)
- func (q *ProductQueries) UpdateActive(ctx context.Context, id string) error
- func (q *ProductQueries) UpdateDigital(ctx context.Context, digital *models.Data) error
- func (q *ProductQueries) UpdatePageActive(ctx context.Context, id string) error
- func (q *ProductQueries) UpdateProduct(ctx context.Context, product *models.Product) error
- type SettingQueries
- func (q *SettingQueries) AddSession(ctx context.Context, key, value string, expires int64) error
- func (q *SettingQueries) DeleteSession(ctx context.Context, key string) error
- func (q *SettingQueries) GetSession(ctx context.Context, key string) (string, error)
- func (q *SettingQueries) GetSettingByGroup(ctx context.Context, settings any) (any, error)
- func (q *SettingQueries) GetSettingByKey(ctx context.Context, key ...string) (map[string]models.SettingName, error)
- func (q *SettingQueries) GroupFieldMap(settings any) map[string]any
- func (q *SettingQueries) UpdatePassword(ctx context.Context, password *models.Password) error
- func (q *SettingQueries) UpdateSession(ctx context.Context, key, value string, expires int64) error
- func (q *SettingQueries) UpdateSettingByGroup(ctx context.Context, settings any) error
- func (q *SettingQueries) UpdateSettingByKey(ctx context.Context, setting *models.SettingName) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSettingByGroup ¶ added in v0.1.9
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.
Types ¶
type AuthQueries ¶
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 ¶
GetPasswordByEmail retrieves the password for a user by their email.
type Base ¶
type Base struct { SettingQueries AuthQueries InstallQueries PageQueries ProductQueries CartQueries }
Define the structure 'Base' that aggregates various queries related to different modules like settings, authentication, installation, pages, products, and cart management.
type CartQueries ¶
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) Cart ¶ added in v0.1.5
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) PaymentList ¶ added in v0.1.5
PaymentList retrieves the status of different payment methods from the database.
func (*CartQueries) UpdateCart ¶
UpdateCart updates the cart details in the database.
type InstallQueries ¶
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.
type PageQueries ¶
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 ¶
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) UpdatePage ¶
UpdatePage updates the details of a page in the database.
func (*PageQueries) UpdatePageContent ¶
UpdatePageContent updates the content of an existing page in the database.
type ProductQueries ¶
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 ¶
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 ¶
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 ¶
UpdateProduct updates an existing product in the database with new values.
type SettingQueries ¶
SettingQueries wraps a sql.DB connection allowing for easy querying and interaction with the database related to application settings.
func (*SettingQueries) AddSession ¶
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 ¶
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
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
UpdatePassword updates the current user's password in the database.
func (*SettingQueries) UpdateSession ¶
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.