165 lines
3.9 KiB
Go
165 lines
3.9 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// source: identity.sql
|
||
|
|
||
|
package database
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const createIdentity = `-- name: CreateIdentity :one
|
||
|
INSERT INTO "identity" (
|
||
|
"login",
|
||
|
"passphrase",
|
||
|
"is_admin",
|
||
|
"is_disabled"
|
||
|
) VALUES (
|
||
|
$1,
|
||
|
$2,
|
||
|
$3,
|
||
|
$4
|
||
|
) RETURNING id, login, passphrase, totp_secret, is_admin, is_disabled, created_at
|
||
|
`
|
||
|
|
||
|
type CreateIdentityParams struct {
|
||
|
Login sql.NullString `json:"login"`
|
||
|
Passphrase []byte `json:"passphrase"`
|
||
|
IsAdmin bool `json:"is_admin"`
|
||
|
IsDisabled bool `json:"is_disabled"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CreateIdentity(ctx context.Context, arg CreateIdentityParams) (Identity, error) {
|
||
|
row := q.db.QueryRowContext(ctx, createIdentity,
|
||
|
arg.Login,
|
||
|
arg.Passphrase,
|
||
|
arg.IsAdmin,
|
||
|
arg.IsDisabled,
|
||
|
)
|
||
|
var i Identity
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Login,
|
||
|
&i.Passphrase,
|
||
|
&i.TotpSecret,
|
||
|
&i.IsAdmin,
|
||
|
&i.IsDisabled,
|
||
|
&i.CreatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getIdentityByID = `-- name: GetIdentityByID :one
|
||
|
SELECT id, login, passphrase, totp_secret, is_admin, is_disabled, created_at FROM "identity"
|
||
|
WHERE "id" = $1
|
||
|
LIMIT 1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetIdentityByID(ctx context.Context, id int64) (Identity, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getIdentityByID, id)
|
||
|
var i Identity
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Login,
|
||
|
&i.Passphrase,
|
||
|
&i.TotpSecret,
|
||
|
&i.IsAdmin,
|
||
|
&i.IsDisabled,
|
||
|
&i.CreatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getIdentityByLogin = `-- name: GetIdentityByLogin :one
|
||
|
SELECT id, login, passphrase, totp_secret, is_admin, is_disabled, created_at FROM "identity"
|
||
|
WHERE "login" = $1
|
||
|
LIMIT 1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetIdentityByLogin(ctx context.Context, login sql.NullString) (Identity, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getIdentityByLogin, login)
|
||
|
var i Identity
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Login,
|
||
|
&i.Passphrase,
|
||
|
&i.TotpSecret,
|
||
|
&i.IsAdmin,
|
||
|
&i.IsDisabled,
|
||
|
&i.CreatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getIdentityByPrimaryEmail = `-- name: GetIdentityByPrimaryEmail :one
|
||
|
SELECT id, login, passphrase, totp_secret, is_admin, is_disabled, identity.created_at, address, identity_id, is_verified, is_primary, email.created_at FROM "identity"
|
||
|
INNER JOIN "email"
|
||
|
ON "email"."identity_id" = "identity"."id"
|
||
|
WHERE
|
||
|
"email"."address" = $1 AND
|
||
|
"email"."is_primary"
|
||
|
LIMIT 1
|
||
|
`
|
||
|
|
||
|
type GetIdentityByPrimaryEmailRow struct {
|
||
|
ID int64 `json:"id"`
|
||
|
Login sql.NullString `json:"login"`
|
||
|
Passphrase []byte `json:"passphrase"`
|
||
|
TotpSecret sql.NullString `json:"totp_secret"`
|
||
|
IsAdmin bool `json:"is_admin"`
|
||
|
IsDisabled bool `json:"is_disabled"`
|
||
|
CreatedAt time.Time `json:"created_at"`
|
||
|
Address string `json:"address"`
|
||
|
IdentityID int64 `json:"identity_id"`
|
||
|
IsVerified bool `json:"is_verified"`
|
||
|
IsPrimary bool `json:"is_primary"`
|
||
|
CreatedAt_2 time.Time `json:"created_at_2"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetIdentityByPrimaryEmail(ctx context.Context, address string) (GetIdentityByPrimaryEmailRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getIdentityByPrimaryEmail, address)
|
||
|
var i GetIdentityByPrimaryEmailRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Login,
|
||
|
&i.Passphrase,
|
||
|
&i.TotpSecret,
|
||
|
&i.IsAdmin,
|
||
|
&i.IsDisabled,
|
||
|
&i.CreatedAt,
|
||
|
&i.Address,
|
||
|
&i.IdentityID,
|
||
|
&i.IsVerified,
|
||
|
&i.IsPrimary,
|
||
|
&i.CreatedAt_2,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const updateIdentityLogin = `-- name: UpdateIdentityLogin :exec
|
||
|
UPDATE "identity" SET (
|
||
|
"login"
|
||
|
) = (
|
||
|
$2
|
||
|
) WHERE "id" = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) UpdateIdentityLogin(ctx context.Context, id int64) error {
|
||
|
_, err := q.db.ExecContext(ctx, updateIdentityLogin, id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const updateIdentityPassphrase = `-- name: UpdateIdentityPassphrase :exec
|
||
|
UPDATE "identity" SET (
|
||
|
"passphrase"
|
||
|
) = (
|
||
|
$2
|
||
|
) WHERE "id" = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) UpdateIdentityPassphrase(ctx context.Context, id int64) error {
|
||
|
_, err := q.db.ExecContext(ctx, updateIdentityPassphrase, id)
|
||
|
return err
|
||
|
}
|