mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package postgresql
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
|
|
"github.com/hanzoai/tasks/common/persistence/sql/sqlplugin"
|
|
)
|
|
|
|
const (
|
|
createEndpointsTableVersionQry = `INSERT INTO nexus_endpoints_partition_status(version) VALUES(1)`
|
|
incrementEndpointsTableVersionQry = `UPDATE nexus_endpoints_partition_status SET version = $1 WHERE version = $2`
|
|
getEndpointsTableVersionQry = `SELECT version FROM nexus_endpoints_partition_status`
|
|
|
|
createEndpointQry = `INSERT INTO nexus_endpoints(id, data, data_encoding, version) VALUES ($1, $2, $3, 1)`
|
|
updateEndpointQry = `UPDATE nexus_endpoints SET data = $1, data_encoding = $2, version = $3 WHERE id = $4 AND version = $5`
|
|
deleteEndpointQry = `DELETE FROM nexus_endpoints WHERE id = $1`
|
|
getEndpointByIdQry = `SELECT id, data, data_encoding, version FROM nexus_endpoints WHERE id = $1`
|
|
getEndpointsQry = `SELECT id, data, data_encoding, version FROM nexus_endpoints WHERE id > $1 ORDER BY id LIMIT $2`
|
|
)
|
|
|
|
func (pdb *db) InitializeNexusEndpointsTableVersion(ctx context.Context) (sql.Result, error) {
|
|
return pdb.ExecContext(ctx, createEndpointsTableVersionQry)
|
|
}
|
|
|
|
func (pdb *db) IncrementNexusEndpointsTableVersion(
|
|
ctx context.Context,
|
|
lastKnownTableVersion int64,
|
|
) (sql.Result, error) {
|
|
return pdb.ExecContext(ctx, incrementEndpointsTableVersionQry, lastKnownTableVersion+1, lastKnownTableVersion)
|
|
}
|
|
|
|
func (pdb *db) GetNexusEndpointsTableVersion(
|
|
ctx context.Context,
|
|
) (int64, error) {
|
|
var version int64
|
|
err := pdb.GetContext(ctx, &version, getEndpointsTableVersionQry)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return 0, nil
|
|
}
|
|
return version, err
|
|
}
|
|
|
|
func (pdb *db) InsertIntoNexusEndpoints(
|
|
ctx context.Context,
|
|
row *sqlplugin.NexusEndpointsRow,
|
|
) (sql.Result, error) {
|
|
return pdb.ExecContext(
|
|
ctx,
|
|
createEndpointQry,
|
|
row.ID,
|
|
row.Data,
|
|
row.DataEncoding)
|
|
}
|
|
|
|
func (pdb *db) UpdateNexusEndpoint(
|
|
ctx context.Context,
|
|
row *sqlplugin.NexusEndpointsRow,
|
|
) (sql.Result, error) {
|
|
return pdb.ExecContext(
|
|
ctx,
|
|
updateEndpointQry,
|
|
row.Data,
|
|
row.DataEncoding,
|
|
row.Version+1,
|
|
row.ID,
|
|
row.Version)
|
|
}
|
|
|
|
func (pdb *db) DeleteFromNexusEndpoints(
|
|
ctx context.Context,
|
|
id []byte,
|
|
) (sql.Result, error) {
|
|
return pdb.ExecContext(ctx, deleteEndpointQry, id)
|
|
}
|
|
|
|
func (pdb *db) GetNexusEndpointByID(
|
|
ctx context.Context,
|
|
id []byte,
|
|
) (*sqlplugin.NexusEndpointsRow, error) {
|
|
var row sqlplugin.NexusEndpointsRow
|
|
err := pdb.GetContext(ctx, &row, getEndpointByIdQry, id)
|
|
return &row, err
|
|
}
|
|
|
|
func (pdb *db) ListNexusEndpoints(
|
|
ctx context.Context,
|
|
request *sqlplugin.ListNexusEndpointsRequest,
|
|
) ([]sqlplugin.NexusEndpointsRow, error) {
|
|
var rows []sqlplugin.NexusEndpointsRow
|
|
err := pdb.SelectContext(ctx, &rows, getEndpointsQry, request.LastID, request.Limit)
|
|
return rows, err
|
|
}
|