Documentation
¶
Overview ¶
Package docdb provides embeddable DocDB implementation.
See `build/version` package documentation for information about Go build tags that affect this package.
See telemetry documentation for basic anonymous usage data we collect. You can set Config's Telemetry field to disable or explicitly enable it.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/hanzoai/docdb/docdb"
)
func main() {
f, err := docdb.New(&docdb.Config{
PostgreSQLURL: "postgres://username:password@127.0.0.1:5432/postgres",
ListenAddr: "127.0.0.1:17027",
StateDir: ".",
})
if err != nil {
log.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
go func() {
f.Run(ctx)
close(done)
}()
uri := f.MongoDBURI()
fmt.Println(uri)
// Use MongoDB URI as usual.
// For example:
//
// import "go.mongodb.org/mongo-driver/v2/mongo"
// import "go.mongodb.org/mongo-driver/v2/mongo/options"
//
// [...]
//
// mongo.Connect(options.Client().ApplyURI(uri))
cancel()
<-done
}
Output: mongodb://127.0.0.1:17027/
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// PostgreSQL URL. Required.
PostgreSQLURL string
// Listen TCP address for MongoDB protocol.
// If empty, TCP listener is disabled.
ListenAddr string
// State directory. Required.
StateDir string
// Defaults to [slog.LevelError].
LogLevel slog.Leveler
// Defaults to [io.Discard], effectively disabling logging.
LogOutput io.Writer
// Defaults to undecided.
// Set to `true` to enable telemetry, `false` to disable it.
// See https://docs.docdb.hanzo.ai/telemetry/.
Telemetry *bool
}
Config represents DocDB configuration.
type DocDB ¶
type DocDB struct {
// contains filtered or unexported fields
}
DocDB represents an instance of embedded DocDB implementation.
func (*DocDB) MongoDBURI ¶
MongoDBURI returns MongoDB URI for this DocDB instance.
func (*DocDB) Run ¶
Run runs DocDB until ctx is canceled.
When this method returns, all listeners, all client connections, and all PostgreSQL connections are closed.
It is required to run this method in order to initialize listeners with their respective IP addresses and ports. Calling *DocDB.MongoDBURI before calling this method will result in a deadlock.