mirror of
https://github.com/1f349/lavender.git
synced 2024-10-18 16:41:51 +01:00
82 lines
1.7 KiB
Go
82 lines
1.7 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// versions:
|
||
|
// sqlc v1.25.0
|
||
|
// source: otp.sql
|
||
|
|
||
|
package database
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
const deleteOtp = `-- name: DeleteOtp :exec
|
||
|
DELETE
|
||
|
FROM otp
|
||
|
WHERE otp.subject = ?
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeleteOtp(ctx context.Context, subject int64) error {
|
||
|
_, err := q.db.ExecContext(ctx, deleteOtp, subject)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const getOtp = `-- name: GetOtp :one
|
||
|
SELECT secret, digits
|
||
|
FROM otp
|
||
|
WHERE subject = ?
|
||
|
`
|
||
|
|
||
|
type GetOtpRow struct {
|
||
|
Secret string `json:"secret"`
|
||
|
Digits int64 `json:"digits"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetOtp(ctx context.Context, subject int64) (GetOtpRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getOtp, subject)
|
||
|
var i GetOtpRow
|
||
|
err := row.Scan(&i.Secret, &i.Digits)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getUserEmail = `-- name: GetUserEmail :one
|
||
|
SELECT email
|
||
|
FROM users
|
||
|
WHERE subject = ?
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetUserEmail(ctx context.Context, subject string) (string, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getUserEmail, subject)
|
||
|
var email string
|
||
|
err := row.Scan(&email)
|
||
|
return email, err
|
||
|
}
|
||
|
|
||
|
const hasOtp = `-- name: HasOtp :one
|
||
|
SELECT EXISTS(SELECT 1 FROM otp WHERE subject = ?) == 1 as hasOtp
|
||
|
`
|
||
|
|
||
|
func (q *Queries) HasOtp(ctx context.Context, subject int64) (bool, error) {
|
||
|
row := q.db.QueryRowContext(ctx, hasOtp, subject)
|
||
|
var hasotp bool
|
||
|
err := row.Scan(&hasotp)
|
||
|
return hasotp, err
|
||
|
}
|
||
|
|
||
|
const setOtp = `-- name: SetOtp :exec
|
||
|
INSERT OR
|
||
|
REPLACE
|
||
|
INTO otp (subject, secret, digits)
|
||
|
VALUES (?, ?, ?)
|
||
|
`
|
||
|
|
||
|
type SetOtpParams struct {
|
||
|
Subject int64 `json:"subject"`
|
||
|
Secret string `json:"secret"`
|
||
|
Digits int64 `json:"digits"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) SetOtp(ctx context.Context, arg SetOtpParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, setOtp, arg.Subject, arg.Secret, arg.Digits)
|
||
|
return err
|
||
|
}
|