diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-11-23 20:27:10 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-11-23 20:27:10 +0200 |
| commit | b67ab26b89e16d4492145702b0ef899d3d6b7416 (patch) | |
| tree | 457e88f976e1812a01face1c0096b826ac6d8805 /internal/data/frequencies.sql.go | |
| parent | 77d9971982e336aa6c0b816d84f2d37780c02de6 (diff) | |
Added frequency queries
Diffstat (limited to 'internal/data/frequencies.sql.go')
| -rw-r--r-- | internal/data/frequencies.sql.go | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/internal/data/frequencies.sql.go b/internal/data/frequencies.sql.go index d978f1f..ae7cd43 100644 --- a/internal/data/frequencies.sql.go +++ b/internal/data/frequencies.sql.go @@ -13,9 +13,12 @@ import ( const createFrequency = `-- name: CreateFrequency :one INSERT INTO frequencies ( - id, network_id, name + id, network_id, + name, hex_color, + perms, position ) VALUES ( - ?, ?, ? + ?, ?, ?, ?, ?, + (SELECT COUNT(*) FROM frequencies WHERE network_id = ?) ) RETURNING id, network_id, name, hex_color, perms, position ` @@ -24,10 +27,18 @@ type CreateFrequencyParams struct { ID snowflake.ID NetworkID snowflake.ID Name string + HexColor *string + Perms int64 } func (q *Queries) CreateFrequency(ctx context.Context, arg CreateFrequencyParams) (Frequency, error) { - row := q.db.QueryRowContext(ctx, createFrequency, arg.ID, arg.NetworkID, arg.Name) + row := q.db.QueryRowContext(ctx, createFrequency, + arg.ID, + arg.NetworkID, + arg.Name, + arg.HexColor, + arg.Perms, + ) var i Frequency err := row.Scan( &i.ID, @@ -40,6 +51,15 @@ func (q *Queries) CreateFrequency(ctx context.Context, arg CreateFrequencyParams return i, err } +const deleteFrequency = `-- name: DeleteFrequency :exec +DELETE FROM frequencies WHERE id = ? +` + +func (q *Queries) DeleteFrequency(ctx context.Context, id snowflake.ID) error { + _, err := q.db.ExecContext(ctx, deleteFrequency, id) + return err +} + const getNetworkFrequencies = `-- name: GetNetworkFrequencies :many SELECT id, network_id, name, hex_color, perms, position FROM frequencies WHERE network_id = ? @@ -75,3 +95,23 @@ func (q *Queries) GetNetworkFrequencies(ctx context.Context, networkID snowflake } return items, nil } + +const swapFrequencies = `-- name: SwapFrequencies :exec +UPDATE frequencies SET + position = CASE + WHEN position = ? THEN ? + WHEN position = ? THEN ? + END +WHERE network_id = ? AND position IN (?, ?) +` + +type SwapFrequenciesParams struct { + Pos1 int64 + Pos2 int64 + NetworkID snowflake.ID +} + +func (q *Queries) SwapFrequencies(ctx context.Context, arg SwapFrequenciesParams) error { + _, err := q.db.ExecContext(ctx, swapFrequencies, arg.Pos1, arg.Pos2, arg.NetworkID) + return err +} |
