Save information about the organization and user from ArcGIS
This commit is contained in:
parent
07d3b3ea76
commit
a08cd87813
20 changed files with 786 additions and 93 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"iter"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
|
|
@ -20,7 +21,7 @@ import (
|
|||
//go:embed oauth_by_user_id.bob.sql
|
||||
var formattedQueries_oauth_by_user_id string
|
||||
|
||||
var oauthTokenByUserIdSQL = formattedQueries_oauth_by_user_id[156:440]
|
||||
var oauthTokenByUserIdSQL = formattedQueries_oauth_by_user_id[156:550]
|
||||
|
||||
type OauthTokenByUserIdQuery = orm.ModQuery[*dialect.SelectQuery, oauthTokenByUserId, OauthTokenByUserIdRow, []OauthTokenByUserIdRow, oauthTokenByUserIdTransformer]
|
||||
|
||||
|
|
@ -47,6 +48,8 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
|
|||
row.ScheduleScanByIndex(3, &t.RefreshToken)
|
||||
row.ScheduleScanByIndex(4, &t.Username)
|
||||
row.ScheduleScanByIndex(5, &t.UserID)
|
||||
row.ScheduleScanByIndex(6, &t.ArcgisID)
|
||||
row.ScheduleScanByIndex(7, &t.ArcgisLicenseTypeID)
|
||||
return &t, nil
|
||||
}, func(v any) (OauthTokenByUserIdRow, error) {
|
||||
return *(v.(*OauthTokenByUserIdRow)), nil
|
||||
|
|
@ -54,20 +57,22 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
|
|||
},
|
||||
},
|
||||
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
|
||||
q.AppendSelect(expressionTypArgs.subExpr(7, 247))
|
||||
q.SetTable(expressionTypArgs.subExpr(253, 264))
|
||||
q.AppendWhere(expressionTypArgs.subExpr(272, 284))
|
||||
q.AppendSelect(expressionTypArgs.subExpr(7, 357))
|
||||
q.SetTable(expressionTypArgs.subExpr(363, 374))
|
||||
q.AppendWhere(expressionTypArgs.subExpr(382, 394))
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type OauthTokenByUserIdRow = struct {
|
||||
ID int32 `db:"id"`
|
||||
AccessToken string `db:"access_token"`
|
||||
Expires time.Time `db:"expires"`
|
||||
RefreshToken string `db:"refresh_token"`
|
||||
Username string `db:"username"`
|
||||
UserID int32 `db:"user_id"`
|
||||
ID int32 `db:"id"`
|
||||
AccessToken string `db:"access_token"`
|
||||
Expires time.Time `db:"expires"`
|
||||
RefreshToken string `db:"refresh_token"`
|
||||
Username string `db:"username"`
|
||||
UserID int32 `db:"user_id"`
|
||||
ArcgisID null.Val[string] `db:"arcgis_id"`
|
||||
ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id"`
|
||||
}
|
||||
|
||||
type oauthTokenByUserIdTransformer = bob.SliceTransformer[OauthTokenByUserIdRow, []OauthTokenByUserIdRow]
|
||||
|
|
@ -80,8 +85,8 @@ func (o oauthTokenByUserId) args() iter.Seq[orm.ArgWithPosition] {
|
|||
return func(yield func(arg orm.ArgWithPosition) bool) {
|
||||
if !yield(orm.ArgWithPosition{
|
||||
Name: "userID",
|
||||
Start: 282,
|
||||
Stop: 284,
|
||||
Start: 392,
|
||||
Stop: 394,
|
||||
Expression: o.UserID,
|
||||
}) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
-- This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
-- OauthTokenByUserId
|
||||
SELECT "oauth_token"."id" AS "id", "oauth_token"."access_token" AS "access_token", "oauth_token"."expires" AS "expires", "oauth_token"."refresh_token" AS "refresh_token", "oauth_token"."username" AS "username", "oauth_token"."user_id" AS "user_id" FROM oauth_token WHERE
|
||||
SELECT "oauth_token"."id" AS "id", "oauth_token"."access_token" AS "access_token", "oauth_token"."expires" AS "expires", "oauth_token"."refresh_token" AS "refresh_token", "oauth_token"."username" AS "username", "oauth_token"."user_id" AS "user_id", "oauth_token"."arcgis_id" AS "arcgis_id", "oauth_token"."arcgis_license_type_id" AS "arcgis_license_type_id" FROM oauth_token WHERE
|
||||
user_id = $1;
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ func TestOauthTokenByUserId(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(columns) != 6 {
|
||||
t.Fatalf("expected %d columns, got %d", 6, len(columns))
|
||||
if len(columns) != 8 {
|
||||
t.Fatalf("expected %d columns, got %d", 8, len(columns))
|
||||
}
|
||||
|
||||
if columns[0] != "id" {
|
||||
|
|
@ -111,5 +111,13 @@ func TestOauthTokenByUserId(t *testing.T) {
|
|||
if columns[5] != "user_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 5, "user_id", columns[5])
|
||||
}
|
||||
|
||||
if columns[6] != "arcgis_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 6, "arcgis_id", columns[6])
|
||||
}
|
||||
|
||||
if columns[7] != "arcgis_license_type_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 7, "arcgis_license_type_id", columns[7])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
95
sql/update_oauth_org.bob.go
Normal file
95
sql/update_oauth_org.bob.go
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"io"
|
||||
"iter"
|
||||
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
)
|
||||
|
||||
//go:embed update_oauth_org.bob.sql
|
||||
var formattedQueries_update_oauth_org string
|
||||
|
||||
var updateOauthTokenOrgSQL = formattedQueries_update_oauth_org[157:249]
|
||||
|
||||
type UpdateOauthTokenOrgQuery = orm.ModExecQuery[*dialect.UpdateQuery, updateOauthTokenOrg]
|
||||
|
||||
func UpdateOauthTokenOrg(ArcgisID string, ArcgisLicenseTypeID string, RefreshToken string) *UpdateOauthTokenOrgQuery {
|
||||
var expressionTypArgs updateOauthTokenOrg
|
||||
|
||||
expressionTypArgs.ArcgisID = psql.Arg(ArcgisID)
|
||||
expressionTypArgs.ArcgisLicenseTypeID = psql.Arg(ArcgisLicenseTypeID)
|
||||
expressionTypArgs.RefreshToken = psql.Arg(RefreshToken)
|
||||
|
||||
return &UpdateOauthTokenOrgQuery{
|
||||
ExecQuery: orm.ExecQuery[updateOauthTokenOrg]{
|
||||
BaseQuery: bob.BaseQuery[updateOauthTokenOrg]{
|
||||
Expression: expressionTypArgs,
|
||||
Dialect: dialect.Dialect,
|
||||
QueryType: bob.QueryTypeUpdate,
|
||||
},
|
||||
},
|
||||
Mod: bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
|
||||
q.Table.Expression = expressionTypArgs.subExpr(7, 18)
|
||||
q.AppendSet(expressionTypArgs.subExpr(23, 66))
|
||||
q.AppendWhere(expressionTypArgs.subExpr(74, 92))
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type updateOauthTokenOrg struct {
|
||||
ArcgisID bob.Expression
|
||||
ArcgisLicenseTypeID bob.Expression
|
||||
RefreshToken bob.Expression
|
||||
}
|
||||
|
||||
func (o updateOauthTokenOrg) args() iter.Seq[orm.ArgWithPosition] {
|
||||
return func(yield func(arg orm.ArgWithPosition) bool) {
|
||||
if !yield(orm.ArgWithPosition{
|
||||
Name: "arcgisID",
|
||||
Start: 35,
|
||||
Stop: 37,
|
||||
Expression: o.ArcgisID,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
|
||||
if !yield(orm.ArgWithPosition{
|
||||
Name: "arcgisLicenseTypeID",
|
||||
Start: 64,
|
||||
Stop: 66,
|
||||
Expression: o.ArcgisLicenseTypeID,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
|
||||
if !yield(orm.ArgWithPosition{
|
||||
Name: "refreshToken",
|
||||
Start: 90,
|
||||
Stop: 92,
|
||||
Expression: o.RefreshToken,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o updateOauthTokenOrg) raw(from, to int) string {
|
||||
return updateOauthTokenOrgSQL[from:to]
|
||||
}
|
||||
|
||||
func (o updateOauthTokenOrg) subExpr(from, to int) bob.Expression {
|
||||
return orm.ArgsToExpression(updateOauthTokenOrgSQL, from, to, o.args())
|
||||
}
|
||||
|
||||
func (o updateOauthTokenOrg) WriteSQL(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.subExpr(0, len(updateOauthTokenOrgSQL)).WriteSQL(ctx, w, d, start)
|
||||
}
|
||||
6
sql/update_oauth_org.bob.sql
Normal file
6
sql/update_oauth_org.bob.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-- Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
-- This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
-- UpdateOauthTokenOrg
|
||||
UPDATE oauth_token SET arcgis_id = $1, arcgis_license_type_id = $2
|
||||
WHERE refresh_token = $3;
|
||||
76
sql/update_oauth_org.bob_test.go
Normal file
76
sql/update_oauth_org.bob_test.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
testutils "github.com/stephenafamo/bob/test/utils"
|
||||
)
|
||||
|
||||
func TestUpdateOauthTokenOrg(t *testing.T) {
|
||||
t.Run("Base", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil))
|
||||
|
||||
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(updateOauthTokenOrgSQL, sb.String()); diff != "" {
|
||||
t.Fatalf("unexpected result (-got +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Mod", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil))
|
||||
|
||||
if _, err := psql.Update(query).WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queryDiff, err := testutils.QueryDiff(updateOauthTokenOrgSQL, sb.String(), formatQuery)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if queryDiff != "" {
|
||||
fmt.Println(sb.String())
|
||||
t.Fatalf("unexpected result (-got +want):\n%s", queryDiff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Exec", func(t *testing.T) {
|
||||
if testDB == nil {
|
||||
t.Skip("skipping test, no DSN provided")
|
||||
}
|
||||
|
||||
ctxTx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
|
||||
tx, err := testDB.Begin(ctxTx)
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting transaction: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := tx.Rollback(ctxTx); err != nil {
|
||||
t.Fatalf("Error rolling back transaction: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
query := psql.Update(UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil)))
|
||||
if _, err := bob.Exec(ctxTx, tx, query); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
3
sql/update_oauth_org.sql
Normal file
3
sql/update_oauth_org.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-- UpdateOauthTokenOrg
|
||||
UPDATE oauth_token SET arcgis_id = $1, arcgis_license_type_id = $2
|
||||
WHERE refresh_token = $3;
|
||||
Loading…
Add table
Add a link
Reference in a new issue