// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: queries.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const addSmsUsed = `-- name: AddSmsUsed :exec UPDATE tags SET sms_used = sms_used + 1, updated_at = now() WHERE id = $1 ` func (q *Queries) AddSmsUsed(ctx context.Context, id int64) error { _, err := q.db.Exec(ctx, addSmsUsed, id) return err } const bindTag = `-- name: BindTag :one UPDATE tags SET owner_id = $1, updated_at = now() WHERE tag_code = $2 AND owner_id IS NULL AND status = 'unset' RETURNING id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start ` type BindTagParams struct { OwnerID pgtype.Int8 `json:"owner_id"` TagCode string `json:"tag_code"` } func (q *Queries) BindTag(ctx context.Context, arg BindTagParams) (Tag, error) { row := q.db.QueryRow(ctx, bindTag, arg.OwnerID, arg.TagCode) var i Tag err := row.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ) return i, err } const clearTagOwner = `-- name: ClearTagOwner :one UPDATE tags SET owner_id=NULL, status='unset', item_type=NULL, description=NULL, photo_url=NULL, phone=NULL, address=NULL, notes=NULL, updated_at=now() WHERE id=$1 RETURNING id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start ` func (q *Queries) ClearTagOwner(ctx context.Context, id int64) (Tag, error) { row := q.db.QueryRow(ctx, clearTagOwner, id) var i Tag err := row.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ) return i, err } const countAlertsByAccountSince = `-- name: CountAlertsByAccountSince :one SELECT count(*) FROM scans s JOIN tags t ON t.id = s.tag_id WHERE t.owner_id = $1 AND s.alert_sent = TRUE AND s.scanned_at > $2 ` type CountAlertsByAccountSinceParams struct { OwnerID pgtype.Int8 `json:"owner_id"` ScannedAt pgtype.Timestamptz `json:"scanned_at"` } // SMS pool draw: alerts sent for any tag owned by the account in the period. func (q *Queries) CountAlertsByAccountSince(ctx context.Context, arg CountAlertsByAccountSinceParams) (int64, error) { row := q.db.QueryRow(ctx, countAlertsByAccountSince, arg.OwnerID, arg.ScannedAt) var count int64 err := row.Scan(&count) return count, err } const countAlertsByIPSince = `-- name: CountAlertsByIPSince :one SELECT count(*) FROM scans WHERE ip = $1 AND alert_sent = TRUE AND scanned_at > $2 ` type CountAlertsByIPSinceParams struct { Ip pgtype.Text `json:"ip"` ScannedAt pgtype.Timestamptz `json:"scanned_at"` } func (q *Queries) CountAlertsByIPSince(ctx context.Context, arg CountAlertsByIPSinceParams) (int64, error) { row := q.db.QueryRow(ctx, countAlertsByIPSince, arg.Ip, arg.ScannedAt) var count int64 err := row.Scan(&count) return count, err } const countAlertsByTagSince = `-- name: CountAlertsByTagSince :one SELECT count(*) FROM scans WHERE tag_id = $1 AND alert_sent = TRUE AND scanned_at > $2 ` type CountAlertsByTagSinceParams struct { TagID int64 `json:"tag_id"` ScannedAt pgtype.Timestamptz `json:"scanned_at"` } func (q *Queries) CountAlertsByTagSince(ctx context.Context, arg CountAlertsByTagSinceParams) (int64, error) { row := q.db.QueryRow(ctx, countAlertsByTagSince, arg.TagID, arg.ScannedAt) var count int64 err := row.Scan(&count) return count, err } const countOwnedTags = `-- name: CountOwnedTags :one SELECT count(*) FROM tags WHERE owner_id = $1 AND status <> 'closed' ` // Live owned-tag count for the per-account cap: everything bound to the // account except retired (closed) tags, including bound-but-unset codes. func (q *Queries) CountOwnedTags(ctx context.Context, ownerID pgtype.Int8) (int64, error) { row := q.db.QueryRow(ctx, countOwnedTags, ownerID) var count int64 err := row.Scan(&count) return count, err } const countTagsByOwner = `-- name: CountTagsByOwner :one SELECT count(*) FROM tags WHERE owner_id = $1 ` func (q *Queries) CountTagsByOwner(ctx context.Context, ownerID pgtype.Int8) (int64, error) { row := q.db.QueryRow(ctx, countTagsByOwner, ownerID) var count int64 err := row.Scan(&count) return count, err } const createUser = `-- name: CreateUser :one INSERT INTO users (email, password_hash, name, phone) VALUES ($1, $2, $3, $4) RETURNING id, email, password_hash, name, phone, created_at, is_admin, remember_token, paused, stripe_id, sms_credits ` type CreateUserParams struct { Email string `json:"email"` PasswordHash string `json:"password_hash"` Name pgtype.Text `json:"name"` Phone pgtype.Text `json:"phone"` } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { row := q.db.QueryRow(ctx, createUser, arg.Email, arg.PasswordHash, arg.Name, arg.Phone, ) var i User err := row.Scan( &i.ID, &i.Email, &i.PasswordHash, &i.Name, &i.Phone, &i.CreatedAt, &i.IsAdmin, &i.RememberToken, &i.Paused, &i.StripeID, &i.SmsCredits, ) return i, err } const getActiveOrderByAccount = `-- name: GetActiveOrderByAccount :one SELECT o.id, o.account_id, o.status, o.created_at, o.updated_at, o.amount, o.renews_at, o.stripe_id, o.pm_type, o.pm_last_four, o.trial_ends_at, o.plan_id, o.period_started_at, p.plan_type, p.price_aud, p.sms_included, p.max_tags, p.alerts_per_day, p.alerts_per_hour FROM orders o LEFT JOIN plans p ON p.id = o.plan_id WHERE o.account_id = $1 AND o.status = 'paid' ORDER BY o.id DESC LIMIT 1 ` type GetActiveOrderByAccountRow struct { ID int64 `json:"id"` AccountID pgtype.Int8 `json:"account_id"` Status string `json:"status"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` Amount pgtype.Numeric `json:"amount"` RenewsAt pgtype.Timestamptz `json:"renews_at"` StripeID pgtype.Text `json:"stripe_id"` PmType pgtype.Text `json:"pm_type"` PmLastFour pgtype.Text `json:"pm_last_four"` TrialEndsAt pgtype.Timestamptz `json:"trial_ends_at"` PlanID pgtype.Int8 `json:"plan_id"` PeriodStartedAt pgtype.Timestamptz `json:"period_started_at"` PlanType pgtype.Text `json:"plan_type"` PriceAud pgtype.Numeric `json:"price_aud"` SmsIncluded pgtype.Int4 `json:"sms_included"` MaxTags pgtype.Int4 `json:"max_tags"` AlertsPerDay pgtype.Int4 `json:"alerts_per_day"` AlertsPerHour pgtype.Int4 `json:"alerts_per_hour"` } // The account's current paid subscription order (if any), with its plan. func (q *Queries) GetActiveOrderByAccount(ctx context.Context, accountID pgtype.Int8) (GetActiveOrderByAccountRow, error) { row := q.db.QueryRow(ctx, getActiveOrderByAccount, accountID) var i GetActiveOrderByAccountRow err := row.Scan( &i.ID, &i.AccountID, &i.Status, &i.CreatedAt, &i.UpdatedAt, &i.Amount, &i.RenewsAt, &i.StripeID, &i.PmType, &i.PmLastFour, &i.TrialEndsAt, &i.PlanID, &i.PeriodStartedAt, &i.PlanType, &i.PriceAud, &i.SmsIncluded, &i.MaxTags, &i.AlertsPerDay, &i.AlertsPerHour, ) return i, err } const getActiveOrderByOwner = `-- name: GetActiveOrderByOwner :one SELECT o.id, o.account_id, o.status, o.created_at, o.updated_at, o.amount, o.renews_at, o.stripe_id, o.pm_type, o.pm_last_four, o.trial_ends_at, o.plan_id, o.period_started_at, p.plan_type, p.price_aud, p.sms_included, p.max_tags, p.alerts_per_day, p.alerts_per_hour FROM tags t JOIN orders o ON o.account_id = t.owner_id AND o.status = 'paid' LEFT JOIN plans p ON p.id = o.plan_id WHERE t.id = $1 ORDER BY o.id DESC LIMIT 1 ` type GetActiveOrderByOwnerRow struct { ID int64 `json:"id"` AccountID pgtype.Int8 `json:"account_id"` Status string `json:"status"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` Amount pgtype.Numeric `json:"amount"` RenewsAt pgtype.Timestamptz `json:"renews_at"` StripeID pgtype.Text `json:"stripe_id"` PmType pgtype.Text `json:"pm_type"` PmLastFour pgtype.Text `json:"pm_last_four"` TrialEndsAt pgtype.Timestamptz `json:"trial_ends_at"` PlanID pgtype.Int8 `json:"plan_id"` PeriodStartedAt pgtype.Timestamptz `json:"period_started_at"` PlanType pgtype.Text `json:"plan_type"` PriceAud pgtype.Numeric `json:"price_aud"` SmsIncluded pgtype.Int4 `json:"sms_included"` MaxTags pgtype.Int4 `json:"max_tags"` AlertsPerDay pgtype.Int4 `json:"alerts_per_day"` AlertsPerHour pgtype.Int4 `json:"alerts_per_hour"` } // Account-level gating for a tag: resolve the tag's owner account, then the // account's active paid subscription order (with plan). Returns zero rows // when the tag is unowned or the account has no paid order. func (q *Queries) GetActiveOrderByOwner(ctx context.Context, id int64) (GetActiveOrderByOwnerRow, error) { row := q.db.QueryRow(ctx, getActiveOrderByOwner, id) var i GetActiveOrderByOwnerRow err := row.Scan( &i.ID, &i.AccountID, &i.Status, &i.CreatedAt, &i.UpdatedAt, &i.Amount, &i.RenewsAt, &i.StripeID, &i.PmType, &i.PmLastFour, &i.TrialEndsAt, &i.PlanID, &i.PeriodStartedAt, &i.PlanType, &i.PriceAud, &i.SmsIncluded, &i.MaxTags, &i.AlertsPerDay, &i.AlertsPerHour, ) return i, err } const getLastAlertByTag = `-- name: GetLastAlertByTag :one SELECT id, tag_id, scanned_at, lat, lng, location_shared, scanner_phone, alert_sent, fingerprint, ip FROM scans WHERE tag_id = $1 AND alert_sent = TRUE ORDER BY scanned_at DESC LIMIT 1 ` func (q *Queries) GetLastAlertByTag(ctx context.Context, tagID int64) (Scan, error) { row := q.db.QueryRow(ctx, getLastAlertByTag, tagID) var i Scan err := row.Scan( &i.ID, &i.TagID, &i.ScannedAt, &i.Lat, &i.Lng, &i.LocationShared, &i.ScannerPhone, &i.AlertSent, &i.Fingerprint, &i.Ip, ) return i, err } const getLatestScanByTag = `-- name: GetLatestScanByTag :one SELECT id, tag_id, scanned_at, lat, lng, location_shared, scanner_phone, alert_sent, fingerprint, ip FROM scans WHERE tag_id = $1 ORDER BY scanned_at DESC LIMIT 1 ` func (q *Queries) GetLatestScanByTag(ctx context.Context, tagID int64) (Scan, error) { row := q.db.QueryRow(ctx, getLatestScanByTag, tagID) var i Scan err := row.Scan( &i.ID, &i.TagID, &i.ScannedAt, &i.Lat, &i.Lng, &i.LocationShared, &i.ScannerPhone, &i.AlertSent, &i.Fingerprint, &i.Ip, ) return i, err } const getOrderByID = `-- name: GetOrderByID :one SELECT id, account_id, status, created_at, updated_at, amount, renews_at, stripe_id, pm_type, pm_last_four, trial_ends_at, plan_id, period_started_at FROM orders WHERE id = $1 ` func (q *Queries) GetOrderByID(ctx context.Context, id int64) (Order, error) { row := q.db.QueryRow(ctx, getOrderByID, id) var i Order err := row.Scan( &i.ID, &i.AccountID, &i.Status, &i.CreatedAt, &i.UpdatedAt, &i.Amount, &i.RenewsAt, &i.StripeID, &i.PmType, &i.PmLastFour, &i.TrialEndsAt, &i.PlanID, &i.PeriodStartedAt, ) return i, err } const getRecentScanByFingerprint = `-- name: GetRecentScanByFingerprint :one SELECT id, tag_id, scanned_at, lat, lng, location_shared, scanner_phone, alert_sent, fingerprint, ip FROM scans WHERE fingerprint = $1 AND id <> $2 AND scanned_at > now() - interval '24 hours' ORDER BY scanned_at DESC LIMIT 1 ` type GetRecentScanByFingerprintParams struct { Fingerprint pgtype.Text `json:"fingerprint"` ID int64 `json:"id"` } func (q *Queries) GetRecentScanByFingerprint(ctx context.Context, arg GetRecentScanByFingerprintParams) (Scan, error) { row := q.db.QueryRow(ctx, getRecentScanByFingerprint, arg.Fingerprint, arg.ID) var i Scan err := row.Scan( &i.ID, &i.TagID, &i.ScannedAt, &i.Lat, &i.Lng, &i.LocationShared, &i.ScannerPhone, &i.AlertSent, &i.Fingerprint, &i.Ip, ) return i, err } const getScanByID = `-- name: GetScanByID :one SELECT id, tag_id, scanned_at, lat, lng, location_shared, scanner_phone, alert_sent, fingerprint, ip FROM scans WHERE id = $1 ` func (q *Queries) GetScanByID(ctx context.Context, id int64) (Scan, error) { row := q.db.QueryRow(ctx, getScanByID, id) var i Scan err := row.Scan( &i.ID, &i.TagID, &i.ScannedAt, &i.Lat, &i.Lng, &i.LocationShared, &i.ScannerPhone, &i.AlertSent, &i.Fingerprint, &i.Ip, ) return i, err } const getShortCode = `-- name: GetShortCode :one SELECT code, scan_id, created_at FROM url_shortened WHERE code = $1 ` func (q *Queries) GetShortCode(ctx context.Context, code string) (UrlShortened, error) { row := q.db.QueryRow(ctx, getShortCode, code) var i UrlShortened err := row.Scan(&i.Code, &i.ScanID, &i.CreatedAt) return i, err } const getTagByCode = `-- name: GetTagByCode :one SELECT id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start FROM tags WHERE tag_code = $1 ` func (q *Queries) GetTagByCode(ctx context.Context, tagCode string) (Tag, error) { row := q.db.QueryRow(ctx, getTagByCode, tagCode) var i Tag err := row.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ) return i, err } const getTagByID = `-- name: GetTagByID :one SELECT id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start FROM tags WHERE id = $1 ` func (q *Queries) GetTagByID(ctx context.Context, id int64) (Tag, error) { row := q.db.QueryRow(ctx, getTagByID, id) var i Tag err := row.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ) return i, err } const getUserByEmail = `-- name: GetUserByEmail :one SELECT id, email, password_hash, name, phone, created_at, is_admin, remember_token, paused, stripe_id, sms_credits FROM users WHERE email = $1 ` func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) { row := q.db.QueryRow(ctx, getUserByEmail, email) var i User err := row.Scan( &i.ID, &i.Email, &i.PasswordHash, &i.Name, &i.Phone, &i.CreatedAt, &i.IsAdmin, &i.RememberToken, &i.Paused, &i.StripeID, &i.SmsCredits, ) return i, err } const getUserByID = `-- name: GetUserByID :one SELECT id, email, password_hash, name, phone, created_at, is_admin, remember_token, paused, stripe_id, sms_credits FROM users WHERE id = $1 ` func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) { row := q.db.QueryRow(ctx, getUserByID, id) var i User err := row.Scan( &i.ID, &i.Email, &i.PasswordHash, &i.Name, &i.Phone, &i.CreatedAt, &i.IsAdmin, &i.RememberToken, &i.Paused, &i.StripeID, &i.SmsCredits, ) return i, err } const insertScan = `-- name: InsertScan :one INSERT INTO scans (tag_id, lat, lng, location_shared, scanner_phone, fingerprint, ip) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id, tag_id, scanned_at, lat, lng, location_shared, scanner_phone, alert_sent, fingerprint, ip ` type InsertScanParams struct { TagID int64 `json:"tag_id"` Lat pgtype.Float8 `json:"lat"` Lng pgtype.Float8 `json:"lng"` LocationShared bool `json:"location_shared"` ScannerPhone pgtype.Text `json:"scanner_phone"` Fingerprint pgtype.Text `json:"fingerprint"` Ip pgtype.Text `json:"ip"` } func (q *Queries) InsertScan(ctx context.Context, arg InsertScanParams) (Scan, error) { row := q.db.QueryRow(ctx, insertScan, arg.TagID, arg.Lat, arg.Lng, arg.LocationShared, arg.ScannerPhone, arg.Fingerprint, arg.Ip, ) var i Scan err := row.Scan( &i.ID, &i.TagID, &i.ScannedAt, &i.Lat, &i.Lng, &i.LocationShared, &i.ScannerPhone, &i.AlertSent, &i.Fingerprint, &i.Ip, ) return i, err } const insertShortCode = `-- name: InsertShortCode :one INSERT INTO url_shortened (code, scan_id) VALUES ($1, $2) RETURNING code, scan_id, created_at ` type InsertShortCodeParams struct { Code string `json:"code"` ScanID int64 `json:"scan_id"` } func (q *Queries) InsertShortCode(ctx context.Context, arg InsertShortCodeParams) (UrlShortened, error) { row := q.db.QueryRow(ctx, insertShortCode, arg.Code, arg.ScanID) var i UrlShortened err := row.Scan(&i.Code, &i.ScanID, &i.CreatedAt) return i, err } const insertTag = `-- name: InsertTag :one INSERT INTO tags (tag_code) VALUES ($1) RETURNING id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start ` func (q *Queries) InsertTag(ctx context.Context, tagCode string) (Tag, error) { row := q.db.QueryRow(ctx, insertTag, tagCode) var i Tag err := row.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ) return i, err } const listRecentScansWithTag = `-- name: ListRecentScansWithTag :many SELECT s.id, s.tag_id, s.scanned_at, s.lat, s.lng, s.location_shared, s.alert_sent, t.tag_code, t.description, t.item_type FROM scans s JOIN tags t ON t.id = s.tag_id ORDER BY s.scanned_at DESC LIMIT $1 ` type ListRecentScansWithTagRow struct { ID int64 `json:"id"` TagID int64 `json:"tag_id"` ScannedAt pgtype.Timestamptz `json:"scanned_at"` Lat pgtype.Float8 `json:"lat"` Lng pgtype.Float8 `json:"lng"` LocationShared bool `json:"location_shared"` AlertSent bool `json:"alert_sent"` TagCode string `json:"tag_code"` Description pgtype.Text `json:"description"` ItemType pgtype.Text `json:"item_type"` } func (q *Queries) ListRecentScansWithTag(ctx context.Context, limit int32) ([]ListRecentScansWithTagRow, error) { rows, err := q.db.Query(ctx, listRecentScansWithTag, limit) if err != nil { return nil, err } defer rows.Close() var items []ListRecentScansWithTagRow for rows.Next() { var i ListRecentScansWithTagRow if err := rows.Scan( &i.ID, &i.TagID, &i.ScannedAt, &i.Lat, &i.Lng, &i.LocationShared, &i.AlertSent, &i.TagCode, &i.Description, &i.ItemType, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listTagsByOwner = `-- name: ListTagsByOwner :many SELECT id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start FROM tags WHERE owner_id = $1 ORDER BY created_at DESC ` func (q *Queries) ListTagsByOwner(ctx context.Context, ownerID pgtype.Int8) ([]Tag, error) { rows, err := q.db.Query(ctx, listTagsByOwner, ownerID) if err != nil { return nil, err } defer rows.Close() var items []Tag for rows.Next() { var i Tag if err := rows.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const setScanAlertSent = `-- name: SetScanAlertSent :exec UPDATE scans SET alert_sent = $2 WHERE id = $1 ` type SetScanAlertSentParams struct { ID int64 `json:"id"` AlertSent bool `json:"alert_sent"` } func (q *Queries) SetScanAlertSent(ctx context.Context, arg SetScanAlertSentParams) error { _, err := q.db.Exec(ctx, setScanAlertSent, arg.ID, arg.AlertSent) return err } const setScanPhone = `-- name: SetScanPhone :exec UPDATE scans SET scanner_phone = $2, fingerprint = $3 WHERE id = $1 ` type SetScanPhoneParams struct { ID int64 `json:"id"` ScannerPhone pgtype.Text `json:"scanner_phone"` Fingerprint pgtype.Text `json:"fingerprint"` } func (q *Queries) SetScanPhone(ctx context.Context, arg SetScanPhoneParams) error { _, err := q.db.Exec(ctx, setScanPhone, arg.ID, arg.ScannerPhone, arg.Fingerprint) return err } const setTagStatus = `-- name: SetTagStatus :exec UPDATE tags SET status=$2, updated_at=now() WHERE id=$1 ` type SetTagStatusParams struct { ID int64 `json:"id"` Status string `json:"status"` } func (q *Queries) SetTagStatus(ctx context.Context, arg SetTagStatusParams) error { _, err := q.db.Exec(ctx, setTagStatus, arg.ID, arg.Status) return err } const updateTagDetails = `-- name: UpdateTagDetails :one UPDATE tags SET item_type=$2, description=$3, photo_url=$4, phone=$5, address=$6, notes=$7, sms_enabled=$8, status='active', updated_at=now() WHERE id=$1 RETURNING id, tag_code, owner_id, status, item_type, description, photo_url, phone, address, notes, created_at, updated_at, sms_enabled, product_id, order_id, sms_allocated, sms_used, sms_period_start ` type UpdateTagDetailsParams struct { ID int64 `json:"id"` ItemType pgtype.Text `json:"item_type"` Description pgtype.Text `json:"description"` PhotoUrl pgtype.Text `json:"photo_url"` Phone pgtype.Text `json:"phone"` Address pgtype.Text `json:"address"` Notes pgtype.Text `json:"notes"` SmsEnabled bool `json:"sms_enabled"` } func (q *Queries) UpdateTagDetails(ctx context.Context, arg UpdateTagDetailsParams) (Tag, error) { row := q.db.QueryRow(ctx, updateTagDetails, arg.ID, arg.ItemType, arg.Description, arg.PhotoUrl, arg.Phone, arg.Address, arg.Notes, arg.SmsEnabled, ) var i Tag err := row.Scan( &i.ID, &i.TagCode, &i.OwnerID, &i.Status, &i.ItemType, &i.Description, &i.PhotoUrl, &i.Phone, &i.Address, &i.Notes, &i.CreatedAt, &i.UpdatedAt, &i.SmsEnabled, &i.ProductID, &i.OrderID, &i.SmsAllocated, &i.SmsUsed, &i.SmsPeriodStart, ) return i, err } const upsertAdmin = `-- name: UpsertAdmin :one INSERT INTO users (email, password_hash, name, is_admin) VALUES ($1, $2, $3, true) ON CONFLICT (email) DO UPDATE SET password_hash = EXCLUDED.password_hash, name = EXCLUDED.name, is_admin = true RETURNING id, email, password_hash, name, phone, created_at, is_admin, remember_token, paused, stripe_id, sms_credits ` type UpsertAdminParams struct { Email string `json:"email"` PasswordHash string `json:"password_hash"` Name pgtype.Text `json:"name"` } func (q *Queries) UpsertAdmin(ctx context.Context, arg UpsertAdminParams) (User, error) { row := q.db.QueryRow(ctx, upsertAdmin, arg.Email, arg.PasswordHash, arg.Name) var i User err := row.Scan( &i.ID, &i.Email, &i.PasswordHash, &i.Name, &i.Phone, &i.CreatedAt, &i.IsAdmin, &i.RememberToken, &i.Paused, &i.StripeID, &i.SmsCredits, ) return i, err }