-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add SurrealDB driver for Magic #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92fa565
feat: add surrealdb driver + example scaffold
Unbreathable 1dfce88
feat: surrealdb example + scripting fixes
Unbreathable fae4110
Merge remote-tracking branch 'origin/main' into feat/surrealdb
Unbreathable 17be8dd
fix: make sure tests run
Unbreathable 7ec43e9
Potential fix for pull request finding
Unbreathable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| 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), | ||
| }, | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| module surrealdb-example | ||
|
|
||
| go 1.27.0 | ||
|
|
||
| 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 | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.