Replace pgx.NamedArgs to pgx.StrictNamedArgs

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-02 08:48:52 +01:00
parent 75c2813578
commit cf12d3966e
15 changed files with 49 additions and 49 deletions

View File

@@ -88,7 +88,7 @@ LIMIT @cursor_limit
` `
} }
func (c *Cursor) SQLArguments() pgx.NamedArgs { func (c *Cursor) SQLArguments() pgx.StrictNamedArgs {
var size = c.Size var size = c.Size
if c.Key == nil { if c.Key == nil {
size += 1 size += 1
@@ -96,7 +96,7 @@ func (c *Cursor) SQLArguments() pgx.NamedArgs {
size += 2 size += 2
} }
arguments := pgx.NamedArgs{ arguments := pgx.StrictNamedArgs{
"cursor_order": c.Position.ToDirection(), "cursor_order": c.Position.ToDirection(),
"cursor_limit": size, "cursor_limit": size,
"cursor_from_id": nil, "cursor_from_id": nil,

View File

@@ -100,7 +100,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"control_id": controlID} args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -148,7 +148,7 @@ VALUES (
); );
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"control_id": c.ID, "control_id": c.ID,
"framework_id": c.FrameworkID, "framework_id": c.FrameworkID,
"category": c.Category, "category": c.Category,
@@ -205,7 +205,7 @@ WHERE
` `
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"framework_id": frameworkID} args := pgx.StrictNamedArgs{"framework_id": frameworkID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
@@ -265,7 +265,7 @@ RETURNING
` `
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"control_id": c.ID, "control_id": c.ID,
"expected_version": params.ExpectedVersion, "expected_version": params.ExpectedVersion,
"updated_at": time.Now(), "updated_at": time.Now(),

View File

@@ -65,7 +65,7 @@ VALUES (
); );
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"control_state_transition_id": cst.ID, "control_state_transition_id": cst.ID,
"control_id": cst.ControlID, "control_id": cst.ControlID,
"from_state": cst.FromState, "from_state": cst.FromState,
@@ -104,7 +104,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"control_id": controlID} args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)

View File

@@ -74,7 +74,7 @@ VALUES (
) )
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"evidence_id": e.ID, "evidence_id": e.ID,
"task_id": e.TaskID, "task_id": e.TaskID,
"object_key": e.ObjectKey, "object_key": e.ObjectKey,
@@ -132,7 +132,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"evidence_id": evidenceID} args := pgx.StrictNamedArgs{"evidence_id": evidenceID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -193,7 +193,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"task_id": taskID} args := pgx.StrictNamedArgs{"task_id": taskID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
@@ -227,7 +227,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"evidence_id": e.ID} args := pgx.StrictNamedArgs{"evidence_id": e.ID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args) _, err := conn.Exec(ctx, q, args)

View File

@@ -65,7 +65,7 @@ VALUES (
); );
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"evidence_state_transition_id": est.ID, "evidence_state_transition_id": est.ID,
"evidence_id": est.EvidenceID, "evidence_id": est.EvidenceID,
"from_state": est.FromState, "from_state": est.FromState,
@@ -104,7 +104,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"evidence_id": evidenceID} args := pgx.StrictNamedArgs{"evidence_id": evidenceID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -138,7 +138,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"evidence_id": evidenceID} args := pgx.StrictNamedArgs{"evidence_id": evidenceID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args) _, err := conn.Exec(ctx, q, args)

View File

@@ -78,7 +78,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"organization_id": organizationID} args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
@@ -123,7 +123,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"framework_id": frameworkID} args := pgx.StrictNamedArgs{"framework_id": frameworkID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
if err != nil { if err != nil {
@@ -168,7 +168,7 @@ VALUES (
); );
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"framework_id": f.ID, "framework_id": f.ID,
"organization_id": f.OrganizationID, "organization_id": f.OrganizationID,
"name": f.Name, "name": f.Name,
@@ -196,7 +196,7 @@ WHERE
AND id = @framework_id; AND id = @framework_id;
` `
args := pgx.NamedArgs{"framework_id": f.ID} args := pgx.StrictNamedArgs{"framework_id": f.ID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
@@ -231,7 +231,7 @@ RETURNING
` `
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"framework_id": f.ID, "framework_id": f.ID,
"expected_version": params.ExpectedVersion, "expected_version": params.ExpectedVersion,
"updated_at": time.Now(), "updated_at": time.Now(),

View File

@@ -58,7 +58,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"organization_id": organizationID} args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -90,7 +90,7 @@ INSERT INTO organizations (
) VALUES (@id, @name, @logo_url, @created_at, @updated_at) ) VALUES (@id, @name, @logo_url, @created_at, @updated_at)
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"id": o.ID, "id": o.ID,
"name": o.Name, "name": o.Name,
"logo_url": o.LogoURL, "logo_url": o.LogoURL,

View File

@@ -81,7 +81,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"people_id": peopleID} args := pgx.StrictNamedArgs{"people_id": peopleID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -129,7 +129,7 @@ VALUES (
) )
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"people_id": p.ID, "people_id": p.ID,
"organization_id": p.OrganizationID, "organization_id": p.OrganizationID,
"kind": p.Kind, "kind": p.Kind,
@@ -155,7 +155,7 @@ DELETE FROM peoples WHERE %s AND id = @people_id
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"people_id": p.ID} args := pgx.StrictNamedArgs{"people_id": p.ID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args) _, err := conn.Exec(ctx, q, args)
@@ -190,7 +190,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"organization_id": organizationID} args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
@@ -239,7 +239,7 @@ RETURNING
` `
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"people_id": p.ID, "people_id": p.ID,
"expected_version": params.ExpectedVersion, "expected_version": params.ExpectedVersion,
"updated_at": time.Now(), "updated_at": time.Now(),

View File

@@ -26,8 +26,8 @@ func NewScope() *Scope {
return &Scope{} return &Scope{}
} }
func (*Scope) SQLArguments() pgx.NamedArgs { func (*Scope) SQLArguments() pgx.StrictNamedArgs {
return pgx.NamedArgs{} return pgx.StrictNamedArgs{}
} }
func (*Scope) SQLFragment() string { func (*Scope) SQLFragment() string {

View File

@@ -106,7 +106,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"task_id": taskID} args := pgx.StrictNamedArgs{"task_id": taskID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -160,7 +160,7 @@ VALUES (
); );
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"task_id": t.ID, "task_id": t.ID,
"control_id": t.ControlID, "control_id": t.ControlID,
"name": t.Name, "name": t.Name,
@@ -231,7 +231,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"control_id": controlID} args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
@@ -288,7 +288,7 @@ SELECT
` `
q = fmt.Sprintf(q, scope.SQLFragment(), scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), scope.SQLFragment())
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"task_id": t.ID, "task_id": t.ID,
"control_id": t.ControlID, "control_id": t.ControlID,
} }

View File

@@ -64,7 +64,7 @@ VALUES (
); );
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"task_state_transition_id": tst.ID, "task_state_transition_id": tst.ID,
"task_id": tst.TaskID, "task_id": tst.TaskID,
"from_state": tst.FromState, "from_state": tst.FromState,
@@ -103,7 +103,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"task_id": taskID} args := pgx.StrictNamedArgs{"task_id": taskID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)

View File

@@ -99,7 +99,7 @@ LIMIT 1;
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"vendor_id": vendorID} args := pgx.StrictNamedArgs{"vendor_id": vendorID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
@@ -158,7 +158,7 @@ VALUES (
) )
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"vendor_id": v.ID, "vendor_id": v.ID,
"organization_id": v.OrganizationID, "organization_id": v.OrganizationID,
"name": v.Name, "name": v.Name,
@@ -188,7 +188,7 @@ DELETE FROM vendors WHERE %s AND id = @vendor_id
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"vendor_id": v.ID} args := pgx.StrictNamedArgs{"vendor_id": v.ID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args) _, err := conn.Exec(ctx, q, args)
@@ -228,7 +228,7 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
args := pgx.NamedArgs{"organization_id": organizationID} args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, cursor.SQLArguments()) maps.Copy(args, cursor.SQLArguments())
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
@@ -287,7 +287,7 @@ RETURNING
` `
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"vendor_id": v.ID, "vendor_id": v.ID,
"expected_version": params.ExpectedVersion, "expected_version": params.ExpectedVersion,
"updated_at": time.Now(), "updated_at": time.Now(),

View File

@@ -58,7 +58,7 @@ WHERE
LIMIT 1; LIMIT 1;
` `
args := pgx.NamedArgs{"session_id": sessionID} args := pgx.StrictNamedArgs{"session_id": sessionID}
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
if err != nil { if err != nil {
@@ -90,7 +90,7 @@ VALUES (
) )
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"session_id": s.ID, "session_id": s.ID,
"user_id": s.UserID, "user_id": s.UserID,
"expired_at": s.ExpiredAt, "expired_at": s.ExpiredAt,
@@ -115,7 +115,7 @@ WHERE
id = @session_id id = @session_id
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"session_id": s.ID, "session_id": s.ID,
"expired_at": s.ExpiredAt, "expired_at": s.ExpiredAt,
"updated_at": s.UpdatedAt, "updated_at": s.UpdatedAt,
@@ -137,7 +137,7 @@ WHERE
id = @session_id id = @session_id
` `
args := pgx.NamedArgs{"session_id": sessionID} args := pgx.StrictNamedArgs{"session_id": sessionID}
_, err := conn.Exec(ctx, q, args) _, err := conn.Exec(ctx, q, args)
return err return err

View File

@@ -62,7 +62,7 @@ WHERE
LIMIT 1; LIMIT 1;
` `
args := pgx.NamedArgs{"user_email": email} args := pgx.StrictNamedArgs{"user_email": email}
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
if err != nil { if err != nil {
@@ -100,7 +100,7 @@ WHERE
LIMIT 1; LIMIT 1;
` `
args := pgx.NamedArgs{"user_id": userID} args := pgx.StrictNamedArgs{"user_id": userID}
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
if err != nil { if err != nil {
@@ -135,7 +135,7 @@ VALUES (
) )
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"user_id": u.ID, "user_id": u.ID,
"email_address": u.EmailAddress, "email_address": u.EmailAddress,
"hashed_password": u.HashedPassword, "hashed_password": u.HashedPassword,

View File

@@ -337,7 +337,7 @@ WHERE
user_id = @user_id; user_id = @user_id;
` `
args := pgx.NamedArgs{"user_id": userID} args := pgx.StrictNamedArgs{"user_id": userID}
var organizationIDs []gid.GID var organizationIDs []gid.GID
@@ -387,7 +387,7 @@ VALUES
ON CONFLICT (user_id, organization_id) DO NOTHING; ON CONFLICT (user_id, organization_id) DO NOTHING;
` `
args := pgx.NamedArgs{ args := pgx.StrictNamedArgs{
"user_id": userID, "user_id": userID,
"organization_id": organizationID, "organization_id": organizationID,
} }