// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: users.sql package db import ( "context" "time" ) const countUsers = `-- name: CountUsers :one SELECT COUNT(*) FROM users ` func (q *Queries) CountUsers(ctx context.Context) (int64, error) { row := q.queryRow(ctx, q.countUsersStmt, countUsers) var count int64 err := row.Scan(&count) return count, err } const createUser = `-- name: CreateUser :one INSERT INTO users ( id, username, password, email, updated_at, created_at ) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) RETURNING id, username, password, email, otp, otp_expiry, last_login, created_at, updated_at ` type CreateUserParams struct { ID string `json:"id"` Username string `json:"username"` Password string `json:"password"` Email *string `json:"email"` } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { row := q.queryRow(ctx, q.createUserStmt, createUser, arg.ID, arg.Username, arg.Password, arg.Email, ) var i User err := row.Scan( &i.ID, &i.Username, &i.Password, &i.Email, &i.Otp, &i.OtpExpiry, &i.LastLogin, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const deleteUser = `-- name: DeleteUser :exec DELETE FROM users WHERE id = ? ` func (q *Queries) DeleteUser(ctx context.Context, id string) error { _, err := q.exec(ctx, q.deleteUserStmt, deleteUser, id) return err } const getUserByEmail = `-- name: GetUserByEmail :one SELECT id, username, password, email, otp, otp_expiry, last_login, created_at, updated_at FROM users WHERE email = ? ` func (q *Queries) GetUserByEmail(ctx context.Context, email *string) (User, error) { row := q.queryRow(ctx, q.getUserByEmailStmt, getUserByEmail, email) var i User err := row.Scan( &i.ID, &i.Username, &i.Password, &i.Email, &i.Otp, &i.OtpExpiry, &i.LastLogin, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getUserByID = `-- name: GetUserByID :one SELECT id, username, password, email, otp, otp_expiry, last_login, created_at, updated_at FROM users WHERE id = ? ` func (q *Queries) GetUserByID(ctx context.Context, id string) (User, error) { row := q.queryRow(ctx, q.getUserByIDStmt, getUserByID, id) var i User err := row.Scan( &i.ID, &i.Username, &i.Password, &i.Email, &i.Otp, &i.OtpExpiry, &i.LastLogin, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getUserByUsername = `-- name: GetUserByUsername :one SELECT id, username, password, email, otp, otp_expiry, last_login, created_at, updated_at FROM users WHERE username = ? ` func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) { row := q.queryRow(ctx, q.getUserByUsernameStmt, getUserByUsername, username) var i User err := row.Scan( &i.ID, &i.Username, &i.Password, &i.Email, &i.Otp, &i.OtpExpiry, &i.LastLogin, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const listUsers = `-- name: ListUsers :many SELECT id, username, password, email, otp, otp_expiry, last_login, created_at, updated_at FROM users ORDER BY created_at DESC LIMIT COALESCE(CAST(?2 AS INTEGER), -1) OFFSET COALESCE(CAST(?1 AS INTEGER), 0) ` type ListUsersParams struct { Offset *int64 `json:"offset"` Limit *int64 `json:"limit"` } func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error) { rows, err := q.query(ctx, q.listUsersStmt, listUsers, arg.Offset, arg.Limit) if err != nil { return nil, err } defer rows.Close() var items []User for rows.Next() { var i User if err := rows.Scan( &i.ID, &i.Username, &i.Password, &i.Email, &i.Otp, &i.OtpExpiry, &i.LastLogin, &i.CreatedAt, &i.UpdatedAt, ); 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 updateUser = `-- name: UpdateUser :one UPDATE users SET username = ?, email = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? RETURNING id, username, password, email, otp, otp_expiry, last_login, created_at, updated_at ` type UpdateUserParams struct { Username string `json:"username"` Email *string `json:"email"` ID string `json:"id"` } func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) { row := q.queryRow(ctx, q.updateUserStmt, updateUser, arg.Username, arg.Email, arg.ID) var i User err := row.Scan( &i.ID, &i.Username, &i.Password, &i.Email, &i.Otp, &i.OtpExpiry, &i.LastLogin, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const updateUserLastLogin = `-- name: UpdateUserLastLogin :exec UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE id = ? ` func (q *Queries) UpdateUserLastLogin(ctx context.Context, id string) error { _, err := q.exec(ctx, q.updateUserLastLoginStmt, updateUserLastLogin, id) return err } const updateUserPassword = `-- name: UpdateUserPassword :exec UPDATE users SET password = ?, otp = '', otp_expiry = NULL WHERE id = ? ` type UpdateUserPasswordParams struct { Password string `json:"password"` ID string `json:"id"` } func (q *Queries) UpdateUserPassword(ctx context.Context, arg UpdateUserPasswordParams) error { _, err := q.exec(ctx, q.updateUserPasswordStmt, updateUserPassword, arg.Password, arg.ID) return err } const updateUserResetToken = `-- name: UpdateUserResetToken :exec UPDATE users SET otp = ?, otp_expiry = ? WHERE id = ? ` type UpdateUserResetTokenParams struct { Otp *string `json:"otp"` OtpExpiry *time.Time `json:"otpExpiry"` ID string `json:"id"` } func (q *Queries) UpdateUserResetToken(ctx context.Context, arg UpdateUserResetTokenParams) error { _, err := q.exec(ctx, q.updateUserResetTokenStmt, updateUserResetToken, arg.Otp, arg.OtpExpiry, arg.ID) return err }