mirror of
https://github.com/1f349/violet.git
synced 2024-11-21 19:01:39 +00:00
251 lines
5.6 KiB
Go
251 lines
5.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: routing.sql
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/1f349/violet/target"
|
|
)
|
|
|
|
const addRedirect = `-- name: AddRedirect :exec
|
|
INSERT OR
|
|
REPLACE
|
|
INTO redirects (source, destination, description, flags, code, active)
|
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
`
|
|
|
|
type AddRedirectParams struct {
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Description string `json:"description"`
|
|
Flags target.Flags `json:"flags"`
|
|
Code int64 `json:"code"`
|
|
Active bool `json:"active"`
|
|
}
|
|
|
|
func (q *Queries) AddRedirect(ctx context.Context, arg AddRedirectParams) error {
|
|
_, err := q.db.ExecContext(ctx, addRedirect,
|
|
arg.Source,
|
|
arg.Destination,
|
|
arg.Description,
|
|
arg.Flags,
|
|
arg.Code,
|
|
arg.Active,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const addRoute = `-- name: AddRoute :exec
|
|
INSERT OR
|
|
REPLACE
|
|
INTO routes (source, destination, description, flags, active)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
`
|
|
|
|
type AddRouteParams struct {
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Description string `json:"description"`
|
|
Flags target.Flags `json:"flags"`
|
|
Active bool `json:"active"`
|
|
}
|
|
|
|
func (q *Queries) AddRoute(ctx context.Context, arg AddRouteParams) error {
|
|
_, err := q.db.ExecContext(ctx, addRoute,
|
|
arg.Source,
|
|
arg.Destination,
|
|
arg.Description,
|
|
arg.Flags,
|
|
arg.Active,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const getActiveRedirects = `-- name: GetActiveRedirects :many
|
|
SELECT source, destination, flags, code
|
|
FROM redirects
|
|
WHERE active = 1
|
|
`
|
|
|
|
type GetActiveRedirectsRow struct {
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Flags target.Flags `json:"flags"`
|
|
Code int64 `json:"code"`
|
|
}
|
|
|
|
func (q *Queries) GetActiveRedirects(ctx context.Context) ([]GetActiveRedirectsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getActiveRedirects)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetActiveRedirectsRow
|
|
for rows.Next() {
|
|
var i GetActiveRedirectsRow
|
|
if err := rows.Scan(
|
|
&i.Source,
|
|
&i.Destination,
|
|
&i.Flags,
|
|
&i.Code,
|
|
); 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 getActiveRoutes = `-- name: GetActiveRoutes :many
|
|
SELECT source, destination, flags
|
|
FROM routes
|
|
WHERE active = 1
|
|
`
|
|
|
|
type GetActiveRoutesRow struct {
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Flags target.Flags `json:"flags"`
|
|
}
|
|
|
|
func (q *Queries) GetActiveRoutes(ctx context.Context) ([]GetActiveRoutesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getActiveRoutes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetActiveRoutesRow
|
|
for rows.Next() {
|
|
var i GetActiveRoutesRow
|
|
if err := rows.Scan(&i.Source, &i.Destination, &i.Flags); 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 getAllRedirects = `-- name: GetAllRedirects :many
|
|
SELECT source, destination, description, flags, code, active
|
|
FROM redirects
|
|
`
|
|
|
|
type GetAllRedirectsRow struct {
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Description string `json:"description"`
|
|
Flags target.Flags `json:"flags"`
|
|
Code int64 `json:"code"`
|
|
Active bool `json:"active"`
|
|
}
|
|
|
|
func (q *Queries) GetAllRedirects(ctx context.Context) ([]GetAllRedirectsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllRedirects)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllRedirectsRow
|
|
for rows.Next() {
|
|
var i GetAllRedirectsRow
|
|
if err := rows.Scan(
|
|
&i.Source,
|
|
&i.Destination,
|
|
&i.Description,
|
|
&i.Flags,
|
|
&i.Code,
|
|
&i.Active,
|
|
); 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 getAllRoutes = `-- name: GetAllRoutes :many
|
|
SELECT source, destination, description, flags, active
|
|
FROM routes
|
|
`
|
|
|
|
type GetAllRoutesRow struct {
|
|
Source string `json:"source"`
|
|
Destination string `json:"destination"`
|
|
Description string `json:"description"`
|
|
Flags target.Flags `json:"flags"`
|
|
Active bool `json:"active"`
|
|
}
|
|
|
|
func (q *Queries) GetAllRoutes(ctx context.Context) ([]GetAllRoutesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllRoutes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllRoutesRow
|
|
for rows.Next() {
|
|
var i GetAllRoutesRow
|
|
if err := rows.Scan(
|
|
&i.Source,
|
|
&i.Destination,
|
|
&i.Description,
|
|
&i.Flags,
|
|
&i.Active,
|
|
); 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 removeRedirect = `-- name: RemoveRedirect :exec
|
|
DELETE
|
|
FROM redirects
|
|
WHERE source = ?
|
|
`
|
|
|
|
func (q *Queries) RemoveRedirect(ctx context.Context, source string) error {
|
|
_, err := q.db.ExecContext(ctx, removeRedirect, source)
|
|
return err
|
|
}
|
|
|
|
const removeRoute = `-- name: RemoveRoute :exec
|
|
DELETE
|
|
FROM routes
|
|
WHERE source = ?
|
|
`
|
|
|
|
func (q *Queries) RemoveRoute(ctx context.Context, source string) error {
|
|
_, err := q.db.ExecContext(ctx, removeRoute, source)
|
|
return err
|
|
}
|