Files
tasks/common/persistence/sql/sqlplugin/sqlite/task_v1.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

98 lines
2.5 KiB
Go

package sqlite
import (
"context"
"database/sql"
"go.temporal.io/api/serviceerror"
"github.com/hanzoai/tasks/common/persistence/sql/sqlplugin"
)
const (
getTaskMinMaxQry = `SELECT task_id, data, data_encoding ` +
`FROM tasks ` +
`WHERE range_hash = ? AND task_queue_id = ? AND task_id >= ? AND task_id < ? ` +
` ORDER BY task_id LIMIT ?`
getTaskMinQry = `SELECT task_id, data, data_encoding ` +
`FROM tasks ` +
`WHERE range_hash = ? AND task_queue_id = ? AND task_id >= ? ORDER BY task_id LIMIT ?`
createTaskQry = `INSERT INTO ` +
`tasks(range_hash, task_queue_id, task_id, data, data_encoding) ` +
`VALUES(:range_hash, :task_queue_id, :task_id, :data, :data_encoding)`
// deleteTaskQry = `DELETE FROM tasks ` +
// `WHERE range_hash = ? AND task_queue_id = ? AND task_id = ?`
rangeDeleteTaskQry = `DELETE FROM tasks ` +
`WHERE range_hash = ? AND task_queue_id = ? AND task_id IN (SELECT task_id FROM
tasks WHERE range_hash = ? AND task_queue_id = ? AND task_id < ? ` +
`ORDER BY task_queue_id,task_id LIMIT ? ) `
)
// InsertIntoTasks inserts one or more rows into tasks table
func (mdb *db) InsertIntoTasks(
ctx context.Context,
rows []sqlplugin.TasksRow,
) (sql.Result, error) {
return mdb.conn.NamedExecContext(ctx,
createTaskQry,
rows,
)
}
// SelectFromTasks reads one or more rows from tasks table
func (mdb *db) SelectFromTasks(
ctx context.Context,
filter sqlplugin.TasksFilter,
) ([]sqlplugin.TasksRow, error) {
var err error
var rows []sqlplugin.TasksRow
switch {
case filter.ExclusiveMaxTaskID != nil:
err = mdb.conn.SelectContext(ctx,
&rows, getTaskMinMaxQry,
filter.RangeHash,
filter.TaskQueueID,
*filter.InclusiveMinTaskID,
*filter.ExclusiveMaxTaskID,
*filter.PageSize,
)
default:
err = mdb.conn.SelectContext(ctx,
&rows, getTaskMinQry,
filter.RangeHash,
filter.TaskQueueID,
*filter.ExclusiveMaxTaskID,
*filter.PageSize,
)
}
if err != nil {
return nil, err
}
return rows, nil
}
// DeleteFromTasks deletes one or more rows from tasks table
func (mdb *db) DeleteFromTasks(
ctx context.Context,
filter sqlplugin.TasksFilter,
) (sql.Result, error) {
if filter.ExclusiveMaxTaskID == nil {
return nil, serviceerror.NewInternal("missing ExclusiveMaxTaskID parameter")
}
if filter.Limit == nil || *filter.Limit == 0 {
return nil, serviceerror.NewInternal("missing limit parameter")
}
return mdb.conn.ExecContext(ctx,
rangeDeleteTaskQry,
filter.RangeHash,
filter.TaskQueueID,
filter.RangeHash,
filter.TaskQueueID,
*filter.ExclusiveMaxTaskID,
*filter.Limit,
)
}