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).
93 lines
2.7 KiB
Go
93 lines
2.7 KiB
Go
package sqlite
|
|
|
|
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 = ? WHERE version = ?`
|
|
getEndpointsTableVersionQry = `SELECT version FROM nexus_endpoints_partition_status`
|
|
|
|
createEndpointQry = `INSERT INTO nexus_endpoints(id, data, data_encoding, version) VALUES (?, ?, ?, 1)`
|
|
updateEndpointQry = `UPDATE nexus_endpoints SET data = ?, data_encoding = ?, version = ? WHERE id = ? AND version = ?`
|
|
deleteEndpointQry = `DELETE FROM nexus_endpoints WHERE id = ?`
|
|
getEndpointByIdQry = `SELECT id, data, data_encoding, version FROM nexus_endpoints WHERE id = ?`
|
|
getEndpointsQry = `SELECT id, data, data_encoding, version FROM nexus_endpoints WHERE id > ? LIMIT ?`
|
|
)
|
|
|
|
func (mdb *db) InitializeNexusEndpointsTableVersion(ctx context.Context) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(ctx, createEndpointsTableVersionQry)
|
|
}
|
|
|
|
func (mdb *db) IncrementNexusEndpointsTableVersion(
|
|
ctx context.Context,
|
|
lastKnownTableVersion int64,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(ctx, incrementEndpointsTableVersionQry, lastKnownTableVersion+1, lastKnownTableVersion)
|
|
}
|
|
|
|
func (mdb *db) GetNexusEndpointsTableVersion(ctx context.Context) (int64, error) {
|
|
var version int64
|
|
err := mdb.conn.GetContext(ctx, &version, getEndpointsTableVersionQry)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return 0, nil
|
|
}
|
|
return version, err
|
|
}
|
|
|
|
func (mdb *db) InsertIntoNexusEndpoints(
|
|
ctx context.Context,
|
|
row *sqlplugin.NexusEndpointsRow,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(
|
|
ctx,
|
|
createEndpointQry,
|
|
row.ID,
|
|
row.Data,
|
|
row.DataEncoding)
|
|
}
|
|
|
|
func (mdb *db) UpdateNexusEndpoint(
|
|
ctx context.Context,
|
|
row *sqlplugin.NexusEndpointsRow,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(
|
|
ctx,
|
|
updateEndpointQry,
|
|
row.Data,
|
|
row.DataEncoding,
|
|
row.Version+1,
|
|
row.ID,
|
|
row.Version)
|
|
}
|
|
|
|
func (mdb *db) DeleteFromNexusEndpoints(
|
|
ctx context.Context,
|
|
id []byte,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(ctx, deleteEndpointQry, id)
|
|
}
|
|
|
|
func (mdb *db) GetNexusEndpointByID(
|
|
ctx context.Context,
|
|
id []byte,
|
|
) (*sqlplugin.NexusEndpointsRow, error) {
|
|
var row sqlplugin.NexusEndpointsRow
|
|
err := mdb.conn.GetContext(ctx, &row, getEndpointByIdQry, id)
|
|
return &row, err
|
|
}
|
|
|
|
func (mdb *db) ListNexusEndpoints(
|
|
ctx context.Context,
|
|
request *sqlplugin.ListNexusEndpointsRequest,
|
|
) ([]sqlplugin.NexusEndpointsRow, error) {
|
|
var rows []sqlplugin.NexusEndpointsRow
|
|
err := mdb.conn.SelectContext(ctx, &rows, getEndpointsQry, request.LastID, request.Limit)
|
|
return rows, err
|
|
}
|