// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.14.0

package store

import (
	"context"
	"database/sql"
	"fmt"
)

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

func New(db DBTX) *Queries {
	return &Queries{db: db}
}

func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
	q := Queries{db: db}
	var err error
	if q.createFileStmt, err = db.PrepareContext(ctx, createFile); err != nil {
		return nil, fmt.Errorf("error preparing query CreateFile: %w", err)
	}
	if q.deleteFileByIDStmt, err = db.PrepareContext(ctx, deleteFileByID); err != nil {
		return nil, fmt.Errorf("error preparing query DeleteFileByID: %w", err)
	}
	if q.deleteFileByObjectNameStmt, err = db.PrepareContext(ctx, deleteFileByObjectName); err != nil {
		return nil, fmt.Errorf("error preparing query DeleteFileByObjectName: %w", err)
	}
	if q.getFileByIDStmt, err = db.PrepareContext(ctx, getFileByID); err != nil {
		return nil, fmt.Errorf("error preparing query GetFileByID: %w", err)
	}
	if q.getFileByNameStmt, err = db.PrepareContext(ctx, getFileByName); err != nil {
		return nil, fmt.Errorf("error preparing query GetFileByName: %w", err)
	}
	if q.getFileByObjectNameStmt, err = db.PrepareContext(ctx, getFileByObjectName); err != nil {
		return nil, fmt.Errorf("error preparing query GetFileByObjectName: %w", err)
	}
	if q.listFilesStmt, err = db.PrepareContext(ctx, listFiles); err != nil {
		return nil, fmt.Errorf("error preparing query ListFiles: %w", err)
	}
	if q.listOwnerFilesStmt, err = db.PrepareContext(ctx, listOwnerFiles); err != nil {
		return nil, fmt.Errorf("error preparing query ListOwnerFiles: %w", err)
	}
	return &q, nil
}

func (q *Queries) Close() error {
	var err error
	if q.createFileStmt != nil {
		if cerr := q.createFileStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing createFileStmt: %w", cerr)
		}
	}
	if q.deleteFileByIDStmt != nil {
		if cerr := q.deleteFileByIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing deleteFileByIDStmt: %w", cerr)
		}
	}
	if q.deleteFileByObjectNameStmt != nil {
		if cerr := q.deleteFileByObjectNameStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing deleteFileByObjectNameStmt: %w", cerr)
		}
	}
	if q.getFileByIDStmt != nil {
		if cerr := q.getFileByIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing getFileByIDStmt: %w", cerr)
		}
	}
	if q.getFileByNameStmt != nil {
		if cerr := q.getFileByNameStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing getFileByNameStmt: %w", cerr)
		}
	}
	if q.getFileByObjectNameStmt != nil {
		if cerr := q.getFileByObjectNameStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing getFileByObjectNameStmt: %w", cerr)
		}
	}
	if q.listFilesStmt != nil {
		if cerr := q.listFilesStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing listFilesStmt: %w", cerr)
		}
	}
	if q.listOwnerFilesStmt != nil {
		if cerr := q.listOwnerFilesStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing listOwnerFilesStmt: %w", cerr)
		}
	}
	return err
}

func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
	switch {
	case stmt != nil && q.tx != nil:
		return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
	case stmt != nil:
		return stmt.ExecContext(ctx, args...)
	default:
		return q.db.ExecContext(ctx, query, args...)
	}
}

func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
	switch {
	case stmt != nil && q.tx != nil:
		return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
	case stmt != nil:
		return stmt.QueryContext(ctx, args...)
	default:
		return q.db.QueryContext(ctx, query, args...)
	}
}

func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
	switch {
	case stmt != nil && q.tx != nil:
		return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
	case stmt != nil:
		return stmt.QueryRowContext(ctx, args...)
	default:
		return q.db.QueryRowContext(ctx, query, args...)
	}
}

type Queries struct {
	db                         DBTX
	tx                         *sql.Tx
	createFileStmt             *sql.Stmt
	deleteFileByIDStmt         *sql.Stmt
	deleteFileByObjectNameStmt *sql.Stmt
	getFileByIDStmt            *sql.Stmt
	getFileByNameStmt          *sql.Stmt
	getFileByObjectNameStmt    *sql.Stmt
	listFilesStmt              *sql.Stmt
	listOwnerFilesStmt         *sql.Stmt
}

func (q *Queries) WithTx(tx *sql.Tx) *Queries {
	return &Queries{
		db:                         tx,
		tx:                         tx,
		createFileStmt:             q.createFileStmt,
		deleteFileByIDStmt:         q.deleteFileByIDStmt,
		deleteFileByObjectNameStmt: q.deleteFileByObjectNameStmt,
		getFileByIDStmt:            q.getFileByIDStmt,
		getFileByNameStmt:          q.getFileByNameStmt,
		getFileByObjectNameStmt:    q.getFileByObjectNameStmt,
		listFilesStmt:              q.listFilesStmt,
		listOwnerFilesStmt:         q.listOwnerFilesStmt,
	}
}
