UPDATE: Entity, Geo, Wiki
Some checks failed
Build and Release / release (push) Failing after 1m7s

This commit is contained in:
2026-04-22 17:45:09 +07:00
parent f127e2f029
commit adb65d8292
50 changed files with 3354 additions and 119 deletions

View File

@@ -0,0 +1,156 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: entities.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createEntity = `-- name: CreateEntity :one
INSERT INTO entities (
name, description, thumbnail_url
) VALUES (
$1, $2, $3
)
RETURNING id, name, description, thumbnail_url, is_deleted, created_at, updated_at
`
type CreateEntityParams struct {
Name string `json:"name"`
Description pgtype.Text `json:"description"`
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
}
func (q *Queries) CreateEntity(ctx context.Context, arg CreateEntityParams) (Entity, error) {
row := q.db.QueryRow(ctx, createEntity, arg.Name, arg.Description, arg.ThumbnailUrl)
var i Entity
err := row.Scan(
&i.ID,
&i.Name,
&i.Description,
&i.ThumbnailUrl,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteEntity = `-- name: DeleteEntity :exec
UPDATE entities
SET
is_deleted = true
WHERE id = $1
`
func (q *Queries) DeleteEntity(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteEntity, id)
return err
}
const getEntityById = `-- name: GetEntityById :one
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at
FROM entities
WHERE id = $1 AND is_deleted = false
`
func (q *Queries) GetEntityById(ctx context.Context, id pgtype.UUID) (Entity, error) {
row := q.db.QueryRow(ctx, getEntityById, id)
var i Entity
err := row.Scan(
&i.ID,
&i.Name,
&i.Description,
&i.ThumbnailUrl,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const searchEntities = `-- name: SearchEntities :many
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at
FROM entities
WHERE is_deleted = false
AND name ILIKE '%' || $1::text || '%'
AND ($2::uuid IS NULL OR id < $2::uuid)
ORDER BY id DESC
LIMIT $3
`
type SearchEntitiesParams struct {
Name string `json:"name"`
CursorID pgtype.UUID `json:"cursor_id"`
LimitCount int32 `json:"limit_count"`
}
func (q *Queries) SearchEntities(ctx context.Context, arg SearchEntitiesParams) ([]Entity, error) {
rows, err := q.db.Query(ctx, searchEntities, arg.Name, arg.CursorID, arg.LimitCount)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Entity{}
for rows.Next() {
var i Entity
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Description,
&i.ThumbnailUrl,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateEntity = `-- name: UpdateEntity :one
UPDATE entities
SET
name = COALESCE($1, name),
description = COALESCE($2, description),
thumbnail_url = COALESCE($3, thumbnail_url)
WHERE id = $4 AND is_deleted = false
RETURNING id, name, description, thumbnail_url, is_deleted, created_at, updated_at
`
type UpdateEntityParams struct {
Name pgtype.Text `json:"name"`
Description pgtype.Text `json:"description"`
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateEntity(ctx context.Context, arg UpdateEntityParams) (Entity, error) {
row := q.db.QueryRow(ctx, updateEntity,
arg.Name,
arg.Description,
arg.ThumbnailUrl,
arg.ID,
)
var i Entity
err := row.Scan(
&i.ID,
&i.Name,
&i.Description,
&i.ThumbnailUrl,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}

View File

@@ -0,0 +1,371 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: geometries.sql
package sqlc
import (
"context"
"encoding/json"
"github.com/jackc/pgx/v5/pgtype"
)
const bulkDeleteEntityGeometriesByEntityId = `-- name: BulkDeleteEntityGeometriesByEntityId :many
DELETE FROM entity_geometries
WHERE entity_id = $1
RETURNING geometry_id
`
func (q *Queries) BulkDeleteEntityGeometriesByEntityId(ctx context.Context, entityID pgtype.UUID) ([]pgtype.UUID, error) {
rows, err := q.db.Query(ctx, bulkDeleteEntityGeometriesByEntityId, entityID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []pgtype.UUID{}
for rows.Next() {
var geometry_id pgtype.UUID
if err := rows.Scan(&geometry_id); err != nil {
return nil, err
}
items = append(items, geometry_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const createEntityGeometries = `-- name: CreateEntityGeometries :exec
INSERT INTO entity_geometries (
entity_id, geometry_id
)
SELECT $1, unnest($2::uuid[])
`
type CreateEntityGeometriesParams struct {
EntityID pgtype.UUID `json:"entity_id"`
GeometryIds []pgtype.UUID `json:"geometry_ids"`
}
func (q *Queries) CreateEntityGeometries(ctx context.Context, arg CreateEntityGeometriesParams) error {
_, err := q.db.Exec(ctx, createEntityGeometries, arg.EntityID, arg.GeometryIds)
return err
}
const createGeometry = `-- name: CreateGeometry :one
INSERT INTO geometries (
geo_type, draw_geometry, binding, time_start, time_end, bbox
) VALUES (
$1, $2, $3, $4, $5, ST_MakeEnvelope($6::float8, $7::float8, $8::float8, $9::float8, 4326)
)
RETURNING id, geo_type, draw_geometry, binding, time_start, time_end,
ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
`
type CreateGeometryParams struct {
GeoType string `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
MaxLat float64 `json:"max_lat"`
}
type CreateGeometryRow struct {
ID pgtype.UUID `json:"id"`
GeoType string `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
MaxLat float64 `json:"max_lat"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) CreateGeometry(ctx context.Context, arg CreateGeometryParams) (CreateGeometryRow, error) {
row := q.db.QueryRow(ctx, createGeometry,
arg.GeoType,
arg.DrawGeometry,
arg.Binding,
arg.TimeStart,
arg.TimeEnd,
arg.MinLng,
arg.MinLat,
arg.MaxLng,
arg.MaxLat,
)
var i CreateGeometryRow
err := row.Scan(
&i.ID,
&i.GeoType,
&i.DrawGeometry,
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
&i.MaxLat,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteGeometry = `-- name: DeleteGeometry :exec
UPDATE geometries
SET
is_deleted = true
WHERE id = $1
`
func (q *Queries) DeleteGeometry(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteGeometry, id)
return err
}
const getGeometryById = `-- name: GetGeometryById :one
SELECT id, geo_type, draw_geometry, binding, time_start, time_end,
ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
FROM geometries
WHERE id = $1 AND is_deleted = false
`
type GetGeometryByIdRow struct {
ID pgtype.UUID `json:"id"`
GeoType string `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
MaxLat float64 `json:"max_lat"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeometryByIdRow, error) {
row := q.db.QueryRow(ctx, getGeometryById, id)
var i GetGeometryByIdRow
err := row.Scan(
&i.ID,
&i.GeoType,
&i.DrawGeometry,
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
&i.MaxLat,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const searchGeometries = `-- name: SearchGeometries :many
SELECT
g.id, g.geo_type, g.draw_geometry, g.binding, g.time_start, g.time_end,
ST_XMin(g.bbox)::float8 as min_lng,
ST_YMin(g.bbox)::float8 as min_lat,
ST_XMax(g.bbox)::float8 as max_lng,
ST_YMax(g.bbox)::float8 as max_lat,
g.is_deleted, g.created_at, g.updated_at
FROM geometries g
WHERE g.is_deleted = false
AND (
$1::float8 IS NULL OR
$2::float8 IS NULL OR
$3::float8 IS NULL OR
$4::float8 IS NULL OR
g.bbox && ST_MakeEnvelope(
$1::float8,
$2::float8,
$3::float8,
$4::float8,
4326
)
)
AND (
$5::int IS NULL OR
(g.time_start <= $5::int AND g.time_end >= $5::int)
)
AND (
$6::uuid IS NULL OR
EXISTS (
SELECT 1
FROM entity_geometries eg
WHERE eg.geometry_id = g.id
AND eg.entity_id = $6::uuid
)
)
ORDER BY g.id DESC
`
type SearchGeometriesParams struct {
SearchMinLng pgtype.Float8 `json:"search_min_lng"`
SearchMinLat pgtype.Float8 `json:"search_min_lat"`
SearchMaxLng pgtype.Float8 `json:"search_max_lng"`
SearchMaxLat pgtype.Float8 `json:"search_max_lat"`
TimePoint pgtype.Int4 `json:"time_point"`
EntityID pgtype.UUID `json:"entity_id"`
}
type SearchGeometriesRow struct {
ID pgtype.UUID `json:"id"`
GeoType string `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
MaxLat float64 `json:"max_lat"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesParams) ([]SearchGeometriesRow, error) {
rows, err := q.db.Query(ctx, searchGeometries,
arg.SearchMinLng,
arg.SearchMinLat,
arg.SearchMaxLng,
arg.SearchMaxLat,
arg.TimePoint,
arg.EntityID,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SearchGeometriesRow{}
for rows.Next() {
var i SearchGeometriesRow
if err := rows.Scan(
&i.ID,
&i.GeoType,
&i.DrawGeometry,
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
&i.MaxLat,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateGeometry = `-- name: UpdateGeometry :one
UPDATE geometries
SET
geo_type = COALESCE($1, geo_type),
draw_geometry = COALESCE($2, draw_geometry),
binding = COALESCE($3, binding),
time_start = COALESCE($4, time_start),
time_end = COALESCE($5, time_end),
bbox = CASE
WHEN $6::boolean = true THEN
ST_MakeEnvelope($7::float8, $8::float8, $9::float8, $10::float8, 4326)
ELSE bbox
END,
updated_at = now()
WHERE id = $11 AND is_deleted = false
RETURNING id, geo_type, draw_geometry, binding, time_start, time_end,
ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
`
type UpdateGeometryParams struct {
GeoType pgtype.Text `json:"geo_type"`
DrawGeometry []byte `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
UpdateBbox pgtype.Bool `json:"update_bbox"`
MinLng pgtype.Float8 `json:"min_lng"`
MinLat pgtype.Float8 `json:"min_lat"`
MaxLng pgtype.Float8 `json:"max_lng"`
MaxLat pgtype.Float8 `json:"max_lat"`
ID pgtype.UUID `json:"id"`
}
type UpdateGeometryRow struct {
ID pgtype.UUID `json:"id"`
GeoType string `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
MaxLat float64 `json:"max_lat"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) UpdateGeometry(ctx context.Context, arg UpdateGeometryParams) (UpdateGeometryRow, error) {
row := q.db.QueryRow(ctx, updateGeometry,
arg.GeoType,
arg.DrawGeometry,
arg.Binding,
arg.TimeStart,
arg.TimeEnd,
arg.UpdateBbox,
arg.MinLng,
arg.MinLat,
arg.MaxLng,
arg.MaxLat,
arg.ID,
)
var i UpdateGeometryRow
err := row.Scan(
&i.ID,
&i.GeoType,
&i.DrawGeometry,
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
&i.MaxLat,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}

View File

@@ -5,9 +5,44 @@
package sqlc
import (
"encoding/json"
"github.com/jackc/pgx/v5/pgtype"
)
type Entity struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
Description pgtype.Text `json:"description"`
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type EntityGeometry struct {
EntityID pgtype.UUID `json:"entity_id"`
GeometryID pgtype.UUID `json:"geometry_id"`
}
type EntityWiki struct {
EntityID pgtype.UUID `json:"entity_id"`
WikiID pgtype.UUID `json:"wiki_id"`
}
type Geometry struct {
ID pgtype.UUID `json:"id"`
GeoType string `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
Bbox interface{} `json:"bbox"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type Media struct {
ID pgtype.UUID `json:"id"`
UserID pgtype.UUID `json:"user_id"`
@@ -77,3 +112,12 @@ type VerificationMedia struct {
VerificationID pgtype.UUID `json:"verification_id"`
MediaID pgtype.UUID `json:"media_id"`
}
type Wiki struct {
ID pgtype.UUID `json:"id"`
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}

View File

@@ -0,0 +1,203 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: wiki.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const bulkDeleteEntityWikisByEntityId = `-- name: BulkDeleteEntityWikisByEntityId :many
DELETE FROM entity_wikis
WHERE entity_id = $1
RETURNING wiki_id
`
func (q *Queries) BulkDeleteEntityWikisByEntityId(ctx context.Context, entityID pgtype.UUID) ([]pgtype.UUID, error) {
rows, err := q.db.Query(ctx, bulkDeleteEntityWikisByEntityId, entityID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []pgtype.UUID{}
for rows.Next() {
var wiki_id pgtype.UUID
if err := rows.Scan(&wiki_id); err != nil {
return nil, err
}
items = append(items, wiki_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const createEntityWikis = `-- name: CreateEntityWikis :exec
INSERT INTO entity_wikis (
entity_id, wiki_id
)
SELECT $1, unnest($2::uuid[])
`
type CreateEntityWikisParams struct {
EntityID pgtype.UUID `json:"entity_id"`
WikiIds []pgtype.UUID `json:"wiki_ids"`
}
func (q *Queries) CreateEntityWikis(ctx context.Context, arg CreateEntityWikisParams) error {
_, err := q.db.Exec(ctx, createEntityWikis, arg.EntityID, arg.WikiIds)
return err
}
const createWiki = `-- name: CreateWiki :one
INSERT INTO wikis (
title, content
) VALUES (
$1, $2
)
RETURNING id, title, content, is_deleted, created_at, updated_at
`
type CreateWikiParams struct {
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
}
func (q *Queries) CreateWiki(ctx context.Context, arg CreateWikiParams) (Wiki, error) {
row := q.db.QueryRow(ctx, createWiki, arg.Title, arg.Content)
var i Wiki
err := row.Scan(
&i.ID,
&i.Title,
&i.Content,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteWiki = `-- name: DeleteWiki :exec
UPDATE wikis
SET
is_deleted = true
WHERE id = $1
`
func (q *Queries) DeleteWiki(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteWiki, id)
return err
}
const getWikiById = `-- name: GetWikiById :one
SELECT id, title, content, is_deleted, created_at, updated_at
FROM wikis
WHERE id = $1 AND is_deleted = false
`
func (q *Queries) GetWikiById(ctx context.Context, id pgtype.UUID) (Wiki, error) {
row := q.db.QueryRow(ctx, getWikiById, id)
var i Wiki
err := row.Scan(
&i.ID,
&i.Title,
&i.Content,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const searchWikis = `-- name: SearchWikis :many
SELECT w.id, w.title, w.content, w.is_deleted, w.created_at, w.updated_at
FROM wikis w
WHERE w.is_deleted = false
AND w.title ILIKE '%' || $1::text || '%'
AND (
$2::uuid IS NULL OR
EXISTS (
SELECT 1
FROM entity_wikis ew
WHERE ew.wiki_id = w.id
AND ew.entity_id = $2::uuid
)
)
AND ($3::uuid IS NULL OR w.id < $3::uuid)
ORDER BY w.id DESC
LIMIT $4
`
type SearchWikisParams struct {
Title string `json:"title"`
EntityID pgtype.UUID `json:"entity_id"`
CursorID pgtype.UUID `json:"cursor_id"`
LimitCount int32 `json:"limit_count"`
}
func (q *Queries) SearchWikis(ctx context.Context, arg SearchWikisParams) ([]Wiki, error) {
rows, err := q.db.Query(ctx, searchWikis,
arg.Title,
arg.EntityID,
arg.CursorID,
arg.LimitCount,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Wiki{}
for rows.Next() {
var i Wiki
if err := rows.Scan(
&i.ID,
&i.Title,
&i.Content,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateWiki = `-- name: UpdateWiki :one
UPDATE wikis
SET
title = COALESCE($1, title),
content = COALESCE($2, content)
WHERE id = $3 AND is_deleted = false
RETURNING id, title, content, is_deleted, created_at, updated_at
`
type UpdateWikiParams struct {
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateWiki(ctx context.Context, arg UpdateWikiParams) (Wiki, error) {
row := q.db.QueryRow(ctx, updateWiki, arg.Title, arg.Content, arg.ID)
var i Wiki
err := row.Scan(
&i.ID,
&i.Title,
&i.Content,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}