feat: add sqlc queries for categories
This commit is contained in:
parent
641b402d4a
commit
d47095a902
305
providers/db/gen/sqlgen/categories.sql.go
Normal file
305
providers/db/gen/sqlgen/categories.sql.go
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: categories.sql
|
||||
|
||||
package sqlgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const countPostsOfCategory = `-- name: CountPostsOfCategory :one
|
||||
SELECT COUNT(*) FROM posts p
|
||||
INNER JOIN post_categories pc ON pc.post_id = p.id
|
||||
WHERE pc.category_id = ? AND p.state = 0 AND p.deleted_at = 0
|
||||
`
|
||||
|
||||
func (q *Queries) CountPostsOfCategory(ctx context.Context, categoryID int64) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, countPostsOfCategory, categoryID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const deleteCategory = `-- name: DeleteCategory :exec
|
||||
DELETE FROM categories WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteCategory(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteCategory, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deletePostCategoriesByPost = `-- name: DeletePostCategoriesByPost :exec
|
||||
DELETE FROM post_categories WHERE post_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePostCategoriesByPost(ctx context.Context, postID int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deletePostCategoriesByPost, postID)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertCategory = `-- name: InsertCategory :one
|
||||
INSERT INTO categories (
|
||||
site_id, guid, name, slug, description, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertCategoryParams struct {
|
||||
SiteID int64
|
||||
Guid string
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) InsertCategory(ctx context.Context, arg InsertCategoryParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertCategory,
|
||||
arg.SiteID,
|
||||
arg.Guid,
|
||||
arg.Name,
|
||||
arg.Slug,
|
||||
arg.Description,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const insertPostCategory = `-- name: InsertPostCategory :exec
|
||||
INSERT OR IGNORE INTO post_categories (post_id, category_id) VALUES (?, ?)
|
||||
`
|
||||
|
||||
type InsertPostCategoryParams struct {
|
||||
PostID int64
|
||||
CategoryID int64
|
||||
}
|
||||
|
||||
func (q *Queries) InsertPostCategory(ctx context.Context, arg InsertPostCategoryParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertPostCategory, arg.PostID, arg.CategoryID)
|
||||
return err
|
||||
}
|
||||
|
||||
const selectCategoriesOfPost = `-- name: SelectCategoriesOfPost :many
|
||||
SELECT c.id, c.site_id, c.guid, c.name, c.slug, c.description, c.created_at, c.updated_at FROM categories c
|
||||
INNER JOIN post_categories pc ON pc.category_id = c.id
|
||||
WHERE pc.post_id = ?
|
||||
ORDER BY c.name ASC
|
||||
`
|
||||
|
||||
func (q *Queries) SelectCategoriesOfPost(ctx context.Context, postID int64) ([]Category, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectCategoriesOfPost, postID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Category
|
||||
for rows.Next() {
|
||||
var i Category
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Name,
|
||||
&i.Slug,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); 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 selectCategoriesOfSite = `-- name: SelectCategoriesOfSite :many
|
||||
SELECT id, site_id, guid, name, slug, description, created_at, updated_at FROM categories
|
||||
WHERE site_id = ? ORDER BY name ASC
|
||||
`
|
||||
|
||||
func (q *Queries) SelectCategoriesOfSite(ctx context.Context, siteID int64) ([]Category, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectCategoriesOfSite, siteID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Category
|
||||
for rows.Next() {
|
||||
var i Category
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Name,
|
||||
&i.Slug,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); 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 selectCategory = `-- name: SelectCategory :one
|
||||
SELECT id, site_id, guid, name, slug, description, created_at, updated_at FROM categories WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) SelectCategory(ctx context.Context, id int64) (Category, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectCategory, id)
|
||||
var i Category
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Name,
|
||||
&i.Slug,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectCategoryByGUID = `-- name: SelectCategoryByGUID :one
|
||||
SELECT id, site_id, guid, name, slug, description, created_at, updated_at FROM categories WHERE guid = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) SelectCategoryByGUID(ctx context.Context, guid string) (Category, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectCategoryByGUID, guid)
|
||||
var i Category
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Name,
|
||||
&i.Slug,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectCategoryBySlugAndSite = `-- name: SelectCategoryBySlugAndSite :one
|
||||
SELECT id, site_id, guid, name, slug, description, created_at, updated_at FROM categories WHERE site_id = ? AND slug = ? LIMIT 1
|
||||
`
|
||||
|
||||
type SelectCategoryBySlugAndSiteParams struct {
|
||||
SiteID int64
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) SelectCategoryBySlugAndSite(ctx context.Context, arg SelectCategoryBySlugAndSiteParams) (Category, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectCategoryBySlugAndSite, arg.SiteID, arg.Slug)
|
||||
var i Category
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Name,
|
||||
&i.Slug,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectPostsOfCategory = `-- name: SelectPostsOfCategory :many
|
||||
SELECT p.id, p.site_id, p.state, p.guid, p.title, p.body, p.slug, p.created_at, p.updated_at, p.published_at, p.deleted_at FROM posts p
|
||||
INNER JOIN post_categories pc ON pc.post_id = p.id
|
||||
WHERE pc.category_id = ? AND p.state = 0 AND p.deleted_at = 0
|
||||
ORDER BY p.published_at DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
|
||||
type SelectPostsOfCategoryParams struct {
|
||||
CategoryID int64
|
||||
Limit int64
|
||||
Offset int64
|
||||
}
|
||||
|
||||
func (q *Queries) SelectPostsOfCategory(ctx context.Context, arg SelectPostsOfCategoryParams) ([]Post, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectPostsOfCategory, arg.CategoryID, arg.Limit, arg.Offset)
|
||||
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.State,
|
||||
&i.Guid,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.Slug,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.PublishedAt,
|
||||
&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 updateCategory = `-- name: UpdateCategory :exec
|
||||
UPDATE categories SET
|
||||
name = ?,
|
||||
slug = ?,
|
||||
description = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdateCategoryParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
UpdatedAt int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCategory(ctx context.Context, arg UpdateCategoryParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateCategory,
|
||||
arg.Name,
|
||||
arg.Slug,
|
||||
arg.Description,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
|
||||
package sqlgen
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,20 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
|
||||
package sqlgen
|
||||
|
||||
type Category struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
Guid string
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
|
||||
type PendingUpload struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
|
|
@ -29,6 +40,11 @@ type Post struct {
|
|||
DeletedAt int64
|
||||
}
|
||||
|
||||
type PostCategory struct {
|
||||
PostID int64
|
||||
CategoryID int64
|
||||
}
|
||||
|
||||
type PublishTarget struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
// source: pending_uploads.sql
|
||||
|
||||
package sqlgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
// source: posts.sql
|
||||
|
||||
package sqlgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
// source: pubtargets.sql
|
||||
|
||||
package sqlgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
// source: sites.sql
|
||||
|
||||
package sqlgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
// source: uploads.sql
|
||||
|
||||
package sqlgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.28.0
|
||||
// source: users.sql
|
||||
|
||||
package sqlgen
|
||||
|
|
|
|||
53
sql/queries/categories.sql
Normal file
53
sql/queries/categories.sql
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
-- name: SelectCategoriesOfSite :many
|
||||
SELECT * FROM categories
|
||||
WHERE site_id = ? ORDER BY name ASC;
|
||||
|
||||
-- name: SelectCategory :one
|
||||
SELECT * FROM categories WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: SelectCategoryByGUID :one
|
||||
SELECT * FROM categories WHERE guid = ? LIMIT 1;
|
||||
|
||||
-- name: SelectCategoryBySlugAndSite :one
|
||||
SELECT * FROM categories WHERE site_id = ? AND slug = ? LIMIT 1;
|
||||
|
||||
-- name: SelectCategoriesOfPost :many
|
||||
SELECT c.* FROM categories c
|
||||
INNER JOIN post_categories pc ON pc.category_id = c.id
|
||||
WHERE pc.post_id = ?
|
||||
ORDER BY c.name ASC;
|
||||
|
||||
-- name: SelectPostsOfCategory :many
|
||||
SELECT p.* FROM posts p
|
||||
INNER JOIN post_categories pc ON pc.post_id = p.id
|
||||
WHERE pc.category_id = ? AND p.state = 0 AND p.deleted_at = 0
|
||||
ORDER BY p.published_at DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
|
||||
-- name: CountPostsOfCategory :one
|
||||
SELECT COUNT(*) FROM posts p
|
||||
INNER JOIN post_categories pc ON pc.post_id = p.id
|
||||
WHERE pc.category_id = ? AND p.state = 0 AND p.deleted_at = 0;
|
||||
|
||||
-- name: InsertCategory :one
|
||||
INSERT INTO categories (
|
||||
site_id, guid, name, slug, description, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdateCategory :exec
|
||||
UPDATE categories SET
|
||||
name = ?,
|
||||
slug = ?,
|
||||
description = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?;
|
||||
|
||||
-- name: DeleteCategory :exec
|
||||
DELETE FROM categories WHERE id = ?;
|
||||
|
||||
-- name: InsertPostCategory :exec
|
||||
INSERT OR IGNORE INTO post_categories (post_id, category_id) VALUES (?, ?);
|
||||
|
||||
-- name: DeletePostCategoriesByPost :exec
|
||||
DELETE FROM post_categories WHERE post_id = ?;
|
||||
Loading…
Reference in a new issue