mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-05-19 02:58:25 -05:00
Add backup service with CRUD operations
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package backups
|
||||
|
||||
import "github.com/eduardolat/pgbackweb/internal/database/dbgen"
|
||||
|
||||
type Service struct {
|
||||
dbgen *dbgen.Queries
|
||||
}
|
||||
|
||||
func New(dbgen *dbgen.Queries) *Service {
|
||||
return &Service{
|
||||
dbgen: dbgen,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package backups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
|
||||
)
|
||||
|
||||
func (s *Service) CreateBackup(
|
||||
ctx context.Context, params dbgen.BackupsServiceCreateBackupParams,
|
||||
) (dbgen.Backup, error) {
|
||||
return s.dbgen.BackupsServiceCreateBackup(ctx, params)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
-- name: BackupsServiceCreateBackup :one
|
||||
INSERT INTO backups (
|
||||
database_id, destination_id, name, cron_expression, is_active, dest_dir,
|
||||
opt_data_only, opt_schema_only, opt_clean, opt_if_exists, opt_create,
|
||||
opt_no_comments
|
||||
)
|
||||
VALUES (
|
||||
@database_id, @destination_id, @name, @cron_expression, @is_active, @dest_dir,
|
||||
@opt_data_only, @opt_schema_only, @opt_clean, @opt_if_exists, @opt_create,
|
||||
@opt_no_comments
|
||||
)
|
||||
RETURNING *;
|
||||
@@ -0,0 +1,13 @@
|
||||
package backups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) DeleteBackup(
|
||||
ctx context.Context, id uuid.UUID,
|
||||
) error {
|
||||
return s.dbgen.BackupsServiceDeleteBackup(ctx, id)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
-- name: BackupsServiceDeleteBackup :exec
|
||||
DELETE FROM backups
|
||||
WHERE id = @id;
|
||||
@@ -0,0 +1,14 @@
|
||||
package backups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) GetBackup(
|
||||
ctx context.Context, id uuid.UUID,
|
||||
) (dbgen.Backup, error) {
|
||||
return s.dbgen.BackupsServiceGetBackup(ctx, id)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
-- name: BackupsServiceGetBackup :one
|
||||
SELECT * FROM backups
|
||||
WHERE id = @id;
|
||||
@@ -0,0 +1,13 @@
|
||||
package backups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
|
||||
)
|
||||
|
||||
func (s *Service) ListBackups(
|
||||
ctx context.Context,
|
||||
) ([]dbgen.Backup, error) {
|
||||
return s.dbgen.BackupsServiceListBackups(ctx)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
-- name: BackupsServiceListBackups :many
|
||||
SELECT * FROM backups;
|
||||
@@ -0,0 +1,13 @@
|
||||
package backups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateBackup(
|
||||
ctx context.Context, params dbgen.BackupsServiceUpdateBackupParams,
|
||||
) (dbgen.Backup, error) {
|
||||
return s.dbgen.BackupsServiceUpdateBackup(ctx, params)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
-- name: BackupsServiceUpdateBackup :one
|
||||
UPDATE backups
|
||||
SET
|
||||
database_id = @database_id,
|
||||
destination_id = @destination_id,
|
||||
name = @name,
|
||||
cron_expression = @cron_expression,
|
||||
is_active = @is_active,
|
||||
dest_dir = @dest_dir,
|
||||
opt_data_only = @opt_data_only,
|
||||
opt_schema_only = @opt_schema_only,
|
||||
opt_clean = @opt_clean,
|
||||
opt_if_exists = @opt_if_exists,
|
||||
opt_create = @opt_create,
|
||||
opt_no_comments = @opt_no_comments
|
||||
WHERE id = @id
|
||||
RETURNING *;
|
||||
Reference in New Issue
Block a user