27389164b0
- Implemented image folder repository with CRUD operations. - Added image reference repository for managing image references to articles. - Created image repository for handling image assets, including listing, inserting, updating, and deleting images. - Introduced image usage repository to track storage usage and quotas for tenants. - Added SQL queries for image assets, folders, references, and usage. - Developed image handler for HTTP endpoints to manage images and folders. - Created database migration scripts for image-related tables and structures.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: image_usage.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const ensureImageStorageUsageRow = `-- name: EnsureImageStorageUsageRow :exec
|
|
INSERT INTO tenant_image_storage_usage (tenant_id, used_bytes)
|
|
VALUES ($1, 0)
|
|
ON CONFLICT (tenant_id) DO NOTHING
|
|
`
|
|
|
|
func (q *Queries) EnsureImageStorageUsageRow(ctx context.Context, tenantID int64) error {
|
|
_, err := q.db.Exec(ctx, ensureImageStorageUsageRow, tenantID)
|
|
return err
|
|
}
|
|
|
|
const getImageStorageUsage = `-- name: GetImageStorageUsage :one
|
|
SELECT used_bytes, updated_at
|
|
FROM tenant_image_storage_usage
|
|
WHERE tenant_id = $1
|
|
`
|
|
|
|
type GetImageStorageUsageRow struct {
|
|
UsedBytes int64 `json:"used_bytes"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetImageStorageUsage(ctx context.Context, tenantID int64) (GetImageStorageUsageRow, error) {
|
|
row := q.db.QueryRow(ctx, getImageStorageUsage, tenantID)
|
|
var i GetImageStorageUsageRow
|
|
err := row.Scan(&i.UsedBytes, &i.UpdatedAt)
|
|
return i, err
|
|
}
|
|
|
|
const releaseImageStorageQuota = `-- name: ReleaseImageStorageQuota :exec
|
|
UPDATE tenant_image_storage_usage
|
|
SET used_bytes = GREATEST(0, used_bytes - $1),
|
|
updated_at = NOW()
|
|
WHERE tenant_id = $2
|
|
`
|
|
|
|
type ReleaseImageStorageQuotaParams struct {
|
|
ReleaseBytes int64 `json:"release_bytes"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) ReleaseImageStorageQuota(ctx context.Context, arg ReleaseImageStorageQuotaParams) error {
|
|
_, err := q.db.Exec(ctx, releaseImageStorageQuota, arg.ReleaseBytes, arg.TenantID)
|
|
return err
|
|
}
|