Files
tasks/common/persistence/sql/sqlplugin/postgresql/nexus_endpoints.go
T
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

95 lines
2.7 KiB
Go

package postgresql
import (
"context"
"database/sql"
"errors"
"go.temporal.io/server/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
}