Skip to content

Commit 1807d6a

Browse files
authored
Merge pull request #15 from kefniark/feature/mysql
Implement Mysql + Mariadb drivers
2 parents b6feaa7 + 414dad1 commit 1807d6a

35 files changed

+1704
-121
lines changed

cmd/mangosql/mangosql.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"fmt"
77
"go/format"
8-
"log"
98
"os"
109
"path"
1110
"regexp"
@@ -16,9 +15,15 @@ import (
1615
"github.com/urfave/cli/v2"
1716
)
1817

18+
var (
19+
version = "dev"
20+
commit = "none"
21+
date = "unknown"
22+
)
23+
1924
func main() {
2025
app := &cli.App{
21-
Version: "v0.0.1",
26+
Version: fmt.Sprintf("%s (%s - %s)", version, commit, date),
2227
Name: "mangosql",
2328
HelpName: "MangoSQL",
2429
Usage: "Generate a SQL Client from a SQL file or folder of SQL migrations",
@@ -62,7 +67,7 @@ Example: mangosql --output db/file.go db/schema.sql`,
6267
return fmt.Errorf("missing source folder")
6368
}
6469

65-
allowed_drivers := []string{"pq", "pgx", "sqlite"}
70+
allowed_drivers := []string{"pq", "pgx", "sqlite", "mysql", "mariadb"}
6671
driver := ctx.String("driver")
6772
if !slices.Contains(allowed_drivers, driver) {
6873
return fmt.Errorf("unknown driver, should be one of %v", allowed_drivers)
@@ -87,7 +92,8 @@ Example: mangosql --output db/file.go db/schema.sql`,
8792
}
8893

8994
if err := app.Run(os.Args); err != nil {
90-
log.Fatal(err)
95+
fmt.Println("\033[31mError\033[0m:", err)
96+
os.Exit(1)
9197
}
9298
}
9399

devenv.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"devenv": {
44
"locked": {
55
"dir": "src/modules",
6-
"lastModified": 1724251323,
6+
"lastModified": 1724504184,
77
"owner": "cachix",
88
"repo": "devenv",
9-
"rev": "5340ef87de79a5e23414e6707cc90009e97745d5",
10-
"treeHash": "f09dcc233cb82d8ccafebd393e124824a0e25b55",
9+
"rev": "51338b58fd666f448db7486ec145dbe52db9b829",
10+
"treeHash": "cedf6d41b00189dfd5132772cb5f35fcb10a7f7b",
1111
"type": "github"
1212
},
1313
"original": {
@@ -112,11 +112,11 @@
112112
"nixpkgs-stable": "nixpkgs-stable"
113113
},
114114
"locked": {
115-
"lastModified": 1724227338,
115+
"lastModified": 1724440431,
116116
"owner": "cachix",
117117
"repo": "pre-commit-hooks.nix",
118-
"rev": "6cedaa7c1b4f82a266e5d30f212273e60d62cb0d",
119-
"treeHash": "698918d3a04360f1dfd19164903511a167368ec1",
118+
"rev": "c8a54057aae480c56e28ef3e14e4960628ac495b",
119+
"treeHash": "40ee1da550348c789ed9503eea365533a618506c",
120120
"type": "github"
121121
},
122122
"original": {

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
version: "3.6"
22
services:
3+
mysqltestdb:
4+
image: mysql:8.0
5+
environment:
6+
MYSQL_ROOT_PASSWORD: root
7+
MYSQL_USER: user
8+
MYSQL_PASSWORD: password
9+
MYSQL_DATABASE: test
10+
restart: unless-stopped
11+
ports:
12+
- "3307:3306"
13+
14+
mariatestdb:
15+
image: mariadb:latest
16+
environment:
17+
MYSQL_ROOT_PASSWORD: root
18+
MYSQL_USER: user
19+
MYSQL_PASSWORD: password
20+
MYSQL_DATABASE: test
21+
restart: unless-stopped
22+
ports:
23+
- "3306:3306"
24+
325
pgtestdb:
426
image: postgres:16
527
environment:

docs/bench/bench.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { withBase } from 'vitepress'
44

55
# Benchmark
66

7-
The following benchmarks are just here to help development and give a general performance idea of MangoSQL.
7+
The benchmarks provided are meant to help development and offer a general sense of MangoSQL's performance. They are not intended to be exhaustive or compare every available method or library.
88

9-
It's not intended to cover every method or library on the market.
9+
MangoSQL’s speed is not a primary objective, it's rather a byproduct of its design. By eliminating abstraction, reducing indirection, and directly interfacing with drivers, the system minimizes overhead.
1010

1111
## Postgres
1212

docs/getting-started/index.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ go install github.com/kefniark/mango-sql/cmd/mangosql
1414
mangosql schema.sql
1515
```
1616

17-
```sh [docker]
18-
# Download from docker registry: https://github.com/kefniark/mango-sql/pkgs/container/mango-sql
17+
```sh [manual]
18+
# Download the last release from https://github.com/kefniark/mango-sql/releases
1919

2020
# Use MangoSQL CLI
21-
docker run -it -v [MOUNT FOLDER]:/app/ ghcr.io/kefniark/mango-sql:latest -i /app/[YOUR SQL FILE] > [OUTPUT GO FILE]
22-
23-
# Example
24-
docker run -it -v .:/app/ ghcr.io/kefniark/mango-sql:latest -i /app/schema.sql > client.go
25-
26-
# -i/--inline: allow to get the generated code without dealing with volume mount and permission issues
21+
./mangosql schema.sql
2722
```
2823

29-
```sh [manual]
30-
# Download the last release from https://github.com/kefniark/mango-sql/releases
24+
```sh [docker]
25+
# Download from docker registry: https://github.com/kefniark/mango-sql/pkgs/container/mango-sql
3126

3227
# Use MangoSQL CLI
33-
./mangosql schema.sql
28+
docker run -t --rm -v .:/app/ \
29+
ghcr.io/kefniark/mango-sql:latest \
30+
-i /app/schema.sql > client.go
31+
32+
# -i/--inline: allow to output the generated file to the console
3433
```
3534

3635
:::
@@ -55,6 +54,22 @@ mangosql --driver sqlite ./schema.sql
5554
mangosql --output ./myfolder --package myfolder --driver sqlite ./schema.sql
5655
```
5756

57+
```sh [mariadb]
58+
# Default command (output: ./database/client.go)
59+
mangosql --driver mariadb ./schema.sql
60+
61+
# Or: Output in a specific folder
62+
mangosql --output ./myfolder --package myfolder --driver mariadb ./schema.sql
63+
```
64+
65+
```sh [mysql]
66+
# Default command (output: ./database/client.go)
67+
mangosql --driver mysql ./schema.sql
68+
69+
# Or: Output in a specific folder
70+
mangosql --output ./myfolder --package myfolder --driver mysql ./schema.sql
71+
```
72+
5873
:::
5974

6075
* `./schema.sql`: Input schema, accept a SQL file or a directory of migrations

docs/getting-started/usage.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ func NewDBClient() (db *DBClient, close func()) {
5555
}
5656
```
5757

58+
```go [mariadb/mysql]
59+
import (
60+
"context"
61+
62+
"github.com/jmoiron/sqlx"
63+
_ "github.com/go-sql-driver/mysql"
64+
)
65+
66+
// TODO: Update mysql/mariadb connection url
67+
// Ref: https://github.com/go-sql-driver/mysql
68+
// example: user:password@tcp(127.0.0.1:3306)/dbname?parseTime=true
69+
const databaseURL := "{CONNECTION URL TO YOUR DATABASE}"
70+
71+
func NewDBClient() (db *DBClient, close func()) {
72+
db, err := sqlx.Open("mysql", databaseURL)
73+
if err != nil {
74+
panic(err)
75+
}
76+
77+
return New(db), func() {
78+
db.Close()
79+
}
80+
}
81+
```
82+
5883
:::
5984

6085
## Enjoy MangoSQL

docs/public/bench_postgres_findmany_alloc.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
</head>
1010

1111
<body><div class="container">
12-
<div class="item" id="UTHMMxeRfgFA" style="width:576px;height:320px;"></div>
12+
<div class="item" id="RonWfyTtinEl" style="width:576px;height:320px;"></div>
1313
</div><script type="text/javascript">
1414
"use strict";
15-
let goecharts_UTHMMxeRfgFA = echarts.init(document.getElementById('UTHMMxeRfgFA'), "shine", { renderer: "canvas" });
16-
let option_UTHMMxeRfgFA = {"legend":{},"series":[{"name":"GormPGX","type":"line","data":[{"value":121},{"value":465},{"value":1082},{"value":2163},{"value":4325},{"value":10789},{"value":22040},{"value":1090},{"value":437},{"value":981},{"value":1888},{"value":3703},{"value":9270},{"value":18535}]},{"name":"MangoPGX","type":"line","data":[{"value":40},{"value":102},{"value":223},{"value":424},{"value":825},{"value":2027},{"value":4541},{"value":1190},{"value":325},{"value":631},{"value":1138},{"value":2142},{"value":5152},{"value":10162}]},{"name":"MangoPQ","type":"line","data":[{"value":41},{"value":121},{"value":257},{"value":483},{"value":934},{"value":2286},{"value":5058},{"value":1190},{"value":293},{"value":580},{"value":1057},{"value":2008},{"value":4862},{"value":9618}]}],"title":{"text":"FindMany|Mem","subtext":"Lower is Better (allocs/op)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
15+
let goecharts_RonWfyTtinEl = echarts.init(document.getElementById('RonWfyTtinEl'), "shine", { renderer: "canvas" });
16+
let option_RonWfyTtinEl = {"legend":{},"series":[{"name":"GormPGX","type":"line","data":[{"value":122},{"value":475},{"value":1107},{"value":2213},{"value":4425},{"value":11039},{"value":22541},{"value":1100},{"value":446},{"value":1006},{"value":1938},{"value":3803},{"value":9521},{"value":19039}]},{"name":"MangoPGX","type":"line","data":[{"value":41},{"value":102},{"value":223},{"value":424},{"value":825},{"value":2027},{"value":4542},{"value":1220},{"value":335},{"value":656},{"value":1188},{"value":2242},{"value":5402},{"value":10662}]},{"name":"MangoPQ","type":"line","data":[{"value":41},{"value":121},{"value":257},{"value":483},{"value":934},{"value":2285},{"value":5058},{"value":1210},{"value":293},{"value":580},{"value":1057},{"value":2008},{"value":4862},{"value":9618}]}],"title":{"text":"FindMany|Mem","subtext":"Lower is Better (allocs/op)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
1717

18-
goecharts_UTHMMxeRfgFA.setOption(option_UTHMMxeRfgFA);
18+
goecharts_RonWfyTtinEl.setOption(option_RonWfyTtinEl);
1919
</script>
2020
<style>
2121
.container {margin-top:30px; display: flex;justify-content: center;align-items: center;}

docs/public/bench_postgres_findmany_cpu.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
</head>
1010

1111
<body><div class="container">
12-
<div class="item" id="VxFbtyzyZZqC" style="width:576px;height:320px;"></div>
12+
<div class="item" id="FinTqiRZVJaq" style="width:576px;height:320px;"></div>
1313
</div><script type="text/javascript">
1414
"use strict";
15-
let goecharts_VxFbtyzyZZqC = echarts.init(document.getElementById('VxFbtyzyZZqC'), "shine", { renderer: "canvas" });
16-
let option_VxFbtyzyZZqC = {"legend":{},"series":[{"name":"GormPGX","type":"line","data":[{"value":2437},{"value":1857},{"value":1403},{"value":952},{"value":553},{"value":214},{"value":127},{"value":606},{"value":4474},{"value":2861},{"value":1925},{"value":1011},{"value":404},{"value":213}]},{"name":"MangoPGX","type":"line","data":[{"value":6889},{"value":4763},{"value":3319},{"value":2074},{"value":1146},{"value":457},{"value":220},{"value":662},{"value":4938},{"value":3742},{"value":2585},{"value":1580},{"value":660},{"value":319}]},{"name":"MangoPQ","type":"line","data":[{"value":7399},{"value":5061},{"value":3449},{"value":2194},{"value":1181},{"value":472},{"value":234},{"value":734},{"value":5388},{"value":3944},{"value":2561},{"value":1559},{"value":676},{"value":329}]}],"title":{"text":"FindMany|CPU","subtext":"Higher is Better (op/s)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
15+
let goecharts_FinTqiRZVJaq = echarts.init(document.getElementById('FinTqiRZVJaq'), "shine", { renderer: "canvas" });
16+
let option_FinTqiRZVJaq = {"legend":{},"series":[{"name":"GormPGX","type":"line","data":[{"value":2429},{"value":1908},{"value":1453},{"value":971},{"value":561},{"value":219},{"value":128},{"value":604},{"value":4173},{"value":2932},{"value":1922},{"value":1045},{"value":432},{"value":185}]},{"name":"MangoPGX","type":"line","data":[{"value":6711},{"value":4795},{"value":3234},{"value":2133},{"value":1154},{"value":449},{"value":223},{"value":651},{"value":4948},{"value":3678},{"value":2582},{"value":1515},{"value":659},{"value":306}]},{"name":"MangoPQ","type":"line","data":[{"value":7443},{"value":5004},{"value":3393},{"value":2158},{"value":1197},{"value":477},{"value":238},{"value":719},{"value":5477},{"value":3483},{"value":2623},{"value":1582},{"value":675},{"value":307}]}],"title":{"text":"FindMany|CPU","subtext":"Higher is Better (op/s)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
1717

18-
goecharts_VxFbtyzyZZqC.setOption(option_VxFbtyzyZZqC);
18+
goecharts_FinTqiRZVJaq.setOption(option_FinTqiRZVJaq);
1919
</script>
2020
<style>
2121
.container {margin-top:30px; display: flex;justify-content: center;align-items: center;}

docs/public/bench_postgres_insertmany_alloc.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
</head>
1010

1111
<body><div class="container">
12-
<div class="item" id="IhywVMYWTAuI" style="width:576px;height:320px;"></div>
12+
<div class="item" id="EWakwZPOUEFv" style="width:576px;height:320px;"></div>
1313
</div><script type="text/javascript">
1414
"use strict";
15-
let goecharts_IhywVMYWTAuI = echarts.init(document.getElementById('IhywVMYWTAuI'), "shine", { renderer: "canvas" });
16-
let option_IhywVMYWTAuI = {"legend":{},"series":[{"name":"GormPGX","type":"line","data":[{"value":121},{"value":465},{"value":1082},{"value":2163},{"value":4325},{"value":10789},{"value":22040},{"value":1090},{"value":437},{"value":981},{"value":1888},{"value":3703},{"value":9270},{"value":18535}]},{"name":"MangoPGX","type":"line","data":[{"value":40},{"value":102},{"value":223},{"value":424},{"value":825},{"value":2027},{"value":4541},{"value":1190},{"value":325},{"value":631},{"value":1138},{"value":2142},{"value":5152},{"value":10162}]},{"name":"MangoPQ","type":"line","data":[{"value":41},{"value":121},{"value":257},{"value":483},{"value":934},{"value":2286},{"value":5058},{"value":1190},{"value":293},{"value":580},{"value":1057},{"value":2008},{"value":4862},{"value":9618}]}],"title":{"text":"InsertMany|Mem","subtext":"Lower is Better (allocs/op)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
15+
let goecharts_EWakwZPOUEFv = echarts.init(document.getElementById('EWakwZPOUEFv'), "shine", { renderer: "canvas" });
16+
let option_EWakwZPOUEFv = {"legend":{},"series":[{"name":"MangoPQ","type":"line","data":[{"value":41},{"value":121},{"value":257},{"value":483},{"value":934},{"value":2285},{"value":5058},{"value":1210},{"value":293},{"value":580},{"value":1057},{"value":2008},{"value":4862},{"value":9618}]},{"name":"GormPGX","type":"line","data":[{"value":122},{"value":475},{"value":1107},{"value":2213},{"value":4425},{"value":11039},{"value":22541},{"value":1100},{"value":446},{"value":1006},{"value":1938},{"value":3803},{"value":9521},{"value":19039}]},{"name":"MangoPGX","type":"line","data":[{"value":41},{"value":102},{"value":223},{"value":424},{"value":825},{"value":2027},{"value":4542},{"value":1220},{"value":335},{"value":656},{"value":1188},{"value":2242},{"value":5402},{"value":10662}]}],"title":{"text":"InsertMany|Mem","subtext":"Lower is Better (allocs/op)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
1717

18-
goecharts_IhywVMYWTAuI.setOption(option_IhywVMYWTAuI);
18+
goecharts_EWakwZPOUEFv.setOption(option_EWakwZPOUEFv);
1919
</script>
2020
<style>
2121
.container {margin-top:30px; display: flex;justify-content: center;align-items: center;}

docs/public/bench_postgres_insertmany_cpu.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
</head>
1010

1111
<body><div class="container">
12-
<div class="item" id="ruMiZnVEmQgz" style="width:576px;height:320px;"></div>
12+
<div class="item" id="DohQFGVHPfSO" style="width:576px;height:320px;"></div>
1313
</div><script type="text/javascript">
1414
"use strict";
15-
let goecharts_ruMiZnVEmQgz = echarts.init(document.getElementById('ruMiZnVEmQgz'), "shine", { renderer: "canvas" });
16-
let option_ruMiZnVEmQgz = {"legend":{},"series":[{"name":"MangoPQ","type":"line","data":[{"value":7399},{"value":5061},{"value":3449},{"value":2194},{"value":1181},{"value":472},{"value":234},{"value":734},{"value":5388},{"value":3944},{"value":2561},{"value":1559},{"value":676},{"value":329}]},{"name":"GormPGX","type":"line","data":[{"value":2437},{"value":1857},{"value":1403},{"value":952},{"value":553},{"value":214},{"value":127},{"value":606},{"value":4474},{"value":2861},{"value":1925},{"value":1011},{"value":404},{"value":213}]},{"name":"MangoPGX","type":"line","data":[{"value":6889},{"value":4763},{"value":3319},{"value":2074},{"value":1146},{"value":457},{"value":220},{"value":662},{"value":4938},{"value":3742},{"value":2585},{"value":1580},{"value":660},{"value":319}]}],"title":{"text":"InsertMany|CPU","subtext":"Higher is Better (op/s)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
15+
let goecharts_DohQFGVHPfSO = echarts.init(document.getElementById('DohQFGVHPfSO'), "shine", { renderer: "canvas" });
16+
let option_DohQFGVHPfSO = {"legend":{},"series":[{"name":"GormPGX","type":"line","data":[{"value":2429},{"value":1908},{"value":1453},{"value":971},{"value":561},{"value":219},{"value":128},{"value":604},{"value":4173},{"value":2932},{"value":1922},{"value":1045},{"value":432},{"value":185}]},{"name":"MangoPGX","type":"line","data":[{"value":6711},{"value":4795},{"value":3234},{"value":2133},{"value":1154},{"value":449},{"value":223},{"value":651},{"value":4948},{"value":3678},{"value":2582},{"value":1515},{"value":659},{"value":306}]},{"name":"MangoPQ","type":"line","data":[{"value":7443},{"value":5004},{"value":3393},{"value":2158},{"value":1197},{"value":477},{"value":238},{"value":719},{"value":5477},{"value":3483},{"value":2623},{"value":1582},{"value":675},{"value":307}]}],"title":{"text":"InsertMany|CPU","subtext":"Higher is Better (op/s)"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["10","25","50","100","250","500"]}],"yAxis":[{}]}
1717

18-
goecharts_ruMiZnVEmQgz.setOption(option_ruMiZnVEmQgz);
18+
goecharts_DohQFGVHPfSO.setOption(option_DohQFGVHPfSO);
1919
</script>
2020
<style>
2121
.container {margin-top:30px; display: flex;justify-content: center;align-items: center;}

0 commit comments

Comments
 (0)