diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index e82d021..504438b 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -1048,9 +1048,9 @@ RETURNING p.id, p.privilegeID, p.account_id, p.privilege_name, p.amount, p.creat -- name: GetExistingContactAmo :many WITH getAmoID AS ( - SELECT AmoID FROM amoContact WHERE AccountID = $1 AND Field IN ($2) + SELECT AmoID FROM amoContact WHERE amoContact.AccountID = $1 AND amoContact.Field IN ($2) ) SELECT DISTINCT * FROM amoContact -WHERE AccountID = $1 AND AmoID IN (SELECT AmoID FROM getAmoID); +WHERE amoContact.AccountID = $1 AND amoContact.AmoID IN (SELECT AmoID FROM getAmoID); -- name: InsertContactAmo :one INSERT INTO amoContact (AccountID, AmoID, Field) VALUES ($1, $2, $3) RETURNING AmoID; diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index 7807b85..3f6b18f 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -1449,9 +1449,11 @@ func (q *Queries) GetCurrentCompany(ctx context.Context, accountid string) (Acco return i, err } -const getExistingContactAmo = `-- name: GetExistingContactAmo :one -SELECT ID, AccountID, AmoID, Field -FROM amoContact WHERE AccountID = $1 AND Field = $2 +const getExistingContactAmo = `-- name: GetExistingContactAmo :many +WITH getAmoID AS ( + SELECT AmoID FROM amoContact WHERE amoContact.AccountID = $1 AND amoContact.Field IN ($2) +) SELECT DISTINCT id, accountid, amoid, field FROM amoContact +WHERE amoContact.AccountID = $1 AND amoContact.AmoID IN (SELECT AmoID FROM getAmoID) ` type GetExistingContactAmoParams struct { @@ -1459,16 +1461,32 @@ type GetExistingContactAmoParams struct { Field string `db:"field" json:"field"` } -func (q *Queries) GetExistingContactAmo(ctx context.Context, arg GetExistingContactAmoParams) (Amocontact, error) { - row := q.db.QueryRowContext(ctx, getExistingContactAmo, arg.Accountid, arg.Field) - var i Amocontact - err := row.Scan( - &i.ID, - &i.Accountid, - &i.Amoid, - &i.Field, - ) - return i, err +func (q *Queries) GetExistingContactAmo(ctx context.Context, arg GetExistingContactAmoParams) ([]Amocontact, error) { + rows, err := q.db.QueryContext(ctx, getExistingContactAmo, arg.Accountid, arg.Field) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Amocontact + for rows.Next() { + var i Amocontact + if err := rows.Scan( + &i.ID, + &i.Accountid, + &i.Amoid, + &i.Field, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil } const getExpiredCountPrivilege = `-- name: GetExpiredCountPrivilege :many