gen with sqlc
This commit is contained in:
parent
0c528d5afb
commit
670d4d88a6
@ -6,8 +6,11 @@ package sqlcgen
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/sqlc-dev/pqtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
@ -38,6 +41,28 @@ type Answer struct {
|
|||||||
Start bool `db:"start" json:"start"`
|
Start bool `db:"start" json:"start"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Field struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Code string `db:"code" json:"code"`
|
||||||
|
Accountid int32 `db:"accountid" json:"accountid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Entity interface{} `db:"entity" json:"entity"`
|
||||||
|
Type string `db:"type" json:"type"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Pipeline struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Accountid int32 `db:"accountid" json:"accountid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Isarchive sql.NullBool `db:"isarchive" json:"isarchive"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
type Privilege struct {
|
type Privilege struct {
|
||||||
ID int32 `db:"id" json:"id"`
|
ID int32 `db:"id" json:"id"`
|
||||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||||
@ -48,19 +73,21 @@ type Privilege struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Question struct {
|
type Question struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
Title string `db:"title" json:"title"`
|
Title string `db:"title" json:"title"`
|
||||||
Description sql.NullString `db:"description" json:"description"`
|
Description sql.NullString `db:"description" json:"description"`
|
||||||
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
||||||
Required sql.NullBool `db:"required" json:"required"`
|
Required sql.NullBool `db:"required" json:"required"`
|
||||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
Page sql.NullInt16 `db:"page" json:"page"`
|
Page sql.NullInt16 `db:"page" json:"page"`
|
||||||
Content sql.NullString `db:"content" json:"content"`
|
Content sql.NullString `db:"content" json:"content"`
|
||||||
Version sql.NullInt16 `db:"version" json:"version"`
|
Version sql.NullInt16 `db:"version" json:"version"`
|
||||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||||
|
Utm json.RawMessage `db:"utm" json:"utm"`
|
||||||
|
Rules json.RawMessage `db:"rules" json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Quiz struct {
|
type Quiz struct {
|
||||||
@ -94,3 +121,49 @@ type Quiz struct {
|
|||||||
AverageTimePassing sql.NullInt32 `db:"average_time_passing" json:"average_time_passing"`
|
AverageTimePassing sql.NullInt32 `db:"average_time_passing" json:"average_time_passing"`
|
||||||
SessionsCount sql.NullInt32 `db:"sessions_count" json:"sessions_count"`
|
SessionsCount sql.NullInt32 `db:"sessions_count" json:"sessions_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Step struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
||||||
|
Accountid int32 `db:"accountid" json:"accountid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Color string `db:"color" json:"color"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Accountid int32 `db:"accountid" json:"accountid"`
|
||||||
|
Entity interface{} `db:"entity" json:"entity"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Color string `db:"color" json:"color"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Token struct {
|
||||||
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
||||||
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
||||||
|
Authcode string `db:"authcode" json:"authcode"`
|
||||||
|
Expiration time.Time `db:"expiration" json:"expiration"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Email string `db:"email" json:"email"`
|
||||||
|
Role string `db:"role" json:"role"`
|
||||||
|
Group pqtype.NullRawMessage `db:"Group" json:"Group"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||||
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
|
Country string `db:"country" json:"country"`
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
|
"github.com/sqlc-dev/pqtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
const accountPagination = `-- name: AccountPagination :many
|
const accountPagination = `-- name: AccountPagination :many
|
||||||
@ -131,6 +132,40 @@ func (q *Queries) CheckAndAddDefault(ctx context.Context, arg CheckAndAddDefault
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkExpired = `-- name: CheckExpired :many
|
||||||
|
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens WHERE Expiration <= EXTRACT(EPOCH FROM NOW()) + (10 * 60)
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) CheckExpired(ctx context.Context) ([]Token, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, checkExpired)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Token
|
||||||
|
for rows.Next() {
|
||||||
|
var i Token
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.Accountid,
|
||||||
|
&i.Refreshtoken,
|
||||||
|
&i.Accesstoken,
|
||||||
|
&i.Authcode,
|
||||||
|
&i.Expiration,
|
||||||
|
&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
|
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
|
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
|
||||||
`
|
`
|
||||||
@ -177,6 +212,29 @@ func (q *Queries) CheckResultsOwner(ctx context.Context, arg CheckResultsOwnerPa
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkUsers = `-- name: CheckUsers :exec
|
||||||
|
UPDATE users SET Name = $1, "Group" = $2, Email = $3, Role = $4 WHERE AmoID = $5
|
||||||
|
`
|
||||||
|
|
||||||
|
type CheckUsersParams struct {
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Group pqtype.NullRawMessage `db:"Group" json:"Group"`
|
||||||
|
Email string `db:"email" json:"email"`
|
||||||
|
Role string `db:"role" json:"role"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CheckUsers(ctx context.Context, arg CheckUsersParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, checkUsers,
|
||||||
|
arg.Name,
|
||||||
|
arg.Group,
|
||||||
|
arg.Email,
|
||||||
|
arg.Role,
|
||||||
|
arg.Amoid,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const copyQuestion = `-- name: CopyQuestion :one
|
const copyQuestion = `-- name: CopyQuestion :one
|
||||||
INSERT INTO question(
|
INSERT INTO question(
|
||||||
quiz_id, title, description, questiontype, required,
|
quiz_id, title, description, questiontype, required,
|
||||||
@ -312,6 +370,70 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createAmoAccount = `-- name: CreateAmoAccount :exec
|
||||||
|
|
||||||
|
INSERT INTO users (AccountID, AmoID, Name, Email, Role, "Group", Deleted, CreatedAt, Subdomain, AmoUserID, Country)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateAmoAccountParams struct {
|
||||||
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
Amoid int32 `db:"amoid" json:"amoid"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Email string `db:"email" json:"email"`
|
||||||
|
Role string `db:"role" json:"role"`
|
||||||
|
Group pqtype.NullRawMessage `db:"Group" json:"Group"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||||
|
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||||
|
Country string `db:"country" json:"country"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// amo methods:
|
||||||
|
func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createAmoAccount,
|
||||||
|
arg.Accountid,
|
||||||
|
arg.Amoid,
|
||||||
|
arg.Name,
|
||||||
|
arg.Email,
|
||||||
|
arg.Role,
|
||||||
|
arg.Group,
|
||||||
|
arg.Deleted,
|
||||||
|
arg.Createdat,
|
||||||
|
arg.Subdomain,
|
||||||
|
arg.Amouserid,
|
||||||
|
arg.Country,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createWebHook = `-- name: CreateWebHook :exec
|
||||||
|
INSERT INTO tokens (AccountID, RefreshToken, AccessToken, AuthCode, Expiration, CreatedAt)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateWebHookParams struct {
|
||||||
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
||||||
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
||||||
|
Authcode string `db:"authcode" json:"authcode"`
|
||||||
|
Expiration time.Time `db:"expiration" json:"expiration"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateWebHook(ctx context.Context, arg CreateWebHookParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createWebHook,
|
||||||
|
arg.Accountid,
|
||||||
|
arg.Refreshtoken,
|
||||||
|
arg.Accesstoken,
|
||||||
|
arg.Authcode,
|
||||||
|
arg.Expiration,
|
||||||
|
arg.Createdat,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const deleteAccountById = `-- name: DeleteAccountById :exec
|
const deleteAccountById = `-- name: DeleteAccountById :exec
|
||||||
DELETE FROM account WHERE id = $1
|
DELETE FROM account WHERE id = $1
|
||||||
`
|
`
|
||||||
@ -340,7 +462,7 @@ func (q *Queries) DeletePrivilegeByID(ctx context.Context, id int32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteQuestion = `-- name: DeleteQuestion :one
|
const deleteQuestion = `-- name: DeleteQuestion :one
|
||||||
UPDATE question SET deleted=true WHERE id=$1 RETURNING question.id, question.quiz_id, question.title, question.description, question.questiontype, question.required, question.deleted, question.page, question.content, question.version, question.parent_ids, question.created_at, question.updated_at
|
UPDATE question SET deleted=true WHERE id=$1 RETURNING question.id, question.quiz_id, question.title, question.description, question.questiontype, question.required, question.deleted, question.page, question.content, question.version, question.parent_ids, question.created_at, question.updated_at, question.utm, question.rules
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error) {
|
func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error) {
|
||||||
@ -360,6 +482,8 @@ func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error
|
|||||||
pq.Array(&i.ParentIds),
|
pq.Array(&i.ParentIds),
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.Utm,
|
||||||
|
&i.Rules,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@ -857,6 +981,49 @@ func (q *Queries) GetAllAnswersByQuizID(ctx context.Context, session sql.NullStr
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAllTokens = `-- name: GetAllTokens :many
|
||||||
|
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetAllTokens(ctx context.Context) ([]Token, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getAllTokens)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Token
|
||||||
|
for rows.Next() {
|
||||||
|
var i Token
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.Accountid,
|
||||||
|
&i.Refreshtoken,
|
||||||
|
&i.Accesstoken,
|
||||||
|
&i.Authcode,
|
||||||
|
&i.Expiration,
|
||||||
|
&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 getCurrentAccount = `-- name: GetCurrentAccount :exec
|
||||||
|
SELECT id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country FROM users WHERE AccountID = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetCurrentAccount(ctx context.Context, accountid string) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, getCurrentAccount, accountid)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const getExpiredPrivilege = `-- name: GetExpiredPrivilege :many
|
const getExpiredPrivilege = `-- name: GetExpiredPrivilege :many
|
||||||
SELECT id, privilegeID, privilege_name, amount, created_at
|
SELECT id, privilegeID, privilege_name, amount, created_at
|
||||||
FROM privileges
|
FROM privileges
|
||||||
@ -1053,7 +1220,7 @@ func (q *Queries) GetQidOwner(ctx context.Context, qid uuid.NullUUID) (string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getQuestionHistory = `-- name: GetQuestionHistory :many
|
const getQuestionHistory = `-- name: GetQuestionHistory :many
|
||||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE question.id = $1 OR question.id = ANY(
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, utm, rules FROM question WHERE question.id = $1 OR question.id = ANY(
|
||||||
SELECT unnest(parent_ids) FROM question WHERE id = $1
|
SELECT unnest(parent_ids) FROM question WHERE id = $1
|
||||||
) ORDER BY question.id DESC LIMIT $2 OFFSET $3
|
) ORDER BY question.id DESC LIMIT $2 OFFSET $3
|
||||||
`
|
`
|
||||||
@ -1087,6 +1254,8 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
|||||||
pq.Array(&i.ParentIds),
|
pq.Array(&i.ParentIds),
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.Utm,
|
||||||
|
&i.Rules,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1122,15 +1291,31 @@ const getQuestions = `-- name: GetQuestions :many
|
|||||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]Question, error) {
|
type GetQuestionsRow struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
Title string `db:"title" json:"title"`
|
||||||
|
Description sql.NullString `db:"description" json:"description"`
|
||||||
|
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
||||||
|
Required sql.NullBool `db:"required" json:"required"`
|
||||||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||||
|
Page sql.NullInt16 `db:"page" json:"page"`
|
||||||
|
Content sql.NullString `db:"content" json:"content"`
|
||||||
|
Version sql.NullInt16 `db:"version" json:"version"`
|
||||||
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestionsRow, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getQuestions, quizID)
|
rows, err := q.db.QueryContext(ctx, getQuestions, quizID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var items []Question
|
var items []GetQuestionsRow
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i Question
|
var i GetQuestionsRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.QuizID,
|
&i.QuizID,
|
||||||
@ -1400,6 +1585,51 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
||||||
|
SELECT id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country FROM users ORDER BY ID OFFSET ($1 - 1) * $2 LIMIT $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetUsersWithPaginationParams struct {
|
||||||
|
Column1 interface{} `db:"column_1" json:"column_1"`
|
||||||
|
Limit int32 `db:"limit" json:"limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPaginationParams) ([]User, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getUsersWithPagination, arg.Column1, arg.Limit)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []User
|
||||||
|
for rows.Next() {
|
||||||
|
var i User
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Accountid,
|
||||||
|
&i.Amoid,
|
||||||
|
&i.Name,
|
||||||
|
&i.Email,
|
||||||
|
&i.Role,
|
||||||
|
&i.Group,
|
||||||
|
&i.Deleted,
|
||||||
|
&i.Createdat,
|
||||||
|
&i.Subdomain,
|
||||||
|
&i.Amouserid,
|
||||||
|
&i.Country,
|
||||||
|
); 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 insertAnswers = `-- name: InsertAnswers :exec
|
const insertAnswers = `-- name: InsertAnswers :exec
|
||||||
INSERT INTO answer(
|
INSERT INTO answer(
|
||||||
content,
|
content,
|
||||||
@ -1851,6 +2081,15 @@ func (q *Queries) QuizCopyQid(ctx context.Context, arg QuizCopyQidParams) (QuizC
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const softDeleteAccount = `-- name: SoftDeleteAccount :exec
|
||||||
|
UPDATE users SET Deleted = TRUE WHERE AccountID = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) SoftDeleteAccount(ctx context.Context, accountid string) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, softDeleteAccount, accountid)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const softDeleteResultByID = `-- name: SoftDeleteResultByID :exec
|
const softDeleteResultByID = `-- name: SoftDeleteResultByID :exec
|
||||||
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
||||||
`
|
`
|
||||||
@ -1895,6 +2134,38 @@ func (q *Queries) UpdatePrivilegeAmount(ctx context.Context, arg UpdatePrivilege
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const webhookDelete = `-- name: WebhookDelete :exec
|
||||||
|
DELETE FROM tokens WHERE AccountID = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) WebhookDelete(ctx context.Context, accountid string) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, webhookDelete, accountid)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const webhookUpdate = `-- name: WebhookUpdate :exec
|
||||||
|
UPDATE tokens SET AccessToken = $1, RefreshToken = $2, Expiration = $3, CreatedAt = $4 WHERE AccountID = $5
|
||||||
|
`
|
||||||
|
|
||||||
|
type WebhookUpdateParams struct {
|
||||||
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
||||||
|
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
||||||
|
Expiration time.Time `db:"expiration" json:"expiration"`
|
||||||
|
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||||
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) WebhookUpdate(ctx context.Context, arg WebhookUpdateParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, webhookUpdate,
|
||||||
|
arg.Accesstoken,
|
||||||
|
arg.Refreshtoken,
|
||||||
|
arg.Expiration,
|
||||||
|
arg.Createdat,
|
||||||
|
arg.Accountid,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const workerStatProcess = `-- name: WorkerStatProcess :exec
|
const workerStatProcess = `-- name: WorkerStatProcess :exec
|
||||||
WITH answer_aggregates AS (
|
WITH answer_aggregates AS (
|
||||||
SELECT
|
SELECT
|
||||||
|
Loading…
Reference in New Issue
Block a user