update sqlc gen
This commit is contained in:
parent
5f2e01f9a0
commit
9c1fb0644e
@ -167,6 +167,125 @@ func (q *Queries) CheckExpired(ctx context.Context) ([]Token, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const checkFields = `-- name: CheckFields :many
|
||||
WITH user_data AS (
|
||||
SELECT AmoID
|
||||
FROM users
|
||||
WHERE users.AccountID = $1
|
||||
)
|
||||
INSERT INTO fields (amoID, code, accountID, name, Entity, type, createdAt)
|
||||
SELECT (new_fields->>'AmoID')::INT,
|
||||
new_fields->>'Code',
|
||||
user_data.AmoID,
|
||||
new_fields->>'Name',
|
||||
CAST(new_fields->>'Entity' AS entitytype),
|
||||
new_fields->>'Type',
|
||||
CURRENT_TIMESTAMP
|
||||
FROM json_array_elements($2::json[]) AS new_fields
|
||||
JOIN user_data ON true
|
||||
ON CONFLICT (amoID, accountID, entity) DO UPDATE
|
||||
SET name = EXCLUDED.name,
|
||||
code = EXCLUDED.code,
|
||||
type = EXCLUDED.type,
|
||||
createdAt = CURRENT_TIMESTAMP
|
||||
RETURNING id, amoid, code, accountid, name, entity, type, deleted, createdat
|
||||
`
|
||||
|
||||
type CheckFieldsParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Column2 []json.RawMessage `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckFields(ctx context.Context, arg CheckFieldsParams) ([]Field, error) {
|
||||
rows, err := q.db.QueryContext(ctx, checkFields, arg.Accountid, pq.Array(arg.Column2))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Field
|
||||
for rows.Next() {
|
||||
var i Field
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Code,
|
||||
&i.Accountid,
|
||||
&i.Name,
|
||||
&i.Entity,
|
||||
&i.Type,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
); 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 checkPipelines = `-- name: CheckPipelines :many
|
||||
WITH user_data AS (
|
||||
SELECT AmoID
|
||||
FROM users
|
||||
WHERE users.AccountID = $1
|
||||
)
|
||||
INSERT INTO pipelines (amoID, accountID, name, isArchive, createdAt)
|
||||
SELECT (new_pipelines->>'AmoID')::INT,
|
||||
user_data.AmoID,
|
||||
new_pipelines->>'Name',
|
||||
new_pipelines->>'IsArchive',
|
||||
CURRENT_TIMESTAMP
|
||||
FROM json_array_elements($2::json[]) AS new_pipelines
|
||||
JOIN user_data ON true
|
||||
ON CONFLICT (amoID, accountID) DO UPDATE
|
||||
SET name = EXCLUDED.name,
|
||||
isArchive = EXCLUDED.isArchive,
|
||||
createdAt = CURRENT_TIMESTAMP
|
||||
RETURNING id, amoid, accountid, name, isarchive, deleted, createdat
|
||||
`
|
||||
|
||||
type CheckPipelinesParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Column2 []json.RawMessage `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckPipelines(ctx context.Context, arg CheckPipelinesParams) ([]Pipeline, error) {
|
||||
rows, err := q.db.QueryContext(ctx, checkPipelines, arg.Accountid, pq.Array(arg.Column2))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Pipeline
|
||||
for rows.Next() {
|
||||
var i Pipeline
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Accountid,
|
||||
&i.Name,
|
||||
&i.Isarchive,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
); 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 checkResultOwner = `-- name: CheckResultOwner :one
|
||||
SELECT q.accountid FROM answer a JOIN quiz q ON a.quiz_id = q.id WHERE a.id = $1 AND a.deleted = FALSE AND a.start = false
|
||||
`
|
||||
@ -213,6 +332,65 @@ func (q *Queries) CheckResultsOwner(ctx context.Context, arg CheckResultsOwnerPa
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const checkSteps = `-- name: CheckSteps :many
|
||||
WITH user_data AS (
|
||||
SELECT AmoID
|
||||
FROM users
|
||||
WHERE users.AccountID = $1
|
||||
)
|
||||
INSERT INTO steps (amoID,pipelineID, accountID, name, color, createdAt)
|
||||
SELECT (new_steps->>'AmoID')::INT,
|
||||
(new_steps->>'PipelineID')::INT,
|
||||
user_data.AmoID,
|
||||
new_steps->>'Name',
|
||||
new_steps->>'Color',
|
||||
CURRENT_TIMESTAMP
|
||||
FROM json_array_elements($2::json[]) AS new_steps
|
||||
JOIN user_data ON true
|
||||
ON CONFLICT (amoID, accountID, PipelineID) DO UPDATE
|
||||
SET name = EXCLUDED.name,
|
||||
color = EXCLUDED.color,
|
||||
createdAt = CURRENT_TIMESTAMP
|
||||
RETURNING id, amoid, pipelineid, accountid, name, color, deleted, createdat
|
||||
`
|
||||
|
||||
type CheckStepsParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Column2 []json.RawMessage `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckSteps(ctx context.Context, arg CheckStepsParams) ([]Step, error) {
|
||||
rows, err := q.db.QueryContext(ctx, checkSteps, arg.Accountid, pq.Array(arg.Column2))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Step
|
||||
for rows.Next() {
|
||||
var i Step
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Pipelineid,
|
||||
&i.Accountid,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
); 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 checkTags = `-- name: CheckTags :many
|
||||
WITH user_data AS (
|
||||
SELECT AmoID
|
||||
|
Loading…
Reference in New Issue
Block a user