// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: users.sql package db import ( "context" "database/sql" ) const bindUserPhone = `-- name: BindUserPhone :one UPDATE users SET phone = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? RETURNING id, openid, unionid, phone, created_at, updated_at, last_login_at ` type BindUserPhoneParams struct { Phone sql.NullString `json:"phone"` ID string `json:"id"` } func (q *Queries) BindUserPhone(ctx context.Context, arg BindUserPhoneParams) (User, error) { row := q.db.QueryRowContext(ctx, bindUserPhone, arg.Phone, arg.ID) var i User err := row.Scan( &i.ID, &i.Openid, &i.Unionid, &i.Phone, &i.CreatedAt, &i.UpdatedAt, &i.LastLoginAt, ) return i, err } const createUser = `-- name: CreateUser :one INSERT INTO users (id, openid, unionid, phone) VALUES (?, ?, ?, ?) RETURNING id, openid, unionid, phone, created_at, updated_at, last_login_at ` type CreateUserParams struct { ID string `json:"id"` Openid string `json:"openid"` Unionid sql.NullString `json:"unionid"` Phone sql.NullString `json:"phone"` } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { row := q.db.QueryRowContext(ctx, createUser, arg.ID, arg.Openid, arg.Unionid, arg.Phone, ) var i User err := row.Scan( &i.ID, &i.Openid, &i.Unionid, &i.Phone, &i.CreatedAt, &i.UpdatedAt, &i.LastLoginAt, ) return i, err } const getUserByID = `-- name: GetUserByID :one SELECT id, openid, unionid, phone, created_at, updated_at, last_login_at FROM users WHERE id = ? ` func (q *Queries) GetUserByID(ctx context.Context, id string) (User, error) { row := q.db.QueryRowContext(ctx, getUserByID, id) var i User err := row.Scan( &i.ID, &i.Openid, &i.Unionid, &i.Phone, &i.CreatedAt, &i.UpdatedAt, &i.LastLoginAt, ) return i, err } const getUserByOpenID = `-- name: GetUserByOpenID :one SELECT id, openid, unionid, phone, created_at, updated_at, last_login_at FROM users WHERE openid = ? ` func (q *Queries) GetUserByOpenID(ctx context.Context, openid string) (User, error) { row := q.db.QueryRowContext(ctx, getUserByOpenID, openid) var i User err := row.Scan( &i.ID, &i.Openid, &i.Unionid, &i.Phone, &i.CreatedAt, &i.UpdatedAt, &i.LastLoginAt, ) return i, err } const listBookingPhoneSummaries = `-- name: ListBookingPhoneSummaries :many SELECT phone, COUNT(*) AS booking_count, CAST(MAX(created_at) AS TEXT) AS last_booking_at FROM bookings WHERE phone <> '' GROUP BY phone ORDER BY last_booking_at DESC, phone ASC ` type ListBookingPhoneSummariesRow struct { Phone string `json:"phone"` BookingCount int64 `json:"booking_count"` LastBookingAt string `json:"last_booking_at"` } func (q *Queries) ListBookingPhoneSummaries(ctx context.Context) ([]ListBookingPhoneSummariesRow, error) { rows, err := q.db.QueryContext(ctx, listBookingPhoneSummaries) if err != nil { return nil, err } defer rows.Close() var items []ListBookingPhoneSummariesRow for rows.Next() { var i ListBookingPhoneSummariesRow if err := rows.Scan(&i.Phone, &i.BookingCount, &i.LastBookingAt); 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 listUsersWithPhone = `-- name: ListUsersWithPhone :many SELECT id, openid, unionid, phone, created_at, updated_at, last_login_at FROM users WHERE phone IS NOT NULL AND phone <> '' ORDER BY updated_at DESC, created_at DESC ` func (q *Queries) ListUsersWithPhone(ctx context.Context) ([]User, error) { rows, err := q.db.QueryContext(ctx, listUsersWithPhone) 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.Openid, &i.Unionid, &i.Phone, &i.CreatedAt, &i.UpdatedAt, &i.LastLoginAt, ); 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 touchUserLogin = `-- name: TouchUserLogin :one UPDATE users SET last_login_at = CURRENT_TIMESTAMP WHERE openid = ? RETURNING id, openid, unionid, phone, created_at, updated_at, last_login_at ` func (q *Queries) TouchUserLogin(ctx context.Context, openid string) (User, error) { row := q.db.QueryRowContext(ctx, touchUserLogin, openid) var i User err := row.Scan( &i.ID, &i.Openid, &i.Unionid, &i.Phone, &i.CreatedAt, &i.UpdatedAt, &i.LastLoginAt, ) return i, err }