You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
281 lines
5.6 KiB
Go
281 lines
5.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.13.0
|
|
// source: queries.sql
|
|
|
|
package namespace
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const allNamespaces = `-- name: AllNamespaces :many
|
|
SELECT
|
|
ns.id,
|
|
ns.name,
|
|
ns.lastseen,
|
|
ns.allowance_time,
|
|
ns.quota_kb,
|
|
ns.quota_usage_kb,
|
|
u.num as u_num,
|
|
u.size_b as u_size_b,
|
|
d.num as d_num,
|
|
d.size_b as d_size_b,
|
|
ul.num as ul_num,
|
|
ul.size_b as ul_size_b
|
|
FROM namespace as ns
|
|
JOIN file_stats as u
|
|
ON ns.usage_id = u.id
|
|
JOIN file_stats as d
|
|
ON ns.download_id = d.id
|
|
JOIN file_stats as ul
|
|
ON ns.upload_id = ul.id
|
|
`
|
|
|
|
type AllNamespacesRow struct {
|
|
ID int64
|
|
Name string
|
|
Lastseen int64
|
|
AllowanceTime sql.NullInt64
|
|
QuotaKb sql.NullInt64
|
|
QuotaUsageKb sql.NullInt64
|
|
UNum int64
|
|
USizeB int64
|
|
DNum int64
|
|
DSizeB int64
|
|
UlNum int64
|
|
UlSizeB int64
|
|
}
|
|
|
|
func (q *Queries) AllNamespaces(ctx context.Context) ([]AllNamespacesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, allNamespaces)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AllNamespacesRow
|
|
for rows.Next() {
|
|
var i AllNamespacesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Lastseen,
|
|
&i.AllowanceTime,
|
|
&i.QuotaKb,
|
|
&i.QuotaUsageKb,
|
|
&i.UNum,
|
|
&i.USizeB,
|
|
&i.DNum,
|
|
&i.DSizeB,
|
|
&i.UlNum,
|
|
&i.UlSizeB,
|
|
); 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 createFileStats = `-- name: CreateFileStats :one
|
|
INSERT INTO file_stats(num, size_b)
|
|
values(?, ?)
|
|
returning id
|
|
`
|
|
|
|
type CreateFileStatsParams struct {
|
|
Num int64
|
|
SizeB int64
|
|
}
|
|
|
|
func (q *Queries) CreateFileStats(ctx context.Context, arg CreateFileStatsParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, createFileStats, arg.Num, arg.SizeB)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const createNamespace = `-- name: CreateNamespace :one
|
|
INSERT INTO
|
|
namespace(
|
|
name,
|
|
lastseen,
|
|
allowance_time,
|
|
quota_kb,
|
|
quota_usage_kb,
|
|
usage_id,
|
|
download_id,
|
|
upload_id
|
|
)
|
|
values(?, ?, ?, ?, ?, ?, ?, ?)
|
|
returning id
|
|
`
|
|
|
|
type CreateNamespaceParams struct {
|
|
Name string
|
|
Lastseen int64
|
|
AllowanceTime sql.NullInt64
|
|
QuotaKb sql.NullInt64
|
|
QuotaUsageKb sql.NullInt64
|
|
UsageID int64
|
|
DownloadID int64
|
|
UploadID int64
|
|
}
|
|
|
|
func (q *Queries) CreateNamespace(ctx context.Context, arg CreateNamespaceParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, createNamespace,
|
|
arg.Name,
|
|
arg.Lastseen,
|
|
arg.AllowanceTime,
|
|
arg.QuotaKb,
|
|
arg.QuotaUsageKb,
|
|
arg.UsageID,
|
|
arg.DownloadID,
|
|
arg.UploadID,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const deleteNameSpace = `-- name: DeleteNameSpace :exec
|
|
DELETE FROM namespace where id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteNameSpace(ctx context.Context, id int64) error {
|
|
_, err := q.db.ExecContext(ctx, deleteNameSpace, id)
|
|
return err
|
|
}
|
|
|
|
const getFileStat = `-- name: GetFileStat :one
|
|
SELECT id, num, size_b FROM file_stats where id = ?
|
|
`
|
|
|
|
func (q *Queries) GetFileStat(ctx context.Context, id int64) (FileStat, error) {
|
|
row := q.db.QueryRowContext(ctx, getFileStat, id)
|
|
var i FileStat
|
|
err := row.Scan(&i.ID, &i.Num, &i.SizeB)
|
|
return i, err
|
|
}
|
|
|
|
const getNamespaceByName = `-- name: GetNamespaceByName :one
|
|
SELECT
|
|
ns.id,
|
|
ns.name,
|
|
ns.lastseen,
|
|
ns.allowance_time,
|
|
ns.quota_kb,
|
|
ns.quota_usage_kb,
|
|
u.num as u_num,
|
|
u.size_b as u_size_b,
|
|
d.num as d_num,
|
|
d.size_b as d_size_b,
|
|
ul.num as ul_num,
|
|
ul.size_b as ul_size_b
|
|
FROM namespace as ns
|
|
JOIN file_stats as u
|
|
ON ns.usage_id = u.id
|
|
JOIN file_stats as d
|
|
ON ns.download_id = d.id
|
|
JOIN file_stats as ul
|
|
ON ns.upload_id = ul.id
|
|
WHERE ns.name = ?
|
|
`
|
|
|
|
type GetNamespaceByNameRow struct {
|
|
ID int64
|
|
Name string
|
|
Lastseen int64
|
|
AllowanceTime sql.NullInt64
|
|
QuotaKb sql.NullInt64
|
|
QuotaUsageKb sql.NullInt64
|
|
UNum int64
|
|
USizeB int64
|
|
DNum int64
|
|
DSizeB int64
|
|
UlNum int64
|
|
UlSizeB int64
|
|
}
|
|
|
|
func (q *Queries) GetNamespaceByName(ctx context.Context, name string) (GetNamespaceByNameRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getNamespaceByName, name)
|
|
var i GetNamespaceByNameRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Lastseen,
|
|
&i.AllowanceTime,
|
|
&i.QuotaKb,
|
|
&i.QuotaUsageKb,
|
|
&i.UNum,
|
|
&i.USizeB,
|
|
&i.DNum,
|
|
&i.DSizeB,
|
|
&i.UlNum,
|
|
&i.UlSizeB,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateFileStat = `-- name: UpdateFileStat :exec
|
|
UPDATE file_stats SET num = ?, size_b = ? where id = ?
|
|
`
|
|
|
|
type UpdateFileStatParams struct {
|
|
Num int64
|
|
SizeB int64
|
|
ID int64
|
|
}
|
|
|
|
func (q *Queries) UpdateFileStat(ctx context.Context, arg UpdateFileStatParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateFileStat, arg.Num, arg.SizeB, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const updateNamespace = `-- name: UpdateNamespace :one
|
|
UPDATE namespace SET
|
|
name = ?,
|
|
lastseen = ?,
|
|
allowance_time = ?,
|
|
quota_kb = ?,
|
|
quota_usage_kb = ?
|
|
WHERE id = ?
|
|
RETURNING usage_id, download_id, upload_id
|
|
`
|
|
|
|
type UpdateNamespaceParams struct {
|
|
Name string
|
|
Lastseen int64
|
|
AllowanceTime sql.NullInt64
|
|
QuotaKb sql.NullInt64
|
|
QuotaUsageKb sql.NullInt64
|
|
ID int64
|
|
}
|
|
|
|
type UpdateNamespaceRow struct {
|
|
UsageID int64
|
|
DownloadID int64
|
|
UploadID int64
|
|
}
|
|
|
|
func (q *Queries) UpdateNamespace(ctx context.Context, arg UpdateNamespaceParams) (UpdateNamespaceRow, error) {
|
|
row := q.db.QueryRowContext(ctx, updateNamespace,
|
|
arg.Name,
|
|
arg.Lastseen,
|
|
arg.AllowanceTime,
|
|
arg.QuotaKb,
|
|
arg.QuotaUsageKb,
|
|
arg.ID,
|
|
)
|
|
var i UpdateNamespaceRow
|
|
err := row.Scan(&i.UsageID, &i.DownloadID, &i.UploadID)
|
|
return i, err
|
|
}
|