all repos — homestead @ 6e3b3d209b4e70fe2edc8d96ea8473efcd075bb9

Code for my website

shared/storage/sqlite/db/query.sql.go (view raw)

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

package db

import (
	"context"
)

const checkPath = `-- name: CheckPath :one
SELECT
    EXISTS(
        SELECT 1
        FROM url
        WHERE path = ?
    ) AS differs
`

func (q *Queries) CheckPath(ctx context.Context, path string) (int64, error) {
	row := q.queryRow(ctx, q.checkPathStmt, checkPath, path)
	var differs int64
	err := row.Scan(&differs)
	return differs, err
}

const getFile = `-- name: GetFile :many
SELECT
    file.file_id, file.url_id, file.content_type, file.last_modified, file.title, file.etag, file.headers,
    content.content_id, content.file_id, content.encoding, content.body
FROM url
INNER JOIN file
    USING (url_id)
INNER JOIN content
    USING (file_id)
WHERE
    url.path = ?
`

type GetFileRow struct {
	File    File
	Content Content
}

func (q *Queries) GetFile(ctx context.Context, path string) ([]GetFileRow, error) {
	rows, err := q.query(ctx, q.getFileStmt, getFile, path)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetFileRow
	for rows.Next() {
		var i GetFileRow
		if err := rows.Scan(
			&i.File.FileID,
			&i.File.UrlID,
			&i.File.ContentType,
			&i.File.LastModified,
			&i.File.Title,
			&i.File.Etag,
			&i.File.Headers,
			&i.Content.ContentID,
			&i.Content.FileID,
			&i.Content.Encoding,
			&i.Content.Body,
		); 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 insertContent = `-- name: InsertContent :exec
INSERT INTO content (file_id, encoding, body)
VALUES (?1, ?2, ?3)
`

type InsertContentParams struct {
	Fileid   int64
	Encoding string
	Body     []byte
}

func (q *Queries) InsertContent(ctx context.Context, arg InsertContentParams) error {
	_, err := q.exec(ctx, q.insertContentStmt, insertContent, arg.Fileid, arg.Encoding, arg.Body)
	return err
}

const insertFile = `-- name: InsertFile :execlastid
INSERT INTO file (
    url_id, content_type, last_modified, etag, title, headers
)
VALUES (
    ?1,
    ?2,
    ?3,
    ?4,
    ?5,
    ?6
)
`

type InsertFileParams struct {
	UrlID        int64
	ContentType  string
	LastModified int64
	Etag         string
	Title        string
	Headers      []byte
}

func (q *Queries) InsertFile(ctx context.Context, arg InsertFileParams) (int64, error) {
	result, err := q.exec(ctx, q.insertFileStmt, insertFile,
		arg.UrlID,
		arg.ContentType,
		arg.LastModified,
		arg.Etag,
		arg.Title,
		arg.Headers,
	)
	if err != nil {
		return 0, err
	}
	return result.LastInsertId()
}

const insertURL = `-- name: InsertURL :execlastid
INSERT INTO url (path) VALUES (?)
`

func (q *Queries) InsertURL(ctx context.Context, path string) (int64, error) {
	result, err := q.exec(ctx, q.insertURLStmt, insertURL, path)
	if err != nil {
		return 0, err
	}
	return result.LastInsertId()
}