Giter VIP home page Giter VIP logo

PocketBase - open source backend in 1 file

build Latest releases Go package documentation

PocketBase is an open source Go backend, consisting of:

  • embedded database (SQLite) with realtime subscriptions
  • built-in files and users management
  • convenient Admin dashboard UI
  • and simple REST-ish API

For documentation and examples, please visit https://pocketbase.io/docs.

Warning

Please keep in mind that PocketBase is still under active development and therefore full backward compatibility is not guaranteed before reaching v1.0.0.

API SDK clients

The easiest way to interact with the API is to use one of the official SDK clients:

Overview

Use as standalone app

You could download the prebuilt executable for your platform from the Releases page. Once downloaded, extract the archive and run ./pocketbase serve in the extracted directory.

The prebuilt executables are based on the examples/base/main.go file and comes with the JS VM plugin enabled by default which allows to extend PocketBase with JavaScript (for more details please refer to Extend with JavaScript).

Use as a Go framework/toolkit

PocketBase is distributed as a regular Go library package which allows you to build your own custom app specific business logic and still have a single portable executable at the end.

Here is a minimal example:

  1. Install Go 1.21+ (if you haven't already)

  2. Create a new project directory with the following main.go file inside it:

    package main
    
    import (
        "log"
        "net/http"
    
        "github.com/labstack/echo/v5"
        "github.com/pocketbase/pocketbase"
        "github.com/pocketbase/pocketbase/apis"
        "github.com/pocketbase/pocketbase/core"
    )
    
    func main() {
        app := pocketbase.New()
    
        app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
            // add new "GET /hello" route to the app router (echo)
            e.Router.AddRoute(echo.Route{
                Method: http.MethodGet,
                Path:   "/hello",
                Handler: func(c echo.Context) error {
                    return c.String(200, "Hello world!")
                },
                Middlewares: []echo.MiddlewareFunc{
                    apis.ActivityLogger(app),
                },
            })
    
            return nil
        })
    
        if err := app.Start(); err != nil {
            log.Fatal(err)
        }
    }
  3. To init the dependencies, run go mod init myapp && go mod tidy.

  4. To start the application, run go run main.go serve.

  5. To build a statically linked executable, you can run CGO_ENABLED=0 go build and then start the created executable with ./myapp serve.

Note

PocketBase embeds SQLite, but doesn't require CGO.

If CGO is enabled (aka. CGO_ENABLED=1), 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.

For more details please refer to Extend with Go.

Building and running the repo main.go example

To build the minimal standalone executable, like the prebuilt ones in the releases page, you can simply run go build inside the examples/base directory:

  1. Install Go 1.21+ (if you haven't already)
  2. Clone/download the repo
  3. Navigate to examples/base
  4. Run GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build (https://go.dev/doc/install/source#environment)
  5. Start the created executable by running ./base serve.

Note that the supported build targets by the pure Go SQLite driver at the moment are:

darwin  amd64
darwin  arm64
freebsd amd64
freebsd arm64
linux   386
linux   amd64
linux   arm
linux   arm64
linux   ppc64le
linux   riscv64
linux   s390x
windows amd64
windows arm64

Testing

PocketBase comes with mixed bag of unit and integration tests. To run them, use the standard go test command:

go test ./...

Check also the Testing guide to learn how to write your own custom application tests.

Security

If you discover a security vulnerability within PocketBase, please send an e-mail to support at pocketbase.io.

All reports will be promptly addressed, and you'll be credited accordingly.

Contributing

PocketBase is free and open source project licensed under the MIT License. You are free to do whatever you want with it, even offering it as a paid service.

You could help continuing its development by:

PRs for new OAuth2 providers, bug fixes, code optimizations and documentation improvements are more than welcome.

But please refrain creating PRs for new features without previously discussing the implementation details. PocketBase has a roadmap and I try to work on issues in specific order and such PRs often come in out of nowhere and skew all initial planning with tedious back-and-forth communication.

Don't get upset if I close your PR, even if it is well executed and tested. This doesn't mean that it will never be merged. Later we can always refer to it and/or take pieces of your implementation when the time comes to work on the issue (don't worry you'll be credited in the release notes).

PocketBase's Projects

benchmarks icon benchmarks

PocketBase test application with various benchmarks

dbx icon dbx

A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.

tygoja icon tygoja

Experimental helper library for generating TypeScript declarations from Go code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.