// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.26.0 // source: query.sql package sqlc import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const allNewReservations = `-- name: AllNewReservations :many SELECT r.id, r.first_name, r.last_name, r.email, r.phone, r.start_date, r.end_date, r.room_id, r.created_at, r.updated_at, r.processed, rm.id, rm.room_name FROM reservations r LEFT JOIN rooms rm ON (r.room_id = rm.id) WHERE r.processed = 0 ORDER BY r.start_date ASC ` type AllNewReservationsRow struct { ID int32 FirstName string LastName string Email string Phone string StartDate pgtype.Date EndDate pgtype.Date RoomID int32 CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp Processed int32 ID_2 pgtype.Int4 RoomName pgtype.Text } func (q *Queries) AllNewReservations(ctx context.Context) ([]AllNewReservationsRow, error) { rows, err := q.db.Query(ctx, allNewReservations) if err != nil { return nil, err } defer rows.Close() var items []AllNewReservationsRow for rows.Next() { var i AllNewReservationsRow if err := rows.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Email, &i.Phone, &i.StartDate, &i.EndDate, &i.RoomID, &i.CreatedAt, &i.UpdatedAt, &i.Processed, &i.ID_2, &i.RoomName, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const allReservations = `-- name: AllReservations :many SELECT r.id, r.first_name, r.last_name, r.email, r.phone, r.start_date, r.end_date, r.room_id, r.created_at, r.updated_at, r.processed, rm.id, rm.room_name FROM reservations r LEFT JOIN rooms rm ON (r.room_id = rm.id) ORDER BY r.start_date ASC ` type AllReservationsRow struct { ID int32 FirstName string LastName string Email string Phone string StartDate pgtype.Date EndDate pgtype.Date RoomID int32 CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp Processed int32 ID_2 pgtype.Int4 RoomName pgtype.Text } func (q *Queries) AllReservations(ctx context.Context) ([]AllReservationsRow, error) { rows, err := q.db.Query(ctx, allReservations) if err != nil { return nil, err } defer rows.Close() var items []AllReservationsRow for rows.Next() { var i AllReservationsRow if err := rows.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Email, &i.Phone, &i.StartDate, &i.EndDate, &i.RoomID, &i.CreatedAt, &i.UpdatedAt, &i.Processed, &i.ID_2, &i.RoomName, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const allRooms = `-- name: AllRooms :many SELECT id, room_name, created_at, updated_at FROM rooms ORDER BY room_name ` func (q *Queries) AllRooms(ctx context.Context) ([]Room, error) { rows, err := q.db.Query(ctx, allRooms) if err != nil { return nil, err } defer rows.Close() var items []Room for rows.Next() { var i Room if err := rows.Scan( &i.ID, &i.RoomName, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const deleteBlockByID = `-- name: DeleteBlockByID :exec DELETE FROM room_restrictions WHERE id = $1 ` func (q *Queries) DeleteBlockByID(ctx context.Context, id int32) error { _, err := q.db.Exec(ctx, deleteBlockByID, id) return err } const deleteReservation = `-- name: DeleteReservation :exec DELETE FROM reservations WHERE id = $1 ` func (q *Queries) DeleteReservation(ctx context.Context, id int32) error { _, err := q.db.Exec(ctx, deleteReservation, id) return err } const getReservationByID = `-- name: GetReservationByID :one SELECT r.id, r.first_name, r.last_name, r.email, r.phone, r.start_date, r.end_date, r.room_id, r.created_at, r.updated_at, r.processed, rm.id, rm.room_name FROM reservations r LEFT JOIN rooms rm ON (r.room_id = rm.id) WHERE r.id = $1 ` type GetReservationByIDRow struct { ID int32 FirstName string LastName string Email string Phone string StartDate pgtype.Date EndDate pgtype.Date RoomID int32 CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp Processed int32 ID_2 pgtype.Int4 RoomName pgtype.Text } func (q *Queries) GetReservationByID(ctx context.Context, id int32) (GetReservationByIDRow, error) { row := q.db.QueryRow(ctx, getReservationByID, id) var i GetReservationByIDRow err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Email, &i.Phone, &i.StartDate, &i.EndDate, &i.RoomID, &i.CreatedAt, &i.UpdatedAt, &i.Processed, &i.ID_2, &i.RoomName, ) return i, err } const getRestrictionsForRoomByDate = `-- name: GetRestrictionsForRoomByDate :many SELECT id, coalesce(reservation_id, 0), restriction_id, room_id, start_date, end_date FROM room_restrictions WHERE $1 < end_date AND $2 >= start_date AND room_id = $3 ` type GetRestrictionsForRoomByDateParams struct { StartDate pgtype.Date EndDate pgtype.Date RoomID int32 } type GetRestrictionsForRoomByDateRow struct { ID int32 ReservationID int32 RestrictionID int32 RoomID int32 StartDate pgtype.Date EndDate pgtype.Date } func (q *Queries) GetRestrictionsForRoomByDate(ctx context.Context, arg GetRestrictionsForRoomByDateParams) ([]GetRestrictionsForRoomByDateRow, error) { rows, err := q.db.Query(ctx, getRestrictionsForRoomByDate, arg.StartDate, arg.EndDate, arg.RoomID) if err != nil { return nil, err } defer rows.Close() var items []GetRestrictionsForRoomByDateRow for rows.Next() { var i GetRestrictionsForRoomByDateRow if err := rows.Scan( &i.ID, &i.ReservationID, &i.RestrictionID, &i.RoomID, &i.StartDate, &i.EndDate, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getRoomById = `-- name: GetRoomById :one SELECT id, room_name, created_at, updated_at FROM rooms WHERE id = $1 ` func (q *Queries) GetRoomById(ctx context.Context, id int32) (Room, error) { row := q.db.QueryRow(ctx, getRoomById, id) var i Room err := row.Scan( &i.ID, &i.RoomName, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getUserByID = `-- name: GetUserByID :one SELECT id, first_name, last_name, email, password, access_level, created_at, updated_at FROM users WHERE id = $1 ` func (q *Queries) GetUserByID(ctx context.Context, id int32) (User, error) { row := q.db.QueryRow(ctx, getUserByID, id) var i User err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Email, &i.Password, &i.AccessLevel, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getUserCred = `-- name: GetUserCred :one SELECT id, password FROM users WHERE email = $1 ` type GetUserCredRow struct { ID int32 Password string } func (q *Queries) GetUserCred(ctx context.Context, email string) (GetUserCredRow, error) { row := q.db.QueryRow(ctx, getUserCred, email) var i GetUserCredRow err := row.Scan(&i.ID, &i.Password) return i, err } const insertBlockForRoom = `-- name: InsertBlockForRoom :exec INSERT INTO room_restrictions ( start_date, end_date, room_id, restriction_id, created_at, updated_at ) VALUES ($1, $2, $3, $4, $5, $6) ` type InsertBlockForRoomParams struct { StartDate pgtype.Date EndDate pgtype.Date RoomID int32 RestrictionID int32 CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } func (q *Queries) InsertBlockForRoom(ctx context.Context, arg InsertBlockForRoomParams) error { _, err := q.db.Exec(ctx, insertBlockForRoom, arg.StartDate, arg.EndDate, arg.RoomID, arg.RestrictionID, arg.CreatedAt, arg.UpdatedAt, ) return err } const insertReservation = `-- name: InsertReservation :one INSERT INTO reservations ( first_name, last_name, email, phone, start_date, end_date, room_id, created_at, updated_at ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id ` type InsertReservationParams struct { FirstName string LastName string Email string Phone string StartDate pgtype.Date EndDate pgtype.Date RoomID int32 CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } func (q *Queries) InsertReservation(ctx context.Context, arg InsertReservationParams) (int32, error) { row := q.db.QueryRow(ctx, insertReservation, arg.FirstName, arg.LastName, arg.Email, arg.Phone, arg.StartDate, arg.EndDate, arg.RoomID, arg.CreatedAt, arg.UpdatedAt, ) var id int32 err := row.Scan(&id) return id, err } const insertRoomRestriction = `-- name: InsertRoomRestriction :exec INSERT INTO room_restrictions ( start_date, end_date, room_id, reservation_id, restriction_id, created_at, updated_at ) VALUES ($1, $2, $3, $4, $5, $6, $7) ` type InsertRoomRestrictionParams struct { StartDate pgtype.Date EndDate pgtype.Date RoomID int32 ReservationID pgtype.Int4 RestrictionID int32 CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } func (q *Queries) InsertRoomRestriction(ctx context.Context, arg InsertRoomRestrictionParams) error { _, err := q.db.Exec(ctx, insertRoomRestriction, arg.StartDate, arg.EndDate, arg.RoomID, arg.ReservationID, arg.RestrictionID, arg.CreatedAt, arg.UpdatedAt, ) return err } const searchAvailabilityByDatesByRoomID = `-- name: SearchAvailabilityByDatesByRoomID :one SELECT count(id) FROM room_restrictions WHERE room_id = $1 AND $2 < end_date AND $3 > start_date ` type SearchAvailabilityByDatesByRoomIDParams struct { RoomID int32 EndDate pgtype.Date StartDate pgtype.Date } func (q *Queries) SearchAvailabilityByDatesByRoomID(ctx context.Context, arg SearchAvailabilityByDatesByRoomIDParams) (int64, error) { row := q.db.QueryRow(ctx, searchAvailabilityByDatesByRoomID, arg.RoomID, arg.EndDate, arg.StartDate) var count int64 err := row.Scan(&count) return count, err } const searchAvailabilityForAllRooms = `-- name: SearchAvailabilityForAllRooms :many SELECT r.id, r.room_name FROM rooms r WHERE r.id NOT IN ( SELECT room_id FROM room_restrictions rr WHERE $1 < rr.end_date AND $2 > rr.start_date ) ` type SearchAvailabilityForAllRoomsParams struct { EndDate pgtype.Date StartDate pgtype.Date } type SearchAvailabilityForAllRoomsRow struct { ID int32 RoomName string } func (q *Queries) SearchAvailabilityForAllRooms(ctx context.Context, arg SearchAvailabilityForAllRoomsParams) ([]SearchAvailabilityForAllRoomsRow, error) { rows, err := q.db.Query(ctx, searchAvailabilityForAllRooms, arg.EndDate, arg.StartDate) if err != nil { return nil, err } defer rows.Close() var items []SearchAvailabilityForAllRoomsRow for rows.Next() { var i SearchAvailabilityForAllRoomsRow if err := rows.Scan(&i.ID, &i.RoomName); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateProcessedForReservation = `-- name: UpdateProcessedForReservation :exec UPDATE reservations SET processed = $1 WHERE id = $2 ` type UpdateProcessedForReservationParams struct { Processed int32 ID int32 } func (q *Queries) UpdateProcessedForReservation(ctx context.Context, arg UpdateProcessedForReservationParams) error { _, err := q.db.Exec(ctx, updateProcessedForReservation, arg.Processed, arg.ID) return err } const updateReservation = `-- name: UpdateReservation :exec UPDATE reservations SET first_name = $1, last_name = $2, email = $3, phone = $4, updated_at = $5 WHERE id = $6 ` type UpdateReservationParams struct { FirstName string LastName string Email string Phone string UpdatedAt pgtype.Timestamp ID int32 } func (q *Queries) UpdateReservation(ctx context.Context, arg UpdateReservationParams) error { _, err := q.db.Exec(ctx, updateReservation, arg.FirstName, arg.LastName, arg.Email, arg.Phone, arg.UpdatedAt, arg.ID, ) return err } const updateUser = `-- name: UpdateUser :exec UPDATE users SET first_name = $1, last_name = $2, email = $3, access_level = $4, updated_at = $5 ` type UpdateUserParams struct { FirstName string LastName string Email string AccessLevel int32 UpdatedAt pgtype.Timestamp } func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error { _, err := q.db.Exec(ctx, updateUser, arg.FirstName, arg.LastName, arg.Email, arg.AccessLevel, arg.UpdatedAt, ) return err }