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

package relation

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.createUserFileRelationStmt, err = db.PrepareContext(ctx, createUserFileRelation); err != nil {
		return nil, fmt.Errorf("error preparing query CreateUserFileRelation: %w", err)
	}
	if q.deleteRelationByFileIDStmt, err = db.PrepareContext(ctx, deleteRelationByFileID); err != nil {
		return nil, fmt.Errorf("error preparing query DeleteRelationByFileID: %w", err)
	}
	if q.deleteRelationByUserIDStmt, err = db.PrepareContext(ctx, deleteRelationByUserID); err != nil {
		return nil, fmt.Errorf("error preparing query DeleteRelationByUserID: %w", err)
	}
	if q.getFileUserRelationByFileIDStmt, err = db.PrepareContext(ctx, getFileUserRelationByFileID); err != nil {
		return nil, fmt.Errorf("error preparing query GetFileUserRelationByFileID: %w", err)
	}
	if q.getFileUserRelationByUserIDStmt, err = db.PrepareContext(ctx, getFileUserRelationByUserID); err != nil {
		return nil, fmt.Errorf("error preparing query GetFileUserRelationByUserID: %w", err)
	}
	return &q, nil
}

func (q *Queries) Close() error {
	var err error
	if q.createUserFileRelationStmt != nil {
		if cerr := q.createUserFileRelationStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing createUserFileRelationStmt: %w", cerr)
		}
	}
	if q.deleteRelationByFileIDStmt != nil {
		if cerr := q.deleteRelationByFileIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing deleteRelationByFileIDStmt: %w", cerr)
		}
	}
	if q.deleteRelationByUserIDStmt != nil {
		if cerr := q.deleteRelationByUserIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing deleteRelationByUserIDStmt: %w", cerr)
		}
	}
	if q.getFileUserRelationByFileIDStmt != nil {
		if cerr := q.getFileUserRelationByFileIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing getFileUserRelationByFileIDStmt: %w", cerr)
		}
	}
	if q.getFileUserRelationByUserIDStmt != nil {
		if cerr := q.getFileUserRelationByUserIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing getFileUserRelationByUserIDStmt: %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
	createUserFileRelationStmt      *sql.Stmt
	deleteRelationByFileIDStmt      *sql.Stmt
	deleteRelationByUserIDStmt      *sql.Stmt
	getFileUserRelationByFileIDStmt *sql.Stmt
	getFileUserRelationByUserIDStmt *sql.Stmt
}

func (q *Queries) WithTx(tx *sql.Tx) *Queries {
	return &Queries{
		db:                              tx,
		tx:                              tx,
		createUserFileRelationStmt:      q.createUserFileRelationStmt,
		deleteRelationByFileIDStmt:      q.deleteRelationByFileIDStmt,
		deleteRelationByUserIDStmt:      q.deleteRelationByUserIDStmt,
		getFileUserRelationByFileIDStmt: q.getFileUserRelationByFileIDStmt,
		getFileUserRelationByUserIDStmt: q.getFileUserRelationByUserIDStmt,
	}
}
