Skip to content

Commit df9ca18

Browse files
feat: add support for both local instances and remote clusters (#87)
**Description** This PR reworks modusgraph to allow the creation of applications to use both the internal "engine"-based system as well as traditional Dgraph clusters. I have kept the old API in place for backwards compatibility. There are still a number of TODOs including an update of the CHANGELOG, but wanted to get this up for review ASAP. St **Checklist** - [x] Code compiles correctly and linting passes locally - [ ] For all _code_ changes, an entry added to the `CHANGELOG.md` file describing and linking to this PR - [x] Tests added for new functionality, or regression tests for bug fixes added as applicable
1 parent fff4862 commit df9ca18

35 files changed

+2173
-299
lines changed

CHANGELOG.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
## UNRELEASED
44

55
- feat: add readfrom json tag to support reverse edges
6-
[#49](https://github.com/hypermodeinc/modusDB/pull/49)
6+
[#49](https://github.com/hypermodeinc/modusgraph/pull/49)
77

8-
- chore: Refactoring package management [#51](https://github.com/hypermodeinc/modusDB/pull/51)
8+
- chore: Refactoring package management [#51](https://github.com/hypermodeinc/modusgraph/pull/51)
99

1010
- fix: alter schema on reverse edge after querying schema
11-
[#55](https://github.com/hypermodeinc/modusDB/pull/55)
11+
[#55](https://github.com/hypermodeinc/modusgraph/pull/55)
1212

1313
- feat: update interface to engine and namespace
14-
[#57](https://github.com/hypermodeinc/modusDB/pull/57)
14+
[#57](https://github.com/hypermodeinc/modusgraph/pull/57)
1515

16-
- chore: Update dgraph dependency [#62](https://github.com/hypermodeinc/modusDB/pull/62)
16+
- chore: Update dgraph dependency [#62](https://github.com/hypermodeinc/modusgraph/pull/62)
1717

18-
- fix: add context to api functions [#69](https://github.com/hypermodeinc/modusDB/pull/69)
18+
- fix: add context to api functions [#69](https://github.com/hypermodeinc/modusgraph/pull/69)
1919

2020
## 2025-01-02 - Version 0.1.0
2121

CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Please help us keep the community safe while working on the project by upholding
88
[Code of Conduct](/CODE_OF_CONDUCT.md) at all times.
99

1010
Before jumping to a pull request, ensure you've looked at
11-
[PRs](https://github.com/hypermodeinc/modusdb/pulls) and
12-
[issues](https://github.com/hypermodeinc/modusdb/issues) (open and closed) for existing work related
13-
to your idea.
11+
[PRs](https://github.com/hypermodeinc/modusgraph/pulls) and
12+
[issues](https://github.com/hypermodeinc/modusgraph/issues) (open and closed) for existing work
13+
related to your idea.
1414

1515
If in doubt or contemplating a larger change, join the
1616
[Hypermode Discord](https://discord.hypermode.com) and start a discussion in the
@@ -28,8 +28,8 @@ includes a set of configs to set VS Code up automatically.
2828
### Clone the Modus repository
2929

3030
To contribute code, start by forking the Modus repository. In the top-right of the
31-
[repo](https://github.com/hypermodeinc/modusdb), click **Fork**. Follow the instructions to create a
32-
fork of the repo in your GitHub workspace.
31+
[repo](https://github.com/hypermodeinc/modusgraph), click **Fork**. Follow the instructions to
32+
create a fork of the repo in your GitHub workspace.
3333

3434
### Building and running tests
3535

README.md

+65-46
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div align="center">
22

3-
[![modus](https://github.com/user-attachments/assets/1a6020bd-d041-4dd0-b4a9-ce01dc015b65)](https://github.com/hypermodeinc/modusdb)
3+
[![modus](https://github.com/user-attachments/assets/1a6020bd-d041-4dd0-b4a9-ce01dc015b65)](https://github.com/hypermodeinc/modusgraph)
44

5-
[![GitHub License](https://img.shields.io/github/license/hypermodeinc/modusdb)](https://github.com/hypermodeinc/modusdb?tab=Apache-2.0-1-ov-file#readme)
5+
[![GitHub License](https://img.shields.io/github/license/hypermodeinc/modusdb)](https://github.com/hypermodeinc/modusgraph?tab=Apache-2.0-1-ov-file#readme)
66
[![chat](https://img.shields.io/discord/1267579648657850441)](https://discord.gg/NJQ4bJpffF)
7-
[![GitHub Repo stars](https://img.shields.io/github/stars/hypermodeinc/modusdb)](https://github.com/hypermodeinc/modusdb/stargazers)
8-
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/hypermodeinc/modusdb)](https://github.com/hypermodeinc/modusdb/commits/main/)
7+
[![GitHub Repo stars](https://img.shields.io/github/stars/hypermodeinc/modusdb)](https://github.com/hypermodeinc/modusgraph/stargazers)
8+
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/hypermodeinc/modusdb)](https://github.com/hypermodeinc/modusgraph/commits/main/)
99

1010
</div>
1111

@@ -15,17 +15,20 @@
1515
<a href="https://discord.gg/4z4GshR7fq">Discord</a>
1616
<p>
1717

18-
**ModusDB is a high-performance, transactional database system.** It's designed to be type-first,
19-
schema-agnostic, and portable. ModusDB provides object-oriented APIs that makes it simple to build
18+
**modusGraph is a high-performance, transactional database system.** It's designed to be type-first,
19+
schema-agnostic, and portable. ModusGraph provides object-oriented APIs that make it simple to build
2020
new apps, paired with support for advanced use cases through the Dgraph Query Language (DQL). A
2121
dynamic schema allows for natural relations to be expressed in your data with performance that
2222
scales with your use case.
2323

24-
ModusDB is available as a Go package for running in-process, providing low-latency reads, writes,
25-
and vector searches. We’ve made trade-offs to prioritize speed and simplicity.
24+
ModusGraph is available as a Go package for running in-process, providing low-latency reads, writes,
25+
and vector searches. We’ve made trade-offs to prioritize speed and simplicity. When runnning
26+
in-process, modusGraph internalizes Dgraph's server components, and data is written to a local
27+
file-based database. modusGraph also supports remote Dgraph servers, allowing you deploy your apps
28+
to any Dgraph cluster simply by changing the connection string.
2629

2730
The [modus framework](https://github.com/hypermodeinc/modus) is optimized for apps that require
28-
sub-second response times. ModusDB augments polyglot functions with simple to use data and vector
31+
sub-second response times. ModusGraph augments polyglot functions with simple to use data and vector
2932
storage. When paired together, you can build a complete AI semantic search or retrieval-augmented
3033
generation (RAG) feature with a single framework.
3134

@@ -35,49 +38,63 @@ generation (RAG) feature with a single framework.
3538
package main
3639

3740
import (
38-
"github.com/hypermodeinc/modusdb"
41+
"context"
42+
"fmt"
43+
"time"
44+
45+
mg "github.com/hypermodeinc/modusgraph"
3946
)
4047

41-
type User struct {
42-
Gid uint64 `json:"gid,omitempty"`
43-
Id string `json:"id,omitempty" db:"constraint=unique"`
44-
Name string `json:"name,omitempty"`
45-
Age int `json:"age,omitempty"`
48+
type TestEntity struct {
49+
Name string `json:"name,omitempty" dgraph:"index=exact"`
50+
Description string `json:"description,omitempty" dgraph:"index=term"`
51+
CreatedAt time.Time `json:"createdAt,omitempty"`
52+
53+
// UID is a required field for nodes
54+
UID string `json:"uid,omitempty"`
55+
// DType is a required field for nodes, will get populated with the struct name
56+
DType []string `json:"dgraph.type,omitempty"`
4657
}
4758

4859
func main() {
49-
engine, err := modusdb.NewEngine(modusdb.NewDefaultConfig("/local/modusdb"))
50-
if err != nil {
51-
panic(err)
52-
}
53-
defer engine.Close()
54-
55-
gid, user, err := modusdb.Upsert(ns, User{
56-
Id: "123",
57-
Name: "A",
58-
Age: 10,
59-
})
60-
if err != nil {
61-
panic(err)
62-
}
63-
fmt.Println(user)
64-
65-
_, queriedUser, err := modusdb.Get[User](ns, gid)
66-
if err != nil {
67-
panic(err)
68-
}
69-
fmt.Println(queriedUser)
70-
71-
_, _, err = modusdb.Delete[User](ns, gid)
72-
if err != nil {
73-
panic(err)
74-
}
60+
// Use a file URI to connect to a in-process modusGraph instance, ensure that the directory exists
61+
uri := "file:///tmp/modusgraph"
62+
// Assigning a Dgraph URI will connect to a remote Dgraph server
63+
// uri := "dgraph://localhost:9080"
64+
65+
client, err := mg.NewClient(uri, mg.WithAutoSchema(true))
66+
if err != nil {
67+
panic(err)
68+
}
69+
defer client.Close()
70+
71+
entity := TestEntity{
72+
Name: "Test Entity",
73+
Description: "This is a test entity",
74+
CreatedAt: time.Now(),
75+
}
76+
77+
ctx := context.Background()
78+
err = client.Insert(ctx, &entity)
79+
80+
if err != nil {
81+
panic(err)
82+
}
83+
fmt.Println("Insert successful, entity UID:", entity.UID)
84+
85+
// Query the entity
86+
var result TestEntity
87+
err = client.Get(ctx, &result, entity.UID)
88+
if err != nil {
89+
panic(err)
90+
}
91+
fmt.Println("Query successful, entity:", result.UID)
7592
}
7693
```
7794

7895
## Open Source
7996

80-
The modus framework, including modusDB, is developed by [Hypermode](https://hypermode.com/) as an
97+
The modus framework, including modusGraph, is developed by [Hypermode](https://hypermode.com/) as an
8198
open-source project, integral but independent from Hypermode.
8299

83100
We welcome external contributions. See the [CONTRIBUTING.md](./CONTRIBUTING.md) file if you would
@@ -90,9 +107,11 @@ us at <[email protected]>.
90107

91108
## Acknowledgements
92109

93-
ModusDB builds heavily upon packages from the open source projects of
110+
modusGraph builds heavily upon packages from the open source projects of
94111
[Dgraph](https://github.com/hypermodeinc/dgraph) (graph query processing and transaction
95112
management), [Badger](https://github.com/dgraph-io/badger) (data storage), and
96-
[Ristretto](https://github.com/dgraph-io/ristretto) (cache). We expect the architecture and
97-
implementations of modusDB and Dgraph to expand in differentiation over time as the projects
98-
optimize for different core use cases, while maintaining Dgraph Query Language (DQL) compatibility.
113+
[Ristretto](https://github.com/dgraph-io/ristretto) (cache). modusGraph also relies on the
114+
[dgman](https://github.com/dolan-in/dgman) repository for much of its functionality. We expect the
115+
architecture and implementations of modusGraph and Dgraph to expand in differentiation over time as
116+
the projects optimize for different core use cases, while maintaining Dgraph Query Language (DQL)
117+
compatibility.

0 commit comments

Comments
 (0)