Files
OwnCord/Server/db/pgdbgen/voice.sql.go
T

372 lines
11 KiB
Go
Raw Normal View History

//go:build postgres
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: voice.sql
package pgdbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const clearAllVoiceStates = `-- name: ClearAllVoiceStates :exec
DELETE FROM voice_states
`
func (q *Queries) ClearAllVoiceStates(ctx context.Context) error {
_, err := q.db.Exec(ctx, clearAllVoiceStates)
return err
}
const clearVoiceState = `-- name: ClearVoiceState :exec
DELETE FROM voice_states WHERE user_id = $1
`
func (q *Queries) ClearVoiceState(ctx context.Context, userID int64) error {
_, err := q.db.Exec(ctx, clearVoiceState, userID)
return err
}
const countActiveCameras = `-- name: CountActiveCameras :one
SELECT COUNT(*) FROM voice_states WHERE channel_id = $1 AND camera = TRUE
`
func (q *Queries) CountActiveCameras(ctx context.Context, channelID int64) (int64, error) {
row := q.db.QueryRow(ctx, countActiveCameras, channelID)
var count int64
err := row.Scan(&count)
return count, err
}
const enableCameraIfUnderLimit = `-- name: EnableCameraIfUnderLimit :execrows
UPDATE voice_states SET camera = TRUE
WHERE voice_states.user_id = $1 AND voice_states.channel_id = $2
AND (SELECT COUNT(*) FROM voice_states AS vs2 WHERE vs2.channel_id = $3 AND vs2.camera = TRUE) < $4
`
type EnableCameraIfUnderLimitParams struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
ChannelID_2 int64 `json:"channelId2"`
ChannelID_3 int64 `json:"channelId3"`
}
func (q *Queries) EnableCameraIfUnderLimit(ctx context.Context, arg EnableCameraIfUnderLimitParams) (int64, error) {
result, err := q.db.Exec(ctx, enableCameraIfUnderLimit,
arg.UserID,
arg.ChannelID,
arg.ChannelID_2,
arg.ChannelID_3,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getAllVoiceStates = `-- name: GetAllVoiceStates :many
SELECT vs.user_id, vs.channel_id, u.username,
vs.muted, vs.deafened, vs.speaking,
vs.camera, vs.screenshare, vs.joined_at
FROM voice_states vs
JOIN users u ON u.id = vs.user_id
ORDER BY vs.channel_id, vs.joined_at ASC
`
type GetAllVoiceStatesRow struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
Username string `json:"username"`
Muted bool `json:"muted"`
Deafened bool `json:"deafened"`
Speaking bool `json:"speaking"`
Camera bool `json:"camera"`
Screenshare bool `json:"screenshare"`
JoinedAt pgtype.Timestamptz `json:"joinedAt"`
}
func (q *Queries) GetAllVoiceStates(ctx context.Context) ([]GetAllVoiceStatesRow, error) {
rows, err := q.db.Query(ctx, getAllVoiceStates)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetAllVoiceStatesRow{}
for rows.Next() {
var i GetAllVoiceStatesRow
if err := rows.Scan(
&i.UserID,
&i.ChannelID,
&i.Username,
&i.Muted,
&i.Deafened,
&i.Speaking,
&i.Camera,
&i.Screenshare,
&i.JoinedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getChannelVoiceStates = `-- name: GetChannelVoiceStates :many
SELECT vs.user_id, vs.channel_id, u.username,
vs.muted, vs.deafened, vs.speaking,
vs.camera, vs.screenshare, vs.joined_at
FROM voice_states vs
JOIN users u ON u.id = vs.user_id
WHERE vs.channel_id = $1
ORDER BY vs.joined_at ASC
`
type GetChannelVoiceStatesRow struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
Username string `json:"username"`
Muted bool `json:"muted"`
Deafened bool `json:"deafened"`
Speaking bool `json:"speaking"`
Camera bool `json:"camera"`
Screenshare bool `json:"screenshare"`
JoinedAt pgtype.Timestamptz `json:"joinedAt"`
}
func (q *Queries) GetChannelVoiceStates(ctx context.Context, channelID int64) ([]GetChannelVoiceStatesRow, error) {
rows, err := q.db.Query(ctx, getChannelVoiceStates, channelID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetChannelVoiceStatesRow{}
for rows.Next() {
var i GetChannelVoiceStatesRow
if err := rows.Scan(
&i.UserID,
&i.ChannelID,
&i.Username,
&i.Muted,
&i.Deafened,
&i.Speaking,
&i.Camera,
&i.Screenshare,
&i.JoinedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUserVoiceState = `-- name: GetUserVoiceState :one
SELECT vs.user_id, vs.channel_id, u.username,
vs.muted, vs.deafened, vs.speaking,
vs.camera, vs.screenshare, vs.joined_at
FROM voice_states vs
JOIN users u ON u.id = vs.user_id
WHERE vs.user_id = $1
`
type GetUserVoiceStateRow struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
Username string `json:"username"`
Muted bool `json:"muted"`
Deafened bool `json:"deafened"`
Speaking bool `json:"speaking"`
Camera bool `json:"camera"`
Screenshare bool `json:"screenshare"`
JoinedAt pgtype.Timestamptz `json:"joinedAt"`
}
func (q *Queries) GetUserVoiceState(ctx context.Context, userID int64) (GetUserVoiceStateRow, error) {
row := q.db.QueryRow(ctx, getUserVoiceState, userID)
var i GetUserVoiceStateRow
err := row.Scan(
&i.UserID,
&i.ChannelID,
&i.Username,
&i.Muted,
&i.Deafened,
&i.Speaking,
&i.Camera,
&i.Screenshare,
&i.JoinedAt,
)
return i, err
}
const joinVoiceChannel = `-- name: JoinVoiceChannel :exec
INSERT INTO voice_states (user_id, channel_id, muted, deafened, speaking, camera, screenshare, joined_at)
VALUES ($1, $2, FALSE, FALSE, FALSE, FALSE, FALSE, $3)
ON CONFLICT (user_id) DO UPDATE SET
channel_id = EXCLUDED.channel_id,
muted = FALSE,
deafened = FALSE,
speaking = FALSE,
camera = FALSE,
screenshare = FALSE,
joined_at = EXCLUDED.joined_at
`
type JoinVoiceChannelParams struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
JoinedAt pgtype.Timestamptz `json:"joinedAt"`
}
// PostgreSQL variants of the sqlite voice queries.
// voice_states boolean columns (muted, deafened, speaking, camera,
// screenshare) use FALSE/TRUE instead of 0/1.
func (q *Queries) JoinVoiceChannel(ctx context.Context, arg JoinVoiceChannelParams) error {
_, err := q.db.Exec(ctx, joinVoiceChannel, arg.UserID, arg.ChannelID, arg.JoinedAt)
return err
}
const joinVoiceChannelIfCapacity = `-- name: JoinVoiceChannelIfCapacity :execrows
INSERT INTO voice_states (user_id, channel_id, muted, deafened, speaking, camera, screenshare, joined_at)
SELECT $1, $2, FALSE, FALSE, FALSE, FALSE, FALSE, $3
WHERE (SELECT COUNT(*) FROM voice_states AS vs2 WHERE vs2.channel_id = $4) < $5
ON CONFLICT (user_id) DO UPDATE SET
channel_id = EXCLUDED.channel_id,
muted = FALSE,
deafened = FALSE,
speaking = FALSE,
camera = FALSE,
screenshare = FALSE,
joined_at = EXCLUDED.joined_at
`
type JoinVoiceChannelIfCapacityParams struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
JoinedAt pgtype.Timestamptz `json:"joinedAt"`
ChannelID_2 int64 `json:"channelId2"`
ChannelID_3 int64 `json:"channelId3"`
}
func (q *Queries) JoinVoiceChannelIfCapacity(ctx context.Context, arg JoinVoiceChannelIfCapacityParams) (int64, error) {
result, err := q.db.Exec(ctx, joinVoiceChannelIfCapacity,
arg.UserID,
arg.ChannelID,
arg.JoinedAt,
arg.ChannelID_2,
arg.ChannelID_3,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const leaveVoiceChannel = `-- name: LeaveVoiceChannel :exec
DELETE FROM voice_states WHERE user_id = $1
`
func (q *Queries) LeaveVoiceChannel(ctx context.Context, userID int64) error {
_, err := q.db.Exec(ctx, leaveVoiceChannel, userID)
return err
}
const leaveVoiceChannelIfMatch = `-- name: LeaveVoiceChannelIfMatch :execrows
DELETE FROM voice_states WHERE user_id = $1 AND channel_id = $2 AND joined_at = $3
`
type LeaveVoiceChannelIfMatchParams struct {
UserID int64 `json:"userId"`
ChannelID int64 `json:"channelId"`
JoinedAt pgtype.Timestamptz `json:"joinedAt"`
}
func (q *Queries) LeaveVoiceChannelIfMatch(ctx context.Context, arg LeaveVoiceChannelIfMatchParams) (int64, error) {
result, err := q.db.Exec(ctx, leaveVoiceChannelIfMatch, arg.UserID, arg.ChannelID, arg.JoinedAt)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateVoiceCamera = `-- name: UpdateVoiceCamera :exec
UPDATE voice_states SET camera = $1 WHERE user_id = $2
`
type UpdateVoiceCameraParams struct {
Camera bool `json:"camera"`
UserID int64 `json:"userId"`
}
func (q *Queries) UpdateVoiceCamera(ctx context.Context, arg UpdateVoiceCameraParams) error {
_, err := q.db.Exec(ctx, updateVoiceCamera, arg.Camera, arg.UserID)
return err
}
const updateVoiceDeafen = `-- name: UpdateVoiceDeafen :exec
UPDATE voice_states SET deafened = $1 WHERE user_id = $2
`
type UpdateVoiceDeafenParams struct {
Deafened bool `json:"deafened"`
UserID int64 `json:"userId"`
}
func (q *Queries) UpdateVoiceDeafen(ctx context.Context, arg UpdateVoiceDeafenParams) error {
_, err := q.db.Exec(ctx, updateVoiceDeafen, arg.Deafened, arg.UserID)
return err
}
const updateVoiceMute = `-- name: UpdateVoiceMute :exec
UPDATE voice_states SET muted = $1 WHERE user_id = $2
`
type UpdateVoiceMuteParams struct {
Muted bool `json:"muted"`
UserID int64 `json:"userId"`
}
func (q *Queries) UpdateVoiceMute(ctx context.Context, arg UpdateVoiceMuteParams) error {
_, err := q.db.Exec(ctx, updateVoiceMute, arg.Muted, arg.UserID)
return err
}
const updateVoiceScreenshare = `-- name: UpdateVoiceScreenshare :exec
UPDATE voice_states SET screenshare = $1 WHERE user_id = $2
`
type UpdateVoiceScreenshareParams struct {
Screenshare bool `json:"screenshare"`
UserID int64 `json:"userId"`
}
func (q *Queries) UpdateVoiceScreenshare(ctx context.Context, arg UpdateVoiceScreenshareParams) error {
_, err := q.db.Exec(ctx, updateVoiceScreenshare, arg.Screenshare, arg.UserID)
return err
}
const updateVoiceSpeaking = `-- name: UpdateVoiceSpeaking :exec
UPDATE voice_states SET speaking = $1 WHERE user_id = $2
`
type UpdateVoiceSpeakingParams struct {
Speaking bool `json:"speaking"`
UserID int64 `json:"userId"`
}
func (q *Queries) UpdateVoiceSpeaking(ctx context.Context, arg UpdateVoiceSpeakingParams) error {
_, err := q.db.Exec(ctx, updateVoiceSpeaking, arg.Speaking, arg.UserID)
return err
}