dgdao #9779
matthewmcneely
announced in
Announcements
dgdao
#9779
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We're happy to announce that dgdao is now available at github.com/dgraph-io/dgdao. dgdao is a type-first, transactional database layer for Go, built on Dgraph. You define plain Go structs with
dgraphtags, and dgdao gives you ORM/DAO-likeInsert/Get/Querymechanics, automatic schema management, and full access to DQL when you need to drop down for advanced queries.The part you find most useful: dgdao runs in-process. Point the client at a
file://URI and it internalizes Dgraph's server components, writing to a local file-based database with low-latency reads, writes, and vector searches. There's no separate server to stand up, which makes it a natural fit for development, testing, and embedded applications. When you're ready to deploy against a real cluster, change the connection string todgraph://host:9080and the same code runs against any remote Dgraph server.There's also a generics-based typed client for those who want compile-time type safety without code generation. The
typedpackage wraps the base client in a Go generic layer: bind your type once withtyped.NewClient[User](client)and you get typed CRUD plus a fluent query builder whereNodes()returns[]Userdirectly, with no destination slices or decode steps at call sites. The builder supports composable filters,OrGroupfor parenthesized OR scopes,WhereEdgefor constraining by a neighbour's scalar over an edge (rendered as a server-sidevarblock so memory stays bounded), auto-paging iteration over a single read-only snapshot, andMultiQueryfor batching several queries into one round-trip. It composes on the same primitives as the base client, so you keep full access to Dgraph's query power.Beyond the basics, dgdao includes schema validation with a
Validatorhook, aDefaulterhook for before-write defaulting, automatic retries, and vector search over embeddings. Auto-schema (dg.WithAutoSchema(true)) derives predicates and indexes directly from your struct tags, so your Go types stay the single source of truth.A good fit for AI-assisted development
If you're building Go applications with coding agents, dgdao removes a lot of friction. An agent can write code against the typed client, spin up a real database with nothing more than a
file://URI, and run the full test suite locally, with no containers, servers, or credentials to configure. Struct tags keep the schema in the code itself, so the agent sees the whole data model in one place, and the compiler catches a large class of mistakes that would otherwise surface at runtime. And because the same code runs unchanged against a remote cluster, what an agent builds and verifies locally scales to Dgraph's well-documented distributed graph capabilities, including horizontal scaling, replication, and multi-tenancy, just by swapping the connection string.Companion repos
There are also companion repos under the
dgraph-ioorg, each an independent Go module you can adopt on its own:go generateagainst your structs and get a fully typed client, query builders, and auto-paging iterators.The README has a copy-paste quickstart, and the
examples/directory covers common patterns, including loading the 1million movie RDF dataset for benchmarking. One caveat: dgdao targets POSIX systems and isn't guaranteed to work on Windows. Everything is Apache 2.0 and contributions are welcome.All reactions