This commit is contained in:
371
internal/gen/sqlc/geometries.sql.go
Normal file
371
internal/gen/sqlc/geometries.sql.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user