Created
August 25, 2025 06:54
-
-
Save HuakunShen/562332f3205f313ac413d17b5a1596d3 to your computer and use it in GitHub Desktop.
Pocketbase + Turso
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "os" | |
| "strings" | |
| "github.com/pocketbase/dbx" | |
| "github.com/pocketbase/pocketbase" | |
| "github.com/pocketbase/pocketbase/apis" | |
| "github.com/pocketbase/pocketbase/core" | |
| _ "github.com/tursodatabase/libsql-client-go/libsql" | |
| ) | |
| func main() { | |
| app := pocketbase.NewWithConfig(pocketbase.Config{ | |
| DBConnect: func(dbPath string) (*dbx.DB, error) { | |
| if strings.Contains(dbPath, "data.db") { | |
| return dbx.Open("libsql", "libsql://[DATABASE].turso.io?authToken=[TOKEN]") | |
| } | |
| return core.DefaultDBConnect(dbPath) | |
| }, | |
| }) | |
| app.OnServe().BindFunc(func(se *core.ServeEvent) error { | |
| // serves static files from the provided public dir (if exists) | |
| se.Router.GET("/{path...}", apis.Static(os.DirFS("./pb_public"), false)) | |
| return se.Next() | |
| }) | |
| if err := app.Start(); err != nil { | |
| log.Fatal(err) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment