all repos — homestead @ 52549c0ea610306039e1f3f91c89e05ba4f41e72

Code for my website

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// 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.style_hash,
	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.StyleHash,
			&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, style_hash, title)
VALUES (
  ?1,
  ?2,
  ?3,
  ?4,
  ?5,
  ?6
)
`

type InsertFileParams struct {
	UrlID        int64
	ContentType  string
	LastModified int64
	Etag         string
	StyleHash    string
	Title        string
}

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.StyleHash,
		arg.Title,
	)
	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()
}