pocketbase

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 10 Imported by: 0

README

PocketBase for PostgreSQL & MySQL (Enterprise Ready)

This is a heavily customized fork of PocketBase, re-engineered for enterprise-grade production environments. The core storage engine has been replaced with PostgreSQL and MySQL to provide higher performance, scalability, and clustering capabilities.

By moving away from SQLite's write-locking limitations, this project is designed for high-concurrency, multi-node clusters, and complex data environments.

Core Features

  • Enterprise Performance: Overcomes SQLite write-locks by leveraging PostgreSQL/MySQL's robust concurrency models.
  • Cluster-Ready Architecture: Native support for multi-instance deployments. Since it doesn't rely on local database files, you can easily run multiple instances behind a load balancer.
  • Dual Database Engines:
    • PostgreSQL: Default engine with standard DSN support.
    • MySQL: Fully compatible via the mysql:// DSN prefix.
  • Flexible Caching:
    • Redis Cache: Enables distributed caching for cluster environments via --redisDsn. When enabled, SSE Realtime subscriptions also use Redis Pub/Sub, ensuring message synchronization across all nodes.
    • In-Memory Cache: Automatically falls back to high-performance local memory caching if Redis is not configured, ensuring lightning-fast responses for standalone setups.
  • Maintain PocketBase Experience: 100% compatible with existing PocketBase APIs, Admin UI, and business logic.

Quick Start

1. Prerequisites
  • Go 1.18+
  • PostgreSQL or MySQL instance
2. Build
git clone https://github.com/zhenruyan/postgrebase.git
cd postgrebase
# Build binary
go build -o pb ./build/
3. Run

By default, the application tries to connect to PostgreSQL at 127.0.0.1:5432.

./pb serve --dataDsn "postgresql://user:password@127.0.0.1:5432/dbname?sslmode=disable"
Using MySQL
./pb serve --dataDsn "mysql://user:password@tcp(127.0.0.1:3306)/dbname"
Enable Redis Cache (Enhanced Cluster Performance)
./pb serve --redisDsn "redis://127.0.0.1:6379/0"

Configuration Flags

  • --dataDsn: Database connection string.
    • PostgreSQL: postgres://user:pass@host:port/db?sslmode=disable
    • MySQL: mysql://user:pass@tcp(host:port)/db
  • --redisDsn: (Optional) Redis connection string. Defaults to high-performance local memory cache if not provided.
  • --dir: Data directory (used for file uploads, backups, etc., but not for the main database).
  • --encryptionEnv: Name of the environment variable for settings encryption.

Development

Building Admin UI

If you modify the Admin UI, rebuild the embedded assets:

cd ui
npm install
npm run build
Contributing
  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

Credits

This project is a fork of PocketBase. Special thanks to Gani Georgiev for the original amazing work.

License

Licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "(untracked)"

Version of PocketBase

Functions

This section is empty.

Types

type Config

type Config struct {
	// optional default values for the console flags
	DefaultDebug         bool
	DefaultDataDir       string // if not set, it will fallback to "./pb_data"
	DefaultDataDsn       string // if not set, it will fallback to "postgresql://<username>:<password>@<host>:<port>/<database>?sslmode=verify-full"
	RedisDsn             string //redis://<user>:<pass>@localhost:6379/<db>
	DefaultEncryptionEnv string

	// hide the default console server info on app startup
	HideStartBanner bool

	// optional DB configurations
	DataMaxOpenConns int // default to core.DefaultDataMaxOpenConns
	DataMaxIdleConns int // default to core.DefaultDataMaxIdleConns
	LogsMaxOpenConns int // default to core.DefaultLogsMaxOpenConns
	LogsMaxIdleConns int // default to core.DefaultLogsMaxIdleConns
}

Config is the PocketBase initialization config struct.

type PocketBase

type PocketBase struct {

	// RootCmd is the main console command
	RootCmd *cobra.Command
	// contains filtered or unexported fields
}

PocketBase defines a PocketBase app launcher.

It implements core.App via embedding and all of the app interface methods could be accessed directly through the instance (eg. PocketBase.DataDir()).

func New

func New() *PocketBase

New creates a new PocketBase instance with the default configuration. Use [NewWithConfig()] if you want to provide a custom configuration.

Note that the application will not be initialized/bootstrapped yet, aka. DB connections, migrations, app settings, etc. will not be accessible. Everything will be initialized when [Start()] is executed. If you want to initialize the application before calling [Start()], then you'll have to manually call [Bootstrap()].

func NewWithConfig

func NewWithConfig(config Config) *PocketBase

NewWithConfig creates a new PocketBase instance with the provided config.

Note that the application will not be initialized/bootstrapped yet, aka. DB connections, migrations, app settings, etc. will not be accessible. Everything will be initialized when [Start()] is executed. If you want to initialize the application before calling [Start()], then you'll have to manually call [Bootstrap()].

func (*PocketBase) Execute

func (pb *PocketBase) Execute() error

Execute initializes the application (if not already) and executes the pb.RootCmd with graceful shutdown support.

This method differs from pb.Start() by not registering the default system commands!

func (*PocketBase) Start

func (pb *PocketBase) Start() error

Start starts the application, aka. registers the default system commands (serve, migrate, version) and executes pb.RootCmd.

Directories

Path Synopsis
Package apis implements the default PocketBase api services and middlewares.
Package apis implements the default PocketBase api services and middlewares.
Package core is the backbone of PocketBase.
Package core is the backbone of PocketBase.
Package daos handles common PocketBase DB model manipulations.
Package daos handles common PocketBase DB model manipulations.
Package dbx provides a set of DB-agnostic and easy-to-use query building methods for relational databases.
Package dbx provides a set of DB-agnostic and easy-to-use query building methods for relational databases.
Package models implements various services used for request data validation and applying changes to existing DB models through the app Dao.
Package models implements various services used for request data validation and applying changes to existing DB models through the app Dao.
validators
Package validators implements custom shared PocketBase validators.
Package validators implements custom shared PocketBase validators.
Package mails implements various helper methods for sending user and admin emails like forgotten password, verification, etc.
Package mails implements various helper methods for sending user and admin emails like forgotten password, verification, etc.
Package migrations contains the system PocketBase DB migrations.
Package migrations contains the system PocketBase DB migrations.
Package models implements all PocketBase DB models and DTOs.
Package models implements all PocketBase DB models and DTOs.
schema
Package schema implements custom Schema and SchemaField datatypes for handling the Collection schema definitions.
Package schema implements custom Schema and SchemaField datatypes for handling the Collection schema definitions.
Package resolvers contains custom search.FieldResolver implementations.
Package resolvers contains custom search.FieldResolver implementations.
Package tokens implements various user and admin tokens generation methods.
Package tokens implements various user and admin tokens generation methods.
tools
cron
Package cron implements a crontab-like service to execute and schedule repeative tasks/jobs.
Package cron implements a crontab-like service to execute and schedule repeative tasks/jobs.
template
Package template is a thin wrapper around the standard html/template and text/template packages that implements a convenient registry to load and cache templates on the fly concurrently.
Package template is a thin wrapper around the standard html/template and text/template packages that implements a convenient registry to load and cache templates on the fly concurrently.
tokenizer
Package tokenizer implements a rudimentary tokens parser of buffered io.Reader while respecting quotes and parenthesis boundaries.
Package tokenizer implements a rudimentary tokens parser of buffered io.Reader while respecting quotes and parenthesis boundaries.
types
Package types implements some commonly used db serializable types like datetime, json, etc.
Package types implements some commonly used db serializable types like datetime, json, etc.
Package ui handles the PocketBase Admin frontend embedding.
Package ui handles the PocketBase Admin frontend embedding.

Jump to

Keyboard shortcuts

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