mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-16 20:05:17 -06:00
194 lines
3.9 KiB
Go
194 lines
3.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: profiles.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const countProfiles = `-- name: CountProfiles :one
|
|
SELECT
|
|
COUNT(*)
|
|
FROM
|
|
profiles
|
|
`
|
|
|
|
func (q *Queries) CountProfiles(ctx context.Context) (int64, error) {
|
|
row := q.queryRow(ctx, q.countProfilesStmt, countProfiles)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createProfile = `-- name: CreateProfile :one
|
|
INSERT INTO
|
|
profiles (name, description, token, created_at, updated_at)
|
|
VALUES
|
|
(?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) RETURNING id, name, description, token, created_at, updated_at
|
|
`
|
|
|
|
type CreateProfileParams struct {
|
|
Name string `json:"name"`
|
|
Description *string `json:"description"`
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
func (q *Queries) CreateProfile(ctx context.Context, arg CreateProfileParams) (Profile, error) {
|
|
row := q.queryRow(ctx, q.createProfileStmt, createProfile, arg.Name, arg.Description, arg.Token)
|
|
var i Profile
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteProfile = `-- name: DeleteProfile :exec
|
|
DELETE FROM profiles
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteProfile(ctx context.Context, id int64) error {
|
|
_, err := q.exec(ctx, q.deleteProfileStmt, deleteProfile, id)
|
|
return err
|
|
}
|
|
|
|
const getProfile = `-- name: GetProfile :one
|
|
SELECT
|
|
id, name, description, token, created_at, updated_at
|
|
FROM
|
|
profiles
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) GetProfile(ctx context.Context, id int64) (Profile, error) {
|
|
row := q.queryRow(ctx, q.getProfileStmt, getProfile, id)
|
|
var i Profile
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getProfileByName = `-- name: GetProfileByName :one
|
|
SELECT
|
|
id, name, description, token, created_at, updated_at
|
|
FROM
|
|
profiles
|
|
WHERE
|
|
name = ?
|
|
`
|
|
|
|
func (q *Queries) GetProfileByName(ctx context.Context, name string) (Profile, error) {
|
|
row := q.queryRow(ctx, q.getProfileByNameStmt, getProfileByName, name)
|
|
var i Profile
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listProfiles = `-- name: ListProfiles :many
|
|
SELECT
|
|
id, name, description, token, created_at, updated_at
|
|
FROM
|
|
profiles
|
|
ORDER BY
|
|
created_at DESC
|
|
LIMIT
|
|
COALESCE(CAST(?2 AS INTEGER), -1)
|
|
OFFSET
|
|
COALESCE(CAST(?1 AS INTEGER), 0)
|
|
`
|
|
|
|
type ListProfilesParams struct {
|
|
Offset *int64 `json:"offset"`
|
|
Limit *int64 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListProfiles(ctx context.Context, arg ListProfilesParams) ([]Profile, error) {
|
|
rows, err := q.query(ctx, q.listProfilesStmt, listProfiles, arg.Offset, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Profile
|
|
for rows.Next() {
|
|
var i Profile
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Token,
|
|
&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 updateProfile = `-- name: UpdateProfile :one
|
|
UPDATE profiles
|
|
SET
|
|
name = ?,
|
|
description = ?,
|
|
token = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE
|
|
id = ? RETURNING id, name, description, token, created_at, updated_at
|
|
`
|
|
|
|
type UpdateProfileParams struct {
|
|
Name string `json:"name"`
|
|
Description *string `json:"description"`
|
|
Token string `json:"token"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProfile(ctx context.Context, arg UpdateProfileParams) (Profile, error) {
|
|
row := q.queryRow(ctx, q.updateProfileStmt, updateProfile,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Token,
|
|
arg.ID,
|
|
)
|
|
var i Profile
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|