Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Magic only officially supports a limited list of services, but you can easily in

- [PostgreSQL](https://liphium.dev/magic/databases/postgresql/) v18
- [Redis](https://liphium.dev/magic/databases/redis/) v7-8
- [SurrealDB](https://liphium.dev/magic/databases/surrealdb/) v3

### Supported S3 Storage

Expand Down
54 changes: 54 additions & 0 deletions examples/surrealdb/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"fmt"

"github.com/Liphium/magic/pkg/databases/surrealdb"

"github.com/Liphium/magic/v4"
"github.com/Liphium/magic/v4/mconfig"
"github.com/Liphium/magic/v4/scripting"
)

func BuildConfig() magic.Config {
return magic.Config{
AppName: "magic-example-surrealdb",
PlanDeployment: func(ctx *mconfig.Context) {

// Create the SurrealDB driver
driver := surrealdb.NewDriver("surrealdb/surrealdb:v3").
NewDatabase("liphium", "posts")
ctx.Register(driver)

// Allocate a new port for the service. This makes it possible to run multiple instances of this app locally, without weird configuration hell. Magic will pick a port in case the preferred one is taken.
port := ctx.ValuePort(8080)

// Register the environment variables required for connecting in surreal.go
ctx.WithEnvironment(mconfig.Environment{
"SURREAL_HOST": mconfig.ValueWithBase([]mconfig.EnvironmentValue{driver.Host(ctx), driver.Port(ctx)}, func(s []string) string {
return fmt.Sprintf("ws://%s:%s", s[0], s[1])
}),
"SURREAL_USER": driver.Username(),
"SURREAL_PASSWORD": driver.Password(),
"SURREAL_NS": mconfig.ValueStatic("liphium"),
"SURREAL_DB": mconfig.ValueStatic("posts"),

// Make the server listen on localhost using the port allocated by Magic
"LISTEN": mconfig.ValueWithBase([]mconfig.EnvironmentValue{port}, func(s []string) string {
return fmt.Sprintf("127.0.0.1:%s", s[0])
}),
})
},
StartFunction: Start,
Scripts: []scripting.Script{
// Scripts to deal with the database, can always come in handy
scripting.CreateScript("db-reset", "Reset the database by dropping all tables", ResetDatabase),
scripting.CreateScript("db-clear", "Clear the database by truncating all tables", ClearDatabases),
scripting.CreateScript("db-seed", "Seed the database with sample posts", SeedDatabase),

// Scripts to call endpoints, really useful for tests and development
scripting.CreateScript("create-post", "Create a post using the endpoint", CreatePost),
scripting.CreateScript("list-posts", "List posts using the endpoint", PrintPosts),
},
}
}
90 changes: 90 additions & 0 deletions examples/surrealdb/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module surrealdb-example

go 1.27.0
Comment thread
Unbreathable marked this conversation as resolved.

replace github.com/Liphium/magic/v4 => ../../.

replace github.com/Liphium/magic/pkg/databases/surrealdb => ../../pkg/databases/surrealdb

require (
github.com/Liphium/magic/pkg/databases/surrealdb v0.0.0-00010101000000-000000000000
github.com/Liphium/magic/v4 v4.0.0
github.com/gofiber/fiber/v2 v2.52.15
github.com/stretchr/testify v1.11.1
github.com/surrealdb/surrealdb.go v1.7.0
resty.dev/v3 v3.0.0-rc.3
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/bubbles v1.0.0 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/huh v1.0.0 // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.11.8 // indirect
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
github.com/charmbracelet/x/exp/strings v0.1.0 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.11.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-connections v0.8.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/felixge/httpsnoop v1.1.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.15 // indirect
github.com/go-logr/logr v1.4.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.3 // indirect
github.com/gofrs/flock v0.13.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/leodido/go-urn v1.5.0 // indirect
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.27 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/moby/api v1.55.0 // indirect
github.com/moby/moby/client v0.5.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xo/terminfo v1.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0 // indirect
go.opentelemetry.io/otel v1.45.0 // indirect
go.opentelemetry.io/otel/metric v1.45.0 // indirect
go.opentelemetry.io/otel/trace v1.45.0 // indirect
golang.org/x/crypto v0.55.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.41.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading