Add backup service with CRUD operations

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-07-20 18:37:24 -06:00
parent cdf4115096
commit 2469221bde
11 changed files with 116 additions and 0 deletions
+13
View File
@@ -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,
}
}
+13
View File
@@ -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 *;
+13
View File
@@ -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;
+14
View File
@@ -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)
}
+3
View File
@@ -0,0 +1,3 @@
-- name: BackupsServiceGetBackup :one
SELECT * FROM backups
WHERE id = @id;
+13
View File
@@ -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;
+13
View File
@@ -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 *;