Merged in feature/client (pull request #31)
Client Entity * repolevel * servicefunctions * openapiclientget * openapiupdate * client * vendor
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: client.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createClient = `-- name: CreateClient :one
|
||||
INSERT INTO clients (name) VALUES ($1) RETURNING id
|
||||
`
|
||||
|
||||
// CreateClient
|
||||
//
|
||||
// INSERT INTO clients (name) VALUES ($1) RETURNING id
|
||||
func (q *Queries) CreateClient(ctx context.Context, name string) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createClient, name)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getClient = `-- name: GetClient :one
|
||||
SELECT id, name, canSync FROM clients WHERE id = $1
|
||||
`
|
||||
|
||||
// GetClient
|
||||
//
|
||||
// SELECT id, name, canSync FROM clients WHERE id = $1
|
||||
func (q *Queries) GetClient(ctx context.Context, id pgtype.UUID) (*Client, error) {
|
||||
row := q.db.QueryRow(ctx, getClient, id)
|
||||
var i Client
|
||||
err := row.Scan(&i.ID, &i.Name, &i.Cansync)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const updateClient = `-- name: UpdateClient :exec
|
||||
UPDATE clients SET name = $1, canSync = $2 WHERE id = $3
|
||||
`
|
||||
|
||||
type UpdateClientParams struct {
|
||||
Name string `db:"name"`
|
||||
Cansync bool `db:"cansync"`
|
||||
ID pgtype.UUID `db:"id"`
|
||||
}
|
||||
|
||||
// UpdateClient
|
||||
//
|
||||
// UPDATE clients SET name = $1, canSync = $2 WHERE id = $3
|
||||
func (q *Queries) UpdateClient(ctx context.Context, arg *UpdateClientParams) error {
|
||||
_, err := q.db.Exec(ctx, updateClient, arg.Name, arg.Cansync, arg.ID)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
|
||||
id, err := queries.CreateClient(ctx, "example_client")
|
||||
assert.Nil(t, err)
|
||||
assert.NotEmpty(t, id)
|
||||
|
||||
client, err := queries.GetClient(ctx, id)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, &repository.Client{
|
||||
ID: id,
|
||||
Name: "example_client",
|
||||
Cansync: false,
|
||||
}, client)
|
||||
|
||||
err = queries.UpdateClient(ctx, &repository.UpdateClientParams{
|
||||
ID: id,
|
||||
Name: "updated_client",
|
||||
Cansync: true,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
client, err = queries.GetClient(ctx, id)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, &repository.Client{
|
||||
ID: id,
|
||||
Name: "updated_client",
|
||||
Cansync: true,
|
||||
}, client)
|
||||
}
|
||||
@@ -49,25 +49,25 @@ func TestCollector(t *testing.T) {
|
||||
|
||||
coll, err := queries.GetCollector(ctx, collId)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, repository.Fullactivecollector{
|
||||
assert.EqualExportedValues(t, &repository.Fullactivecollector{
|
||||
ID: collId,
|
||||
Jobid: jobId,
|
||||
Mincleanversion: minCleanVersion,
|
||||
Mintextversion: minTextVersion,
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
}, *coll)
|
||||
}, coll)
|
||||
|
||||
coll, err = queries.GetCollectorByJobID(ctx, jobId)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, repository.Fullactivecollector{
|
||||
assert.EqualExportedValues(t, &repository.Fullactivecollector{
|
||||
ID: collId,
|
||||
Jobid: jobId,
|
||||
Mincleanversion: minCleanVersion,
|
||||
Mintextversion: minTextVersion,
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
}, *coll)
|
||||
}, coll)
|
||||
|
||||
err = queries.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
||||
Collectorid: collId,
|
||||
@@ -79,7 +79,7 @@ func TestCollector(t *testing.T) {
|
||||
|
||||
coll, err = queries.GetCollector(ctx, collId)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, repository.Fullactivecollector{
|
||||
assert.EqualExportedValues(t, &repository.Fullactivecollector{
|
||||
ID: collId,
|
||||
Jobid: jobId,
|
||||
Mincleanversion: minCleanVersion,
|
||||
@@ -87,7 +87,7 @@ func TestCollector(t *testing.T) {
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\": \"%s\"}", database.MustToUUID(jsonId).String())),
|
||||
}, *coll)
|
||||
}, coll)
|
||||
|
||||
qs, err := queries.ListCollectorQueries(ctx, collId)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -68,6 +68,12 @@ type Activecollectorswithrequiredid struct {
|
||||
Queryids interface{} `db:"queryids"`
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Name string `db:"name"`
|
||||
Cansync bool `db:"cansync"`
|
||||
}
|
||||
|
||||
type Collector struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Jobid pgtype.UUID `db:"jobid"`
|
||||
@@ -128,13 +134,6 @@ type Queryconfig struct {
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
}
|
||||
|
||||
type Querydeprecation struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Time pgtype.Timestamp `db:"time"`
|
||||
Removedat pgtype.Timestamp `db:"removedat"`
|
||||
}
|
||||
|
||||
type Requiredquery struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
|
||||
@@ -79,18 +79,6 @@ func (q *Queries) CreateQuery(ctx context.Context, type_ Querytype) (pgtype.UUID
|
||||
return id, err
|
||||
}
|
||||
|
||||
const deprecateQuery = `-- name: DeprecateQuery :exec
|
||||
INSERT INTO queryDeprecations (queryId) VALUES ($1)
|
||||
`
|
||||
|
||||
// DeprecateQuery
|
||||
//
|
||||
// INSERT INTO queryDeprecations (queryId) VALUES ($1)
|
||||
func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deprecateQuery, queryid)
|
||||
return err
|
||||
}
|
||||
|
||||
const getQuery = `-- name: GetQuery :one
|
||||
SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries WHERE id = $1
|
||||
`
|
||||
@@ -136,24 +124,6 @@ func (q *Queries) GetQueryConfig(ctx context.Context, arg *GetQueryConfigParams)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const isQueryDeprecated = `-- name: IsQueryDeprecated :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is null LIMIT 1
|
||||
)
|
||||
`
|
||||
|
||||
// IsQueryDeprecated
|
||||
//
|
||||
// SELECT EXISTS (
|
||||
// SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is null LIMIT 1
|
||||
// )
|
||||
func (q *Queries) IsQueryDeprecated(ctx context.Context, queryid pgtype.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, isQueryDeprecated, queryid)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
return exists, err
|
||||
}
|
||||
|
||||
const listQueries = `-- name: ListQueries :many
|
||||
SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries
|
||||
`
|
||||
|
||||
@@ -35,14 +35,14 @@ func TestQueries(t *testing.T) {
|
||||
|
||||
jsonQuery, err := queries.GetQuery(ctx, jsonQueryID)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, repository.Fullactivequery{
|
||||
assert.EqualExportedValues(t, &repository.Fullactivequery{
|
||||
ID: jsonQueryID,
|
||||
Type: repository.QuerytypeJsonExtractor,
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{database.MustToDBUUID(uuid.Nil)},
|
||||
}, *jsonQuery)
|
||||
}, jsonQuery)
|
||||
|
||||
err = queries.UpdateQuery(ctx, &repository.UpdateQueryParams{
|
||||
Latestversion: 2,
|
||||
@@ -97,14 +97,14 @@ func TestQueries(t *testing.T) {
|
||||
|
||||
jsonQuery, err = queries.GetQuery(ctx, jsonQueryID)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, repository.Fullactivequery{
|
||||
assert.EqualExportedValues(t, &repository.Fullactivequery{
|
||||
ID: jsonQueryID,
|
||||
Type: repository.QuerytypeJsonExtractor,
|
||||
Activeversion: 1,
|
||||
Latestversion: 2,
|
||||
Config: jsonConfig,
|
||||
Requiredids: []pgtype.UUID{contextQueryID},
|
||||
}, *jsonQuery)
|
||||
}, jsonQuery)
|
||||
|
||||
err = queries.UpdateQuery(ctx, &repository.UpdateQueryParams{
|
||||
Activeversion: 2,
|
||||
@@ -115,14 +115,14 @@ func TestQueries(t *testing.T) {
|
||||
|
||||
jsonQuery, err = queries.GetQuery(ctx, jsonQueryID)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, repository.Fullactivequery{
|
||||
assert.EqualExportedValues(t, &repository.Fullactivequery{
|
||||
ID: jsonQueryID,
|
||||
Type: repository.QuerytypeJsonExtractor,
|
||||
Activeversion: 2,
|
||||
Latestversion: 2,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{database.MustToDBUUID(uuid.Nil)},
|
||||
}, *jsonQuery)
|
||||
}, jsonQuery)
|
||||
|
||||
all_exist, err := queries.AllQueriesExist(ctx, []pgtype.UUID{})
|
||||
assert.Nil(t, err)
|
||||
@@ -143,17 +143,6 @@ func TestQueries(t *testing.T) {
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []pgtype.UUID{jsonQueryID, database.MustToDBUUID(uuid.New())})
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, all_exist)
|
||||
|
||||
isDeprecated, err := queries.IsQueryDeprecated(ctx, jsonQueryID)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, isDeprecated)
|
||||
|
||||
err = queries.DeprecateQuery(ctx, jsonQueryID)
|
||||
assert.Nil(t, err)
|
||||
|
||||
isDeprecated, err = queries.IsQueryDeprecated(ctx, jsonQueryID)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, isDeprecated)
|
||||
}
|
||||
|
||||
func TestQueriesList(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user