The biggest difference from other backend solutions like Firebase, Supabase, Nhost, etc., is that PocketBase actually could be used as a Go framework that enables you to build your own custom app specific business logic and still have a single portable executable at the end.
The minimal PocketBase application looks like this:
// main.go
package main
import (
"log"
"github.com/pocketbase/pocketbase"
)
func main() {
app := pocketbase.New()
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
Running/building the application is the same as for any other Go program, aka. just
go run main.go
and go build
.
PocketBase embeds SQLite, but doesn't require CGO.
If CGO is enabled, it will use
mattn/go-sqlite3
driver, otherwise -
modernc.org/sqlite.
Enable CGO only if you really need to squeeze the read/write query performance at the expense of complicating
cross compilation.
PocketBase could be extended by:
- Binding to event hooks and modifying responses, eg.:
app.OnRecordBeforeCreateRequest().Add(func(e *core.RecordCreateEvent) error { // overwrite the newly submitted "posts" record status to pending if e.Record.Collection().Name == "posts" { e.Record.Set("status", "pending") } return nil })
- Registering custom routes, eg:
app.OnBeforeServe().Add(func(e *core.ServeEvent) error { e.Router.AddRoute(echo.Route{ Method: http.MethodGet, Path: "/api/hello", Handler: func(c echo.Context) error { return c.String(http.StatusOK, "Hello world!") }, Middlewares: []echo.MiddlewareFunc{ apis.ActivityLogger(app), apis.RequireAdminAuth(), }, }) return nil })
- Registering custom console commands, eg.:
app.RootCmd.AddCommand(&cobra.Command{ Use: "hello", Run: func(command *cobra.Command, args []string) { print("Hello world!") }, })
- and much more...
You may also find useful checking the repo source and the package documentation .