core.App interface is the main entry point for all PocketBase functionality. It provides methods for database operations, file storage, settings management, and event hooks.
Creating an app instance
New()
Create a new PocketBase instance with default configuration:NewWithConfig()
Create a PocketBase instance with custom configuration:Lifecycle methods
Bootstrap()
Initialize the application (create data directory, open database connections, load settings):The application is automatically bootstrapped when you call
Start(). You only need to manually call Bootstrap() if you need to initialize the app before starting.Start()
Start the application and register default system commands:ResetBootstrapState()
Release initialized resources (close database connections, stop cron ticker):App properties
DataDir()
Get the app data directory path:IsDev()
Check if the app is in development mode:IsBootstrapped()
Check if the application was initialized:Logger()
Get the default app logger:Settings()
Get the loaded app settings:Store()
Get the app runtime store (for temporary data):Database access
DB()
Get the main database builder instance (automatically routes SELECT to concurrent pool):ConcurrentDB()
Get the concurrent database instance (for read operations):NonconcurrentDB()
Get the nonconcurrent database instance (for write operations):Transactions
RunInTransaction()
Execute a function within a database transaction:Filesystem
NewFilesystem()
Create a new filesystem instance for managing files:NewBackupsFilesystem()
Create a new filesystem instance for managing backups:Mail client
NewMailClient()
Create a new mail client based on current settings:Backups
CreateBackup()
Create a backup of the current app data:RestoreBackup()
Restore a backup and restart the application:Other utilities
Cron()
Get the app cron instance for scheduling tasks:SubscriptionsBroker()
Get the realtime subscriptions broker:ReloadSettings()
Reinitialize and reload app settings:Auxiliary database methods
PocketBase uses two databases:data.db for main data and auxiliary.db for logs and temporary data.
AuxDB()
Get the auxiliary database builder instance (automatically routes SELECT to concurrent pool):AuxConcurrentDB()
Get the concurrent auxiliary database instance (for read operations):AuxNonconcurrentDB()
Get the nonconcurrent auxiliary database instance (for write operations):AuxHasTable()
Check if a table or view exists in the auxiliary database:AuxVacuum()
Reclaim unused disk space in the auxiliary database:AuxModelQuery()
Create a preconfigured SELECT query for the auxiliary database:AuxSave()
Validate and save a model to the auxiliary database:AuxSaveNoValidate()
Save a model to the auxiliary database without validation:AuxDelete()
Delete a model from the auxiliary database:AuxRunInTransaction()
Execute a function within an auxiliary database transaction:It’s safe to nest
AuxRunInTransaction calls as long as you use the callback’s txApp instance.Table operations
HasTable()
Check if a table or view exists in the main database:TableColumns()
Get all column names of a table:TableInfo()
Get detailed information about table columns:TableIndexes()
Get all indexes for a table:DeleteTable()
Drop a table from the database:DeleteView()
Drop a view from the database:SaveView()
Create or update a persistent SQL view:CreateViewFields()
Create a FieldsList from a SELECT query for use in view collections:The SELECT query must have an “id” column and cannot use wildcard (*) columns.
Transaction helpers
TxInfo()
Get the transaction info associated with the current app instance:This is useful when you need to execute logic after a transaction completes, such as sending notifications or cleaning up resources.
IsTransactional()
Check if the current app instance is part of a transaction:UnsafeWithoutHooks()
Get a shallow copy of the app without any registered hooks:Additional model methods
SaveNoValidate()
Save a model to the database without running validations:Use
Save() instead if you want to run validations before persisting.SaveWithContext()
Save a model with a context to limit execution time:DeleteWithContext()
Delete a model with a context to limit execution time:Validate()
Trigger the OnModelValidate hook for a model without saving:ValidateWithContext()
Validate a model with a custom context:Type signature
ThePocketBase struct embeds the core.App interface:
core.App interface is implemented by core.BaseApp: