// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.17.2
// source: query.sql

package main

import (
	"context"
	"time"
)

const addStudent = `-- name: addStudent :execlastid
insert into students (fname, lname, date_of_birth, email, gender, address) values (?, ?, ?, ?, ?, ?)
`

type addStudentParams struct {
	Fname       string
	Lname       string
	DateOfBirth time.Time
	Email       string
	Gender      string
	Address     string
}

func (q *Queries) addStudent(ctx context.Context, arg addStudentParams) (int64, error) {
	result, err := q.db.ExecContext(ctx, addStudent,
		arg.Fname,
		arg.Lname,
		arg.DateOfBirth,
		arg.Email,
		arg.Gender,
		arg.Address,
	)
	if err != nil {
		return 0, err
	}
	return result.LastInsertId()
}

const fetchStudents = `-- name: fetchStudents :many
SELECT id, fname, lname, date_of_birth, email, address, gender FROM students LIMIT 10
`

func (q *Queries) fetchStudents(ctx context.Context) ([]Student, error) {
	rows, err := q.db.QueryContext(ctx, fetchStudents)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Student
	for rows.Next() {
		var i Student
		if err := rows.Scan(
			&i.ID,
			&i.Fname,
			&i.Lname,
			&i.DateOfBirth,
			&i.Email,
			&i.Address,
			&i.Gender,
		); 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 studentByID = `-- name: studentByID :one
SELECT id, fname, lname, date_of_birth, email, address, gender FROM students WHERE id = ?
`

func (q *Queries) studentByID(ctx context.Context, id int64) (Student, error) {
	row := q.db.QueryRowContext(ctx, studentByID, id)
	var i Student
	err := row.Scan(
		&i.ID,
		&i.Fname,
		&i.Lname,
		&i.DateOfBirth,
		&i.Email,
		&i.Address,
		&i.Gender,
	)
	return i, err
}
