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

package store

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

const createFile = `-- name: CreateFile :execresult
INSERT INTO files (
        name,
        object_name,
        owner,
        created_at,
        updated_at,
        deleted_at
    )
VALUES (?, ?, ?, ?, ?, ?)
`

type CreateFileParams struct {
	Name       string       `db:"name" json:"name"`
	ObjectName string       `db:"object_name" json:"object_name"`
	Owner      int64        `db:"owner" json:"owner"`
	CreatedAt  time.Time    `db:"created_at" json:"created_at"`
	UpdatedAt  sql.NullTime `db:"updated_at" json:"updated_at"`
	DeletedAt  sql.NullTime `db:"deleted_at" json:"deleted_at"`
}

func (q *Queries) CreateFile(ctx context.Context, arg *CreateFileParams) (sql.Result, error) {
	return q.exec(ctx, q.createFileStmt, createFile,
		arg.Name,
		arg.ObjectName,
		arg.Owner,
		arg.CreatedAt,
		arg.UpdatedAt,
		arg.DeletedAt,
	)
}

const deleteFileByID = `-- name: DeleteFileByID :exec
DELETE FROM files
WHERE id = ?
`

func (q *Queries) DeleteFileByID(ctx context.Context, id int64) error {
	_, err := q.exec(ctx, q.deleteFileByIDStmt, deleteFileByID, id)
	return err
}

const deleteFileByObjectName = `-- name: DeleteFileByObjectName :exec
DELETE FROM files
WHERE object_name = ?
`

func (q *Queries) DeleteFileByObjectName(ctx context.Context, objectName string) error {
	_, err := q.exec(ctx, q.deleteFileByObjectNameStmt, deleteFileByObjectName, objectName)
	return err
}

const getFileByID = `-- name: GetFileByID :one
SELECT id, name, object_name, owner, created_at, updated_at, deleted_at
FROM files
WHERE id = ?
LIMIT 1
`

func (q *Queries) GetFileByID(ctx context.Context, id int64) (File, error) {
	row := q.queryRow(ctx, q.getFileByIDStmt, getFileByID, id)
	var i File
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.ObjectName,
		&i.Owner,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return i, err
}

const getFileByName = `-- name: GetFileByName :one
SELECT id, name, object_name, owner, created_at, updated_at, deleted_at
FROM files
WHERE name = ?
LIMIT 1
`

func (q *Queries) GetFileByName(ctx context.Context, name string) (File, error) {
	row := q.queryRow(ctx, q.getFileByNameStmt, getFileByName, name)
	var i File
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.ObjectName,
		&i.Owner,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return i, err
}

const getFileByObjectName = `-- name: GetFileByObjectName :one
SELECT id, name, object_name, owner, created_at, updated_at, deleted_at
FROM files
WHERE object_name = ?
LIMIT 1
`

func (q *Queries) GetFileByObjectName(ctx context.Context, objectName string) (File, error) {
	row := q.queryRow(ctx, q.getFileByObjectNameStmt, getFileByObjectName, objectName)
	var i File
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.ObjectName,
		&i.Owner,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return i, err
}

const listFiles = `-- name: ListFiles :many
SELECT id, name, object_name, owner, created_at, updated_at, deleted_at
FROM files
ORDER BY id
`

func (q *Queries) ListFiles(ctx context.Context) ([]File, error) {
	rows, err := q.query(ctx, q.listFilesStmt, listFiles)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []File{}
	for rows.Next() {
		var i File
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.ObjectName,
			&i.Owner,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.DeletedAt,
		); 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 listOwnerFiles = `-- name: ListOwnerFiles :many
SELECT id, name, object_name, owner, created_at, updated_at, deleted_at
FROM files
WHERE owner = ?
ORDER BY id
`

func (q *Queries) ListOwnerFiles(ctx context.Context, owner int64) ([]File, error) {
	rows, err := q.query(ctx, q.listOwnerFilesStmt, listOwnerFiles, owner)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []File{}
	for rows.Next() {
		var i File
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.ObjectName,
			&i.Owner,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.DeletedAt,
		); 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
}
