// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.27.0 // source: networks.sql package data import ( "context" "github.com/kyren223/eko/pkg/snowflake" ) const createNetwork = `-- name: CreateNetwork :one INSERT INTO networks ( id, owner_id, name, is_public, icon, bg_hex_color, fg_hex_color ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public ` type CreateNetworkParams struct { ID snowflake.ID OwnerID snowflake.ID Name string IsPublic bool Icon string BgHexColor *string FgHexColor string } func (q *Queries) CreateNetwork(ctx context.Context, arg CreateNetworkParams) (Network, error) { row := q.db.QueryRowContext(ctx, createNetwork, arg.ID, arg.OwnerID, arg.Name, arg.IsPublic, arg.Icon, arg.BgHexColor, arg.FgHexColor, ) var i Network err := row.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ) return i, err } const deleteNetwork = `-- name: DeleteNetwork :exec DELETE FROM networks WHERE id = ? ` func (q *Queries) DeleteNetwork(ctx context.Context, id snowflake.ID) error { _, err := q.db.ExecContext(ctx, deleteNetwork, id) return err } const getBannedUsersInNetwork = `-- name: GetBannedUsersInNetwork :many SELECT users.id, users.name, users.public_key, users.description, users.is_public_dm, users.is_deleted, network_banned_users.banned_at, network_banned_users.reason FROM network_banned_users JOIN users ON users.id = network_banned_users.banned_user_id WHERE network_banned_users.network_id = ? ` type GetBannedUsersInNetworkRow struct { User User BannedAt string Reason *string } func (q *Queries) GetBannedUsersInNetwork(ctx context.Context, networkID snowflake.ID) ([]GetBannedUsersInNetworkRow, error) { rows, err := q.db.QueryContext(ctx, getBannedUsersInNetwork, networkID) if err != nil { return nil, err } defer rows.Close() var items []GetBannedUsersInNetworkRow for rows.Next() { var i GetBannedUsersInNetworkRow if err := rows.Scan( &i.User.ID, &i.User.Name, &i.User.PublicKey, &i.User.Description, &i.User.IsPublicDM, &i.User.IsDeleted, &i.BannedAt, &i.Reason, ); 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 getNetworkById = `-- name: GetNetworkById :one SELECT id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public FROM networks WHERE id = ? ` func (q *Queries) GetNetworkById(ctx context.Context, id snowflake.ID) (Network, error) { row := q.db.QueryRowContext(ctx, getNetworkById, id) var i Network err := row.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ) return i, err } const getPublicNetworks = `-- name: GetPublicNetworks :many SELECT id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public FROM networks WHERE is_public = true ` func (q *Queries) GetPublicNetworks(ctx context.Context) ([]Network, error) { rows, err := q.db.QueryContext(ctx, getPublicNetworks) if err != nil { return nil, err } defer rows.Close() var items []Network for rows.Next() { var i Network if err := rows.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ); 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 getUsersInNetwork = `-- name: GetUsersInNetwork :many SELECT users.id, users.name, users.public_key, users.description, users.is_public_dm, users.is_deleted, users_networks.joined_at, users_networks.is_admin, users_networks.is_muted FROM users_networks JOIN users ON users.id = users_networks.user_id WHERE users_networks.network_id = ? ` type GetUsersInNetworkRow struct { User User JoinedAt string IsAdmin bool IsMuted bool } func (q *Queries) GetUsersInNetwork(ctx context.Context, networkID snowflake.ID) ([]GetUsersInNetworkRow, error) { rows, err := q.db.QueryContext(ctx, getUsersInNetwork, networkID) if err != nil { return nil, err } defer rows.Close() var items []GetUsersInNetworkRow for rows.Next() { var i GetUsersInNetworkRow if err := rows.Scan( &i.User.ID, &i.User.Name, &i.User.PublicKey, &i.User.Description, &i.User.IsPublicDM, &i.User.IsDeleted, &i.JoinedAt, &i.IsAdmin, &i.IsMuted, ); 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 setNetworkIcon = `-- name: SetNetworkIcon :one UPDATE networks SET icon = ?, bg_hex_color = ?, fg_hex_color = ? WHERE id = ? RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public ` type SetNetworkIconParams struct { Icon string BgHexColor *string FgHexColor string ID snowflake.ID } func (q *Queries) SetNetworkIcon(ctx context.Context, arg SetNetworkIconParams) (Network, error) { row := q.db.QueryRowContext(ctx, setNetworkIcon, arg.Icon, arg.BgHexColor, arg.FgHexColor, arg.ID, ) var i Network err := row.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ) return i, err } const setNetworkIsPublic = `-- name: SetNetworkIsPublic :one UPDATE networks SET is_public = ? WHERE id = ? RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public ` type SetNetworkIsPublicParams struct { IsPublic bool ID snowflake.ID } func (q *Queries) SetNetworkIsPublic(ctx context.Context, arg SetNetworkIsPublicParams) (Network, error) { row := q.db.QueryRowContext(ctx, setNetworkIsPublic, arg.IsPublic, arg.ID) var i Network err := row.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ) return i, err } const setNetworkName = `-- name: SetNetworkName :one UPDATE networks SET name = ? WHERE id = ? RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public ` type SetNetworkNameParams struct { Name string ID snowflake.ID } func (q *Queries) SetNetworkName(ctx context.Context, arg SetNetworkNameParams) (Network, error) { row := q.db.QueryRowContext(ctx, setNetworkName, arg.Name, arg.ID) var i Network err := row.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ) return i, err } const transferNetwork = `-- name: TransferNetwork :one UPDATE networks SET owner_id = ? WHERE id = ? RETURNING id, owner_id, name, icon, bg_hex_color, fg_hex_color, is_public ` type TransferNetworkParams struct { OwnerID snowflake.ID ID snowflake.ID } func (q *Queries) TransferNetwork(ctx context.Context, arg TransferNetworkParams) (Network, error) { row := q.db.QueryRowContext(ctx, transferNetwork, arg.OwnerID, arg.ID) var i Network err := row.Scan( &i.ID, &i.OwnerID, &i.Name, &i.Icon, &i.BgHexColor, &i.FgHexColor, &i.IsPublic, ) return i, err }