rest

package
v0.0.1-toy-1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package rest provides a PostgreSQL REST API server similar to PostgREST.

The server automatically exposes database tables and views as REST endpoints. Each endpoint supports standard HTTP methods: GET, POST, PATCH, DELETE.

Query parameters control filtering, pagination, and ordering:

Parameter         | Description
------------------|------------------------------------------------
?select=col1,col2 | Select specific columns
?order=col.desc   | Order results (supports nullsfirst/nullslast)
?limit=100        | Limit number of results (default: 100)
?offset=0         | Pagination offset (default: 0)
?col=eq.val       | Filter by column equality
?col=gt.val       | Filter with greater than comparison
?col=lt.val       | Filter with less than comparison
?col=gte.val      | Filter with greater than or equal comparison
?col=lte.val      | Filter with less than or equal comparison
?col=like.val     | Filter with pattern matching
?col=in.(a,b,c)   | Filter with value lists
?col=is.null      | Filter for null values
?or=(a.eq.x,b.lt.y) | Combine filters with logical operators

API is compatible with PostgREST. For more details, see: https://docs.postgrest.org/en/stable/references/api/tables_views.html

Example usage:

server, err := rest.NewServer("postgres://user:pass@localhost/db", "")
if err != nil {
	log.Fatal(err)
}
defer server.Shutdown()
log.Fatal(server.Start(":8080"))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterParam

type FilterParam struct {
	Operator string
	Value    any
}

type JoinParam

type JoinParam struct {
	Table    string
	JoinType string
	On       string
}

type OrderParam

type OrderParam struct {
	Column        string
	Direction     string // asc or desc
	NullsPosition string // first or last
}

type QueryParams

type QueryParams struct {
	Select     []string                 // Columns to select
	Order      []OrderParam             // Order by columns
	Limit      int                      // Limit results
	Offset     int                      // Offset results
	Filters    map[string][]FilterParam // Column filters
	EmbedJoins []JoinParam              // Embedded resource joins (foreign keys)
}

QueryParams holds parsed query parameters in a structured way

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(connString string, baseURL string) (*Server, error)

func (*Server) Shutdown

func (s *Server) Shutdown()

Gracefully shut down server

func (*Server) Start

func (s *Server) Start(addr string) error

Start server on the given address

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL