Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 8e19ed8

Browse files
feat: support MySQL database connections (#722)
1 parent 973f7ed commit 8e19ed8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4861
-343
lines changed

.trunk/configs/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"datasource",
3434
"dbname",
3535
"dbpool",
36+
"dburl",
3637
"dcli",
3738
"Debugf",
3839
"dgraph",
@@ -87,6 +88,7 @@
8788
"jackc",
8889
"Jairus",
8990
"jensneuse",
91+
"jmoiron",
9092
"joho",
9193
"jsonlogs",
9294
"jsonparser",

.vscode/launch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@
171171
"label": "HTTP Client Example",
172172
"value": "http"
173173
},
174+
{
175+
"label": "MySQL Client Example",
176+
"value": "mysql"
177+
},
174178
{
175179
"label": "Neo4j Client Example",
176180
"value": "neo4j"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[#707](https://github.com/hypermodeinc/modus/pull/707)
1414
- feat: support type aliases and redefinitions
1515
[#721](https://github.com/hypermodeinc/modus/pull/721)
16+
- feat: support MySQL database connections [#722](https://github.com/hypermodeinc/modus/pull/722)
1617

1718
## 2025-01-09 - CLI 0.16.6
1819

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use (
1717
./sdk/go/examples/embedding
1818
./sdk/go/examples/graphql
1919
./sdk/go/examples/http
20+
./sdk/go/examples/mysql
2021
./sdk/go/examples/neo4j
2122
./sdk/go/examples/postgresql
2223
./sdk/go/examples/simple

lib/manifest/manifest.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ func parseManifestJson(data []byte, manifest *Manifest) error {
172172
}
173173
info.Name = name
174174
manifest.Connections[name] = info
175+
case ConnectionTypeMysql:
176+
var info MysqlConnectionInfo
177+
if err := json.Unmarshal(rawCon, &info); err != nil {
178+
return fmt.Errorf("failed to parse mysql connection [%s]: %w", name, err)
179+
}
180+
info.Name = name
181+
manifest.Connections[name] = info
175182
case ConnectionTypeDgraph:
176183
var info DgraphConnectionInfo
177184
if err := json.Unmarshal(rawCon, &info); err != nil {

lib/manifest/modus_schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@
219219
"required": ["type", "connString"],
220220
"additionalProperties": false
221221
},
222+
{
223+
"properties": {
224+
"type": {
225+
"type": "string",
226+
"const": "mysql",
227+
"description": "Type of the connection."
228+
},
229+
"connString": {
230+
"type": "string",
231+
"minLength": 1,
232+
"pattern": "^mysql:\\/\\/(.*?@)?([0-9a-zA-Z.-]*?)(:\\d+)?(\\/[0-9a-zA-Z.-]+)?(\\?.+)?$",
233+
"description": "The MySQL connection string in URI format.",
234+
"markdownDescription": "The MySQL connection string in URI format.\n\nReference: https://docs.hypermode.com/modus/app-manifest#mysql-connection"
235+
}
236+
},
237+
"required": ["type", "connString"],
238+
"additionalProperties": false
239+
},
222240
{
223241
"properties": {
224242
"type": {

lib/manifest/mysql.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 Hypermode Inc.
3+
* Licensed under the terms of the Apache License, Version 2.0
4+
* See the LICENSE file that accompanied this code for further details.
5+
*
6+
* SPDX-FileCopyrightText: 2025 Hypermode Inc. <hello@hypermode.com>
7+
* SPDX-License-Identifier: Apache-2.0
8+
*/
9+
10+
package manifest
11+
12+
const ConnectionTypeMysql ConnectionType = "mysql"
13+
14+
type MysqlConnectionInfo struct {
15+
Name string `json:"-"`
16+
Type ConnectionType `json:"type"`
17+
ConnStr string `json:"connString"`
18+
}
19+
20+
func (info MysqlConnectionInfo) ConnectionName() string {
21+
return info.Name
22+
}
23+
24+
func (info MysqlConnectionInfo) ConnectionType() ConnectionType {
25+
return info.Type
26+
}
27+
28+
func (info MysqlConnectionInfo) Hash() string {
29+
return computeHash(info.Name, info.Type, info.ConnStr)
30+
}
31+
32+
func (info MysqlConnectionInfo) Variables() []string {
33+
return extractVariables(info.ConnStr)
34+
}

lib/manifest/test/manifest_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func TestReadManifest(t *testing.T) {
9797
Type: manifest.ConnectionTypePostgresql,
9898
ConnStr: "postgresql://{{POSTGRESQL_USERNAME}}:{{POSTGRESQL_PASSWORD}}@1.2.3.4:5432/data?sslmode=disable",
9999
},
100+
"my-mysql": manifest.MysqlConnectionInfo{
101+
Name: "my-mysql",
102+
Type: manifest.ConnectionTypeMysql,
103+
ConnStr: "mysql://{{MYSQL_USERNAME}}:{{MYSQL_PASSWORD}}@1.2.3.4:3306/mydb?sslmode=disable",
104+
},
100105
"my-dgraph-cloud": manifest.DgraphConnectionInfo{
101106
Name: "my-dgraph-cloud",
102107
Type: manifest.ConnectionTypeDgraph,
@@ -207,6 +212,20 @@ func TestPostgresConnectionInfo_Hash(t *testing.T) {
207212
}
208213
}
209214

215+
func TestMysqlConnectionInfo_Hash(t *testing.T) {
216+
connection := manifest.MysqlConnectionInfo{
217+
Name: "my-database",
218+
ConnStr: "mysql://{{MYSQL_USERNAME}}:{{MYSQL_PASSWORD}}@1.2.3.4:3306/mydb?sslmode=disable",
219+
}
220+
221+
expectedHash := "3b96055cec5bd4195901e1442c856fe5b5493b0af0dde8f64f1d14a4795f5272"
222+
223+
actualHash := connection.Hash()
224+
if actualHash != expectedHash {
225+
t.Errorf("Expected hash: %s, but got: %s", expectedHash, actualHash)
226+
}
227+
}
228+
210229
func TestDgraphCloudConnectionInfo_Hash(t *testing.T) {
211230
connection := manifest.DgraphConnectionInfo{
212231
Name: "my-dgraph-cloud",
@@ -259,6 +278,7 @@ func TestGetVariablesFromManifest(t *testing.T) {
259278
"my-rest-api": {"API_TOKEN"},
260279
"another-rest-api": {"USERNAME", "PASSWORD"},
261280
"neon": {"POSTGRESQL_USERNAME", "POSTGRESQL_PASSWORD"},
281+
"my-mysql": {"MYSQL_USERNAME", "MYSQL_PASSWORD"},
262282
"my-dgraph-cloud": {"DGRAPH_KEY"},
263283
"my-neo4j": {"NEO4J_USERNAME", "NEO4J_PASSWORD"},
264284
}

lib/manifest/test/valid_modus.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
"type": "postgresql",
6565
"connString": "postgresql://{{POSTGRESQL_USERNAME}}:{{POSTGRESQL_PASSWORD}}@1.2.3.4:5432/data?sslmode=disable"
6666
},
67+
"my-mysql": {
68+
"type": "mysql",
69+
"connString": "mysql://{{MYSQL_USERNAME}}:{{MYSQL_PASSWORD}}@1.2.3.4:3306/mydb?sslmode=disable"
70+
},
6771
"my-dgraph-cloud": {
6872
"type": "dgraph",
6973
"grpcTarget": "frozen-mango.grpc.eu-central-1.aws.cloud.dgraph.io:443",

runtime/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
github.com/docker/go-connections v0.5.0
2525
github.com/fatih/color v1.18.0
2626
github.com/getsentry/sentry-go v0.31.1
27+
github.com/go-sql-driver/mysql v1.8.1
2728
github.com/go-viper/mapstructure/v2 v2.2.1
2829
github.com/goccy/go-json v0.10.4
2930
github.com/gofrs/flock v0.12.1
@@ -46,15 +47,18 @@ require (
4647
github.com/tetratelabs/wazero v1.8.2
4748
github.com/tidwall/gjson v1.18.0
4849
github.com/tidwall/sjson v1.2.5
50+
github.com/twpayne/go-geom v1.6.0
4951
github.com/viterin/vek v0.4.2
5052
github.com/wundergraph/graphql-go-tools/execution v1.2.0
5153
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.142
54+
github.com/xo/dburl v0.23.2
5255
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
5356
golang.org/x/sys v0.29.0
5457
google.golang.org/grpc v1.69.4
5558
)
5659

5760
require (
61+
filippo.io/edwards25519 v1.1.0 // indirect
5862
github.com/Microsoft/go-winio v0.6.2 // indirect
5963
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
6064
github.com/aws/aws-sdk-go-v2/credentials v1.17.54 // indirect

0 commit comments

Comments
 (0)