Manager: convert storing authored jobs from gorm to sqlc
Convert the creation of new jobs & tasks in the database (which happens by storing the 'authored job' + its tasks) from gorm to sqlc.
This commit is contained in:
parent
bfe47ea394
commit
842d1ab9a4
@ -198,6 +198,10 @@ type queriesTX struct {
|
|||||||
// queries returns the SQLC Queries struct, connected to this database.
|
// queries returns the SQLC Queries struct, connected to this database.
|
||||||
// It is intended that all GORM queries will be migrated to use this interface
|
// It is intended that all GORM queries will be migrated to use this interface
|
||||||
// instead.
|
// instead.
|
||||||
|
//
|
||||||
|
// After calling this function, all queries should use this transaction until it
|
||||||
|
// is closed (either committed or rolled back). Otherwise SQLite will deadlock,
|
||||||
|
// as it will make any other query wait until this transaction is done.
|
||||||
func (db *DB) queriesWithTX() (*queriesTX, error) {
|
func (db *DB) queriesWithTX() (*queriesTX, error) {
|
||||||
sqldb, err := db.gormDB.DB()
|
sqldb, err := db.gormDB.DB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -147,44 +147,66 @@ type TaskFailure struct {
|
|||||||
// StoreJob stores an AuthoredJob and its tasks, and saves it to the database.
|
// StoreJob stores an AuthoredJob and its tasks, and saves it to the database.
|
||||||
// The job will be in 'under construction' status. It is up to the caller to transition it to its desired initial status.
|
// The job will be in 'under construction' status. It is up to the caller to transition it to its desired initial status.
|
||||||
func (db *DB) StoreAuthoredJob(ctx context.Context, authoredJob job_compilers.AuthoredJob) error {
|
func (db *DB) StoreAuthoredJob(ctx context.Context, authoredJob job_compilers.AuthoredJob) error {
|
||||||
return db.gormDB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
|
||||||
// TODO: separate conversion of struct types from storing things in the database.
|
// Run all queries in a single transaction.
|
||||||
dbJob := Job{
|
qtx, err := db.queriesWithTX()
|
||||||
UUID: authoredJob.JobID,
|
if err != nil {
|
||||||
Name: authoredJob.Name,
|
return err
|
||||||
JobType: authoredJob.JobType,
|
}
|
||||||
Status: authoredJob.Status,
|
defer qtx.rollback()
|
||||||
Priority: authoredJob.Priority,
|
|
||||||
Settings: StringInterfaceMap(authoredJob.Settings),
|
// Serialise the embedded JSON.
|
||||||
Metadata: StringStringMap(authoredJob.Metadata),
|
settings, err := json.Marshal(authoredJob.Settings)
|
||||||
Storage: JobStorageInfo{
|
if err != nil {
|
||||||
ShamanCheckoutID: authoredJob.Storage.ShamanCheckoutID,
|
return fmt.Errorf("converting job settings to JSON: %w", err)
|
||||||
},
|
}
|
||||||
|
metadata, err := json.Marshal(authoredJob.Metadata)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("converting job metadata to JSON: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the job itself.
|
||||||
|
params := sqlc.CreateJobParams{
|
||||||
|
CreatedAt: db.gormDB.NowFunc(),
|
||||||
|
UUID: authoredJob.JobID,
|
||||||
|
Name: authoredJob.Name,
|
||||||
|
JobType: authoredJob.JobType,
|
||||||
|
Priority: int64(authoredJob.Priority),
|
||||||
|
Status: string(authoredJob.Status),
|
||||||
|
Settings: settings,
|
||||||
|
Metadata: metadata,
|
||||||
|
StorageShamanCheckoutID: authoredJob.Storage.ShamanCheckoutID,
|
||||||
|
}
|
||||||
|
|
||||||
|
if authoredJob.WorkerTagUUID != "" {
|
||||||
|
dbTag, err := qtx.queries.FetchWorkerTagByUUID(ctx, authoredJob.WorkerTagUUID)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return fmt.Errorf("no worker tag %q found", authoredJob.WorkerTagUUID)
|
||||||
|
case err != nil:
|
||||||
|
return fmt.Errorf("could not find worker tag %q: %w", authoredJob.WorkerTagUUID, err)
|
||||||
}
|
}
|
||||||
|
params.WorkerTagID = sql.NullInt64{Int64: dbTag.WorkerTag.ID, Valid: true}
|
||||||
|
}
|
||||||
|
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("job", dbJob.UUID).
|
Str("job", params.UUID).
|
||||||
Str("type", dbJob.JobType).
|
Str("type", params.JobType).
|
||||||
Str("name", dbJob.Name).
|
Str("name", params.Name).
|
||||||
Str("status", string(dbJob.Status)).
|
Str("status", params.Status).
|
||||||
Msg("persistence: storing authored job")
|
Msg("persistence: storing authored job")
|
||||||
|
|
||||||
// Find and assign the worker tag.
|
jobID, err := qtx.queries.CreateJob(ctx, params)
|
||||||
if authoredJob.WorkerTagUUID != "" {
|
if err != nil {
|
||||||
dbTag, err := fetchWorkerTag(tx, authoredJob.WorkerTagUUID)
|
return jobError(err, "storing job")
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
dbJob.WorkerTagID = &dbTag.ID
|
|
||||||
dbJob.WorkerTag = dbTag
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tx.Create(&dbJob).Error; err != nil {
|
err = db.storeAuthoredJobTaks(ctx, qtx, jobID, &authoredJob)
|
||||||
return jobError(err, "storing job")
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return db.storeAuthoredJobTaks(ctx, tx, &dbJob, &authoredJob)
|
return qtx.commit()
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoreAuthoredJobTaks is a low-level function that is only used for recreating an existing job's tasks.
|
// StoreAuthoredJobTaks is a low-level function that is only used for recreating an existing job's tasks.
|
||||||
@ -194,19 +216,41 @@ func (db *DB) StoreAuthoredJobTaks(
|
|||||||
job *Job,
|
job *Job,
|
||||||
authoredJob *job_compilers.AuthoredJob,
|
authoredJob *job_compilers.AuthoredJob,
|
||||||
) error {
|
) error {
|
||||||
tx := db.gormDB.WithContext(ctx)
|
qtx, err := db.queriesWithTX()
|
||||||
return db.storeAuthoredJobTaks(ctx, tx, job, authoredJob)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer qtx.rollback()
|
||||||
|
|
||||||
|
err = db.storeAuthoredJobTaks(ctx, qtx, int64(job.ID), authoredJob)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return qtx.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// storeAuthoredJobTaks stores the tasks of the authored job.
|
||||||
|
// Note that this function does NOT commit the database transaction. That is up
|
||||||
|
// to the caller.
|
||||||
func (db *DB) storeAuthoredJobTaks(
|
func (db *DB) storeAuthoredJobTaks(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
tx *gorm.DB,
|
qtx *queriesTX,
|
||||||
dbJob *Job,
|
jobID int64,
|
||||||
authoredJob *job_compilers.AuthoredJob,
|
authoredJob *job_compilers.AuthoredJob,
|
||||||
) error {
|
) error {
|
||||||
|
type TaskInfo struct {
|
||||||
|
ID int64
|
||||||
|
UUID string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
uuidToTask := make(map[string]*Task)
|
// Give every task the same creation timestamp.
|
||||||
|
now := db.gormDB.NowFunc()
|
||||||
|
|
||||||
|
uuidToTask := make(map[string]TaskInfo)
|
||||||
for _, authoredTask := range authoredJob.Tasks {
|
for _, authoredTask := range authoredJob.Tasks {
|
||||||
|
// Marshal commands to JSON.
|
||||||
var commands []Command
|
var commands []Command
|
||||||
for _, authoredCommand := range authoredTask.Commands {
|
for _, authoredCommand := range authoredTask.Commands {
|
||||||
commands = append(commands, Command{
|
commands = append(commands, Command{
|
||||||
@ -214,31 +258,41 @@ func (db *DB) storeAuthoredJobTaks(
|
|||||||
Parameters: StringInterfaceMap(authoredCommand.Parameters),
|
Parameters: StringInterfaceMap(authoredCommand.Parameters),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
commandsJSON, err := json.Marshal(commands)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not convert commands of task %q to JSON: %w",
|
||||||
|
authoredTask.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
dbTask := Task{
|
taskParams := sqlc.CreateTaskParams{
|
||||||
Name: authoredTask.Name,
|
CreatedAt: now,
|
||||||
Type: authoredTask.Type,
|
Name: authoredTask.Name,
|
||||||
UUID: authoredTask.UUID,
|
Type: authoredTask.Type,
|
||||||
Job: dbJob,
|
UUID: authoredTask.UUID,
|
||||||
Priority: authoredTask.Priority,
|
JobID: jobID,
|
||||||
Status: api.TaskStatusQueued,
|
Priority: int64(authoredTask.Priority),
|
||||||
Commands: commands,
|
Status: string(api.TaskStatusQueued),
|
||||||
|
Commands: commandsJSON,
|
||||||
// dependencies are stored below.
|
// dependencies are stored below.
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("task", dbTask.UUID).
|
Str("task", taskParams.UUID).
|
||||||
Str("job", dbJob.UUID).
|
Str("type", taskParams.Type).
|
||||||
Str("type", dbTask.Type).
|
Str("name", taskParams.Name).
|
||||||
Str("name", dbTask.Name).
|
Str("status", string(taskParams.Status)).
|
||||||
Str("status", string(dbTask.Status)).
|
|
||||||
Msg("persistence: storing authored task")
|
Msg("persistence: storing authored task")
|
||||||
|
|
||||||
if err := tx.Create(&dbTask).Error; err != nil {
|
taskID, err := qtx.queries.CreateTask(ctx, taskParams)
|
||||||
|
if err != nil {
|
||||||
return taskError(err, "storing task: %v", err)
|
return taskError(err, "storing task: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
uuidToTask[authoredTask.UUID] = &dbTask
|
uuidToTask[authoredTask.UUID] = TaskInfo{
|
||||||
|
ID: taskID,
|
||||||
|
UUID: taskParams.UUID,
|
||||||
|
Name: taskParams.Name,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the dependencies between tasks.
|
// Store the dependencies between tasks.
|
||||||
@ -247,18 +301,27 @@ func (db *DB) storeAuthoredJobTaks(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dbTask, ok := uuidToTask[authoredTask.UUID]
|
taskInfo, ok := uuidToTask[authoredTask.UUID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return taskError(nil, "unable to find task %q in the database, even though it was just authored", authoredTask.UUID)
|
return taskError(nil, "unable to find task %q in the database, even though it was just authored", authoredTask.UUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
deps := make([]*Task, len(authoredTask.Dependencies))
|
deps := make([]*TaskInfo, len(authoredTask.Dependencies))
|
||||||
for i, t := range authoredTask.Dependencies {
|
for idx, authoredDep := range authoredTask.Dependencies {
|
||||||
depTask, ok := uuidToTask[t.UUID]
|
depTask, ok := uuidToTask[authoredDep.UUID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return taskError(nil, "finding task with UUID %q; a task depends on a task that is not part of this job", t.UUID)
|
return taskError(nil, "finding task with UUID %q; a task depends on a task that is not part of this job", authoredDep.UUID)
|
||||||
}
|
}
|
||||||
deps[i] = depTask
|
|
||||||
|
err := qtx.queries.StoreTaskDependency(ctx, sqlc.StoreTaskDependencyParams{
|
||||||
|
TaskID: taskInfo.ID,
|
||||||
|
DependencyID: depTask.ID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return taskError(err, "error storing task %q depending on task %q", authoredTask.UUID, depTask.UUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
deps[idx] = &depTask
|
||||||
}
|
}
|
||||||
|
|
||||||
if log.Debug().Enabled() {
|
if log.Debug().Enabled() {
|
||||||
@ -267,26 +330,11 @@ func (db *DB) storeAuthoredJobTaks(
|
|||||||
depNames[i] = dep.Name
|
depNames[i] = dep.Name
|
||||||
}
|
}
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("task", dbTask.UUID).
|
Str("task", taskInfo.UUID).
|
||||||
Str("name", dbTask.Name).
|
Str("name", taskInfo.Name).
|
||||||
Strs("dependencies", depNames).
|
Strs("dependencies", depNames).
|
||||||
Msg("persistence: storing authored task dependencies")
|
Msg("persistence: storing authored task dependencies")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependenciesbatchsize := 1000
|
|
||||||
for j := 0; j < len(deps); j += dependenciesbatchsize {
|
|
||||||
end := j + dependenciesbatchsize
|
|
||||||
if end > len(deps) {
|
|
||||||
end = len(deps)
|
|
||||||
}
|
|
||||||
currentDeps := deps[j:end]
|
|
||||||
dbTask.Dependencies = currentDeps
|
|
||||||
tx.Model(&dbTask).Where("UUID = ?", dbTask.UUID)
|
|
||||||
subQuery := tx.Model(dbTask).Updates(Task{Dependencies: currentDeps})
|
|
||||||
if subQuery.Error != nil {
|
|
||||||
return taskError(subQuery.Error, "error with storing dependencies of task %q issue exists in dependencies %d to %d", authoredTask.UUID, j, end)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
-- name: CreateJob :exec
|
-- name: CreateJob :execlastid
|
||||||
INSERT INTO jobs (
|
INSERT INTO jobs (
|
||||||
created_at,
|
created_at,
|
||||||
|
updated_at,
|
||||||
uuid,
|
uuid,
|
||||||
name,
|
name,
|
||||||
job_type,
|
job_type,
|
||||||
@ -10,9 +11,49 @@ INSERT INTO jobs (
|
|||||||
activity,
|
activity,
|
||||||
settings,
|
settings,
|
||||||
metadata,
|
metadata,
|
||||||
storage_shaman_checkout_id
|
storage_shaman_checkout_id,
|
||||||
|
worker_tag_id
|
||||||
)
|
)
|
||||||
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );
|
VALUES (
|
||||||
|
@created_at,
|
||||||
|
@created_at,
|
||||||
|
@uuid,
|
||||||
|
@name,
|
||||||
|
@job_type,
|
||||||
|
@priority,
|
||||||
|
@status,
|
||||||
|
@activity,
|
||||||
|
@settings,
|
||||||
|
@metadata,
|
||||||
|
@storage_shaman_checkout_id,
|
||||||
|
@worker_tag_id
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: CreateTask :execlastid
|
||||||
|
INSERT INTO tasks (
|
||||||
|
created_at,
|
||||||
|
updated_at,
|
||||||
|
uuid,
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
job_id,
|
||||||
|
priority,
|
||||||
|
status,
|
||||||
|
commands
|
||||||
|
) VALUES (
|
||||||
|
@created_at,
|
||||||
|
@created_at,
|
||||||
|
@uuid,
|
||||||
|
@name,
|
||||||
|
@type,
|
||||||
|
@job_id,
|
||||||
|
@priority,
|
||||||
|
@status,
|
||||||
|
@commands
|
||||||
|
);
|
||||||
|
|
||||||
|
-- name: StoreTaskDependency :exec
|
||||||
|
INSERT INTO task_dependencies (task_id, dependency_id) VALUES (@task_id, @dependency_id);
|
||||||
|
|
||||||
-- name: FetchJob :one
|
-- name: FetchJob :one
|
||||||
-- Fetch a job by its UUID.
|
-- Fetch a job by its UUID.
|
||||||
|
@ -63,9 +63,10 @@ func (q *Queries) CountWorkersFailingTask(ctx context.Context, taskID int64) (in
|
|||||||
return num_failed, err
|
return num_failed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const createJob = `-- name: CreateJob :exec
|
const createJob = `-- name: CreateJob :execlastid
|
||||||
INSERT INTO jobs (
|
INSERT INTO jobs (
|
||||||
created_at,
|
created_at,
|
||||||
|
updated_at,
|
||||||
uuid,
|
uuid,
|
||||||
name,
|
name,
|
||||||
job_type,
|
job_type,
|
||||||
@ -74,9 +75,23 @@ INSERT INTO jobs (
|
|||||||
activity,
|
activity,
|
||||||
settings,
|
settings,
|
||||||
metadata,
|
metadata,
|
||||||
storage_shaman_checkout_id
|
storage_shaman_checkout_id,
|
||||||
|
worker_tag_id
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
?1,
|
||||||
|
?1,
|
||||||
|
?2,
|
||||||
|
?3,
|
||||||
|
?4,
|
||||||
|
?5,
|
||||||
|
?6,
|
||||||
|
?7,
|
||||||
|
?8,
|
||||||
|
?9,
|
||||||
|
?10,
|
||||||
|
?11
|
||||||
)
|
)
|
||||||
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
|
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateJobParams struct {
|
type CreateJobParams struct {
|
||||||
@ -90,10 +105,11 @@ type CreateJobParams struct {
|
|||||||
Settings json.RawMessage
|
Settings json.RawMessage
|
||||||
Metadata json.RawMessage
|
Metadata json.RawMessage
|
||||||
StorageShamanCheckoutID string
|
StorageShamanCheckoutID string
|
||||||
|
WorkerTagID sql.NullInt64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateJob(ctx context.Context, arg CreateJobParams) error {
|
func (q *Queries) CreateJob(ctx context.Context, arg CreateJobParams) (int64, error) {
|
||||||
_, err := q.db.ExecContext(ctx, createJob,
|
result, err := q.db.ExecContext(ctx, createJob,
|
||||||
arg.CreatedAt,
|
arg.CreatedAt,
|
||||||
arg.UUID,
|
arg.UUID,
|
||||||
arg.Name,
|
arg.Name,
|
||||||
@ -104,8 +120,64 @@ func (q *Queries) CreateJob(ctx context.Context, arg CreateJobParams) error {
|
|||||||
arg.Settings,
|
arg.Settings,
|
||||||
arg.Metadata,
|
arg.Metadata,
|
||||||
arg.StorageShamanCheckoutID,
|
arg.StorageShamanCheckoutID,
|
||||||
|
arg.WorkerTagID,
|
||||||
)
|
)
|
||||||
return err
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return result.LastInsertId()
|
||||||
|
}
|
||||||
|
|
||||||
|
const createTask = `-- name: CreateTask :execlastid
|
||||||
|
INSERT INTO tasks (
|
||||||
|
created_at,
|
||||||
|
updated_at,
|
||||||
|
uuid,
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
job_id,
|
||||||
|
priority,
|
||||||
|
status,
|
||||||
|
commands
|
||||||
|
) VALUES (
|
||||||
|
?1,
|
||||||
|
?1,
|
||||||
|
?2,
|
||||||
|
?3,
|
||||||
|
?4,
|
||||||
|
?5,
|
||||||
|
?6,
|
||||||
|
?7,
|
||||||
|
?8
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateTaskParams struct {
|
||||||
|
CreatedAt time.Time
|
||||||
|
UUID string
|
||||||
|
Name string
|
||||||
|
Type string
|
||||||
|
JobID int64
|
||||||
|
Priority int64
|
||||||
|
Status string
|
||||||
|
Commands json.RawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (int64, error) {
|
||||||
|
result, err := q.db.ExecContext(ctx, createTask,
|
||||||
|
arg.CreatedAt,
|
||||||
|
arg.UUID,
|
||||||
|
arg.Name,
|
||||||
|
arg.Type,
|
||||||
|
arg.JobID,
|
||||||
|
arg.Priority,
|
||||||
|
arg.Status,
|
||||||
|
arg.Commands,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return result.LastInsertId()
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteJob = `-- name: DeleteJob :exec
|
const deleteJob = `-- name: DeleteJob :exec
|
||||||
@ -805,6 +877,20 @@ func (q *Queries) SetLastRendered(ctx context.Context, arg SetLastRenderedParams
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const storeTaskDependency = `-- name: StoreTaskDependency :exec
|
||||||
|
INSERT INTO task_dependencies (task_id, dependency_id) VALUES (?1, ?2)
|
||||||
|
`
|
||||||
|
|
||||||
|
type StoreTaskDependencyParams struct {
|
||||||
|
TaskID int64
|
||||||
|
DependencyID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) StoreTaskDependency(ctx context.Context, arg StoreTaskDependencyParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, storeTaskDependency, arg.TaskID, arg.DependencyID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const taskAssignToWorker = `-- name: TaskAssignToWorker :exec
|
const taskAssignToWorker = `-- name: TaskAssignToWorker :exec
|
||||||
UPDATE tasks SET
|
UPDATE tasks SET
|
||||||
updated_at = ?1,
|
updated_at = ?1,
|
||||||
|
@ -60,6 +60,11 @@ LEFT JOIN worker_tag_membership m ON (m.worker_tag_id = worker_tags.id)
|
|||||||
LEFT JOIN workers on (m.worker_id = workers.id)
|
LEFT JOIN workers on (m.worker_id = workers.id)
|
||||||
WHERE workers.uuid = @uuid;
|
WHERE workers.uuid = @uuid;
|
||||||
|
|
||||||
|
-- name: FetchWorkerTagByUUID :one
|
||||||
|
SELECT sqlc.embed(worker_tags)
|
||||||
|
FROM worker_tags
|
||||||
|
WHERE worker_tags.uuid = @uuid;
|
||||||
|
|
||||||
-- name: SoftDeleteWorker :execrows
|
-- name: SoftDeleteWorker :execrows
|
||||||
UPDATE workers SET deleted_at=@deleted_at
|
UPDATE workers SET deleted_at=@deleted_at
|
||||||
WHERE uuid=@uuid;
|
WHERE uuid=@uuid;
|
||||||
|
@ -129,6 +129,30 @@ func (q *Queries) FetchWorker(ctx context.Context, uuid string) (Worker, error)
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchWorkerTagByUUID = `-- name: FetchWorkerTagByUUID :one
|
||||||
|
SELECT worker_tags.id, worker_tags.created_at, worker_tags.updated_at, worker_tags.uuid, worker_tags.name, worker_tags.description
|
||||||
|
FROM worker_tags
|
||||||
|
WHERE worker_tags.uuid = ?1
|
||||||
|
`
|
||||||
|
|
||||||
|
type FetchWorkerTagByUUIDRow struct {
|
||||||
|
WorkerTag WorkerTag
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) FetchWorkerTagByUUID(ctx context.Context, uuid string) (FetchWorkerTagByUUIDRow, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, fetchWorkerTagByUUID, uuid)
|
||||||
|
var i FetchWorkerTagByUUIDRow
|
||||||
|
err := row.Scan(
|
||||||
|
&i.WorkerTag.ID,
|
||||||
|
&i.WorkerTag.CreatedAt,
|
||||||
|
&i.WorkerTag.UpdatedAt,
|
||||||
|
&i.WorkerTag.UUID,
|
||||||
|
&i.WorkerTag.Name,
|
||||||
|
&i.WorkerTag.Description,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const fetchWorkerTags = `-- name: FetchWorkerTags :many
|
const fetchWorkerTags = `-- name: FetchWorkerTags :many
|
||||||
SELECT worker_tags.id, worker_tags.created_at, worker_tags.updated_at, worker_tags.uuid, worker_tags.name, worker_tags.description
|
SELECT worker_tags.id, worker_tags.created_at, worker_tags.updated_at, worker_tags.uuid, worker_tags.name, worker_tags.description
|
||||||
FROM worker_tags
|
FROM worker_tags
|
||||||
|
Loading…
Reference in New Issue
Block a user