weiro/providers/db/gen/sqlgen/posts.sql.go

85 lines
1.6 KiB
Go
Raw Normal View History

2026-02-19 10:21:27 +00:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
2026-02-20 06:39:58 +00:00
// sqlc v1.30.0
2026-02-19 10:21:27 +00:00
// source: posts.sql
2026-02-19 11:29:44 +00:00
package sqlgen
2026-02-19 10:21:27 +00:00
import (
"context"
)
const insertPost = `-- name: InsertPost :one
INSERT INTO posts (
site_id,
guid,
title,
body,
slug,
created_at,
published_at
) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING id
`
type InsertPostParams struct {
SiteID int64
Guid string
Title string
Body string
Slug string
CreatedAt int64
PublishedAt int64
}
func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertPost,
arg.SiteID,
arg.Guid,
arg.Title,
arg.Body,
arg.Slug,
arg.CreatedAt,
arg.PublishedAt,
)
var id int64
err := row.Scan(&id)
return id, err
}
const selectPostsOfSite = `-- name: SelectPostsOfSite :many
SELECT id, site_id, guid, title, body, slug, created_at, published_at FROM posts WHERE site_id = ? ORDER BY created_at DESC LIMIT 10
`
func (q *Queries) SelectPostsOfSite(ctx context.Context, siteID int64) ([]Post, error) {
rows, err := q.db.QueryContext(ctx, selectPostsOfSite, siteID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.Guid,
&i.Title,
&i.Body,
&i.Slug,
&i.CreatedAt,
&i.PublishedAt,
); 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
}