Skip to main content
The 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:
Always use the txApp instance passed to your callback function, not the original app instance, to ensure operations are part of the 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:
This feature is experimental and currently expected to work only on UNIX-based systems. The application process will be replaced using execve.

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:
This method is vulnerable to SQL injection. The table name must come only from trusted input.

DeleteView()

Drop a view from the database:
This method is vulnerable to SQL injection. The view name must come only from trusted input.

SaveView()

Create or update a persistent SQL view:
This method is vulnerable to SQL injection. Arguments must come only from trusted input.

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:
Using the unsafe app instance may cause data integrity errors since record validations and normalizations rely on 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

The PocketBase struct embeds the core.App interface:
The core.App interface is implemented by core.BaseApp: