233 lines
5.7 KiB
Go
233 lines
5.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: price_inquiries.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const countPriceInquiries = `-- name: CountPriceInquiries :one
|
|
SELECT COUNT(*) FROM price_inquiries
|
|
WHERE (
|
|
?1 = ''
|
|
OR province LIKE '%' || ?1 || '%'
|
|
OR city LIKE '%' || ?1 || '%'
|
|
OR district LIKE '%' || ?1 || '%'
|
|
)
|
|
AND (?2 = '' OR phone LIKE '%' || ?2 || '%')
|
|
AND (?3 = '' OR status = ?3)
|
|
AND (
|
|
(?4 = '' AND ?5 = '')
|
|
OR (
|
|
(?4 = '' OR created_at >= ?4 || ' 00:00:00')
|
|
AND (?5 = '' OR created_at <= ?5 || ' 23:59:59')
|
|
)
|
|
OR (
|
|
(?4 = '' OR updated_at >= ?4 || ' 00:00:00')
|
|
AND (?5 = '' OR updated_at <= ?5 || ' 23:59:59')
|
|
)
|
|
OR (
|
|
(?4 = '' OR last_submitted_at >= ?4 || ' 00:00:00')
|
|
AND (?5 = '' OR last_submitted_at <= ?5 || ' 23:59:59')
|
|
)
|
|
)
|
|
`
|
|
|
|
type CountPriceInquiriesParams struct {
|
|
Area interface{} `json:"area"`
|
|
Phone interface{} `json:"phone"`
|
|
Status interface{} `json:"status"`
|
|
TimeFrom interface{} `json:"time_from"`
|
|
TimeTo interface{} `json:"time_to"`
|
|
}
|
|
|
|
func (q *Queries) CountPriceInquiries(ctx context.Context, arg CountPriceInquiriesParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countPriceInquiries,
|
|
arg.Area,
|
|
arg.Phone,
|
|
arg.Status,
|
|
arg.TimeFrom,
|
|
arg.TimeTo,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const listPriceInquiries = `-- name: ListPriceInquiries :many
|
|
SELECT id, user_id, phone, province, city, district, project_name, status, remark, last_submitted_at, created_at, updated_at FROM price_inquiries
|
|
WHERE (
|
|
?1 = ''
|
|
OR province LIKE '%' || ?1 || '%'
|
|
OR city LIKE '%' || ?1 || '%'
|
|
OR district LIKE '%' || ?1 || '%'
|
|
)
|
|
AND (?2 = '' OR phone LIKE '%' || ?2 || '%')
|
|
AND (?3 = '' OR status = ?3)
|
|
AND (
|
|
(?4 = '' AND ?5 = '')
|
|
OR (
|
|
(?4 = '' OR created_at >= ?4 || ' 00:00:00')
|
|
AND (?5 = '' OR created_at <= ?5 || ' 23:59:59')
|
|
)
|
|
OR (
|
|
(?4 = '' OR updated_at >= ?4 || ' 00:00:00')
|
|
AND (?5 = '' OR updated_at <= ?5 || ' 23:59:59')
|
|
)
|
|
OR (
|
|
(?4 = '' OR last_submitted_at >= ?4 || ' 00:00:00')
|
|
AND (?5 = '' OR last_submitted_at <= ?5 || ' 23:59:59')
|
|
)
|
|
)
|
|
ORDER BY last_submitted_at DESC, updated_at DESC, created_at DESC
|
|
LIMIT ?7 OFFSET ?6
|
|
`
|
|
|
|
type ListPriceInquiriesParams struct {
|
|
Area interface{} `json:"area"`
|
|
Phone interface{} `json:"phone"`
|
|
Status interface{} `json:"status"`
|
|
TimeFrom interface{} `json:"time_from"`
|
|
TimeTo interface{} `json:"time_to"`
|
|
Offset int64 `json:"offset"`
|
|
Limit int64 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListPriceInquiries(ctx context.Context, arg ListPriceInquiriesParams) ([]PriceInquiry, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPriceInquiries,
|
|
arg.Area,
|
|
arg.Phone,
|
|
arg.Status,
|
|
arg.TimeFrom,
|
|
arg.TimeTo,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []PriceInquiry
|
|
for rows.Next() {
|
|
var i PriceInquiry
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Phone,
|
|
&i.Province,
|
|
&i.City,
|
|
&i.District,
|
|
&i.ProjectName,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.LastSubmittedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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 updatePriceInquiry = `-- name: UpdatePriceInquiry :one
|
|
UPDATE price_inquiries
|
|
SET status = ?, remark = ?, updated_at = STRFTIME('%Y-%m-%d %H:%M:%f', 'now', '+8 hours')
|
|
WHERE id = ?
|
|
RETURNING id, user_id, phone, province, city, district, project_name, status, remark, last_submitted_at, created_at, updated_at
|
|
`
|
|
|
|
type UpdatePriceInquiryParams struct {
|
|
Status string `json:"status"`
|
|
Remark string `json:"remark"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePriceInquiry(ctx context.Context, arg UpdatePriceInquiryParams) (PriceInquiry, error) {
|
|
row := q.db.QueryRowContext(ctx, updatePriceInquiry, arg.Status, arg.Remark, arg.ID)
|
|
var i PriceInquiry
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Phone,
|
|
&i.Province,
|
|
&i.City,
|
|
&i.District,
|
|
&i.ProjectName,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.LastSubmittedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const upsertPriceInquiry = `-- name: UpsertPriceInquiry :one
|
|
INSERT INTO price_inquiries (
|
|
id, user_id, phone, province, city, district, project_name, status,
|
|
last_submitted_at, created_at, updated_at
|
|
)
|
|
VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?,
|
|
STRFTIME('%Y-%m-%d %H:%M:%f', 'now', '+8 hours'),
|
|
STRFTIME('%Y-%m-%d %H:%M:%f', 'now', '+8 hours'),
|
|
STRFTIME('%Y-%m-%d %H:%M:%f', 'now', '+8 hours')
|
|
)
|
|
ON CONFLICT(phone) DO UPDATE SET
|
|
last_submitted_at = STRFTIME('%Y-%m-%d %H:%M:%f', 'now', '+8 hours'),
|
|
updated_at = STRFTIME('%Y-%m-%d %H:%M:%f', 'now', '+8 hours')
|
|
RETURNING id, user_id, phone, province, city, district, project_name, status, remark, last_submitted_at, created_at, updated_at
|
|
`
|
|
|
|
type UpsertPriceInquiryParams struct {
|
|
ID string `json:"id"`
|
|
UserID sql.NullString `json:"user_id"`
|
|
Phone string `json:"phone"`
|
|
Province string `json:"province"`
|
|
City string `json:"city"`
|
|
District string `json:"district"`
|
|
ProjectName string `json:"project_name"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpsertPriceInquiry(ctx context.Context, arg UpsertPriceInquiryParams) (PriceInquiry, error) {
|
|
row := q.db.QueryRowContext(ctx, upsertPriceInquiry,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.Phone,
|
|
arg.Province,
|
|
arg.City,
|
|
arg.District,
|
|
arg.ProjectName,
|
|
arg.Status,
|
|
)
|
|
var i PriceInquiry
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Phone,
|
|
&i.Province,
|
|
&i.City,
|
|
&i.District,
|
|
&i.ProjectName,
|
|
&i.Status,
|
|
&i.Remark,
|
|
&i.LastSubmittedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|