Installation
First, create a new Go module and install PocketBase:Basic example
Here’s a minimal example fromexamples/base/main.go:
main.go
Configuration
You can customize PocketBase’s configuration usingNewWithConfig:
The application is bootstrapped automatically when you call
app.Start(). Database connections, migrations, and settings are initialized at this point.Application lifecycle
The PocketBase app follows this lifecycle:1
Creation
Create a new PocketBase instance with
New() or NewWithConfig().2
Configuration
Register plugins, hooks, and custom commands before starting.
3
Bootstrap
The app bootstraps when
Start() or Execute() is called. This initializes:- Database connections
- Migrations
- Application settings
- Event hooks
4
Execution
The app executes the command (default is
serve) and runs until terminated.5
Termination
Graceful shutdown with cleanup via
OnTerminate() hooks.Custom commands
You can add custom CLI commands to your PocketBase app:Working with the database
- Query records
- Create records
- Update records
- Delete records
- Raw SQL
Accessing app settings
You can read and modify application settings:Register plugins
PocketBase supports a plugin system for modular extensions:Build and deployment
1
Build the binary
2
Run the application
3
Optional: Cross-compile
Complete example
Here’s a complete example with multiple features:main.go
Next steps
Event hooks
Learn about all available event hooks
Custom routes
Add custom API endpoints