Skip to content

Commit e301ff1

Browse files
committed
reorganize test suite to be reusable for different drivers pq, pgx and sqlite
1 parent a806fe0 commit e301ff1

47 files changed

Lines changed: 1863 additions & 1313 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ coverage.*
1313
bin/
1414
codegen/test/
1515

16-
tests/**/client.go
16+
tests/**/client.go
17+
dist/

.goreleaser.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines below are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
version: 2
10+
11+
before:
12+
hooks:
13+
# You may remove this if you don't use go modules.
14+
- go mod tidy
15+
16+
builds:
17+
- main: cmd/mangosql
18+
env:
19+
- CGO_ENABLED=0
20+
goos:
21+
- linux
22+
- windows
23+
- darwin
24+
25+
archives:
26+
- format: tar.gz
27+
# this name template makes the OS and Arch compatible with the results of `uname`.
28+
name_template: >-
29+
{{ .ProjectName }}_
30+
{{- title .Os }}_
31+
{{- if eq .Arch "amd64" }}x86_64
32+
{{- else if eq .Arch "386" }}i386
33+
{{- else }}{{ .Arch }}{{ end }}
34+
{{- if .Arm }}v{{ .Arm }}{{ end }}
35+
# use zip for windows archives
36+
format_overrides:
37+
- goos: windows
38+
format: zip
39+
40+
changelog:
41+
sort: asc
42+
filters:
43+
exclude:
44+
- "^docs:"
45+
- "^test:"

Readme.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,33 @@ Also the current SQL Parser being based on CockroachDB, some postgres specific s
110110

111111
**Known Bug**:
112112
* Sqlite:
113-
* [ ] Generated code contains not supported keywords (like `ANY`, just need more tests)
114-
* [ ] Batch insert not working, syntax not supported in sqlite
113+
* [x] ~Generated code contains not supported keywords (like `ANY`, just need more tests)~
114+
* [x] ~Batch insert not working, syntax not supported in sqlite~
115115
* Postgres
116-
* [x] When multiple where condition are combined, index may conflict
116+
* [x] ~When multiple where condition are combined, index may conflict~
117117
* [ ] In sqlx+pq, some advanced type serialization are not supported (like jsonb)
118118

119119
**Roadmap**:
120-
* [x] Handle custom user queries
120+
* [x] ~Handle custom user queries~
121121
* [ ] Handle sql enums
122122
* [ ] Handle sql views
123123
* [ ] Support more types and custom types (cf ulid, ...)
124124
* [ ] Support more driver and database Mysql/MariaDB/Sqlite3
125-
* [x] For Postgres support both `pq + sqlc` or `pgx`
125+
* [x] ~For Postgres support both `pq + sqlc` or `pgx`~
126126
* [ ] For Mysql/MariaDB `go-sql-driver` (throught sqlx)
127-
* [x] For Sqlite `modernc.org/sqlite` (throught sqlx)
127+
* [x] ~For Sqlite `modernc.org/sqlite` (throught sqlx)~
128128
* [ ] Support easier logging and profiling
129129
* [ ] Support for Listen/Notify on pgx
130130
* [ ] Support DB Introspection to automatically extract schema from running database
131131
* [ ] Write Documentation
132132
* [ ] Pick a static doc generator website
133133
* [ ] Setup
134+
* Tutorial Postgres
135+
* Local DB
136+
* Supabase
137+
* Tutorial SQLite
138+
* Memory
139+
* Torso
134140
* [ ] Write benchmark to compare performance with existing Golang ORM
135141
* [x] Wrote basic comparison (insert, bulk insert, select)
136142
* [ ] Add more use cases (select with lot of data, upsert, complex query with joins)

bench.log

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
goos: linux
2+
goarch: amd64
3+
pkg: github.com/kefniark/mango-sql/tests/bench
4+
cpu: AMD Ryzen 7 5700U with Radeon Graphics
5+
BenchmarkInsertOne/Insert_One_-_Mango_PQ-16 6649 152768 ns/op 1728 B/op 41 allocs/op
6+
BenchmarkInsertOne/Insert_One_-_Mango_PGX-16 6912 952006 ns/op 1553 B/op 40 allocs/op
7+
BenchmarkInsertOne/Insert_One_-_Gorm_PGX-16 2752 977085 ns/op 7788 B/op 118 allocs/op
8+
BenchmarkInsertOne/Insert_One_-_Mango_Sqlite-16 29546 42716 ns/op 2728 B/op 94 allocs/op
9+
BenchmarkInsertOne/Insert_One_-_Gorm_Sqlite-16 21243 58353 ns/op 6910 B/op 102 allocs/op
10+
BenchmarkInsertBulk/Insert_Bulk_-_Mango_PQ-16 2283 9747579 ns/op 32134 B/op 533 allocs/op
11+
BenchmarkInsertBulk/Insert_Bulk_-_Mango_PGX-16 2184 10853293 ns/op 35214 B/op 474 allocs/op
12+
BenchmarkInsertBulk/Insert_Bulk_-_Gorm-16 100 20145619 ns/op 150938 B/op 2161 allocs/op
13+
BenchmarkSelect/Select_-_Mango_PQ-16 780 5445075 ns/op 58538 B/op 1190 allocs/op
14+
BenchmarkSelect/Select_-_Mango_Pgx-16 100 20128747 ns/op 57819 B/op 1190 allocs/op
15+
BenchmarkSelect/Select_-_Gorm-16 648 7139486 ns/op 55852 B/op 1090 allocs/op
16+
PASS
17+
ok github.com/kefniark/mango-sql/tests/bench 73.676s

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": 1723409744,
6+
"lastModified": 1723487333,
77
"owner": "cachix",
88
"repo": "devenv",
9-
"rev": "116159a4bfeaa79662f4c39dbfaf2fce6a5737f7",
10-
"treeHash": "ccbae63055f83e669996a88a3cbb4ef69febd002",
9+
"rev": "b285601679c7686f623791ad93a8e0debc322633",
10+
"treeHash": "724e2581d01b2775202a61459cc6e63abbf56063",
1111
"type": "github"
1212
},
1313
"original": {
@@ -72,11 +72,11 @@
7272
},
7373
"nixpkgs-stable": {
7474
"locked": {
75-
"lastModified": 1723282977,
75+
"lastModified": 1723556749,
7676
"owner": "NixOS",
7777
"repo": "nixpkgs",
78-
"rev": "a781ff33ae258bbcfd4ed6e673860c3e923bf2cc",
79-
"treeHash": "75cf71293251c603e56d6076098346b4128b2ec8",
78+
"rev": "4a92571f9207810b559c9eac203d1f4d79830073",
79+
"treeHash": "e3518a5882da387efc1f99184797844a9952ecd0",
8080
"type": "github"
8181
},
8282
"original": {

devenv.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{ pkgs, lib, config, inputs, ... }:
22

33
{
4-
# https://devenv.sh/basics/
5-
env.GREET = "devenv";
6-
74
# https://devenv.sh/packages/
85
packages = [
96
pkgs.git

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/kefniark/mango-sql
22

3-
go 1.22.1
3+
go 1.22.5
4+
5+
toolchain go1.22.6
46

57
require (
68
github.com/Masterminds/squirrel v1.5.4
@@ -17,6 +19,7 @@ require (
1719
github.com/urfave/cli/v2 v2.27.4
1820
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
1921
gorm.io/driver/postgres v1.5.9
22+
gorm.io/driver/sqlite v1.5.6
2023
gorm.io/gorm v1.25.11
2124
modernc.org/sqlite v1.29.6
2225
)
@@ -28,12 +31,13 @@ require (
2831
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
2932
github.com/cockroachdb/redact v1.1.5 // indirect
3033
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
31-
github.com/davecgh/go-spew v1.1.1 // indirect
34+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3235
github.com/dustin/go-humanize v1.0.1 // indirect
3336
github.com/getsentry/raven-go v0.2.0 // indirect
3437
github.com/getsentry/sentry-go v0.28.1 // indirect
3538
github.com/gogo/protobuf v1.3.2 // indirect
3639
github.com/golang/protobuf v1.5.4 // indirect
40+
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
3741
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
3842
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
3943
github.com/jackc/pgpassfile v1.0.0 // indirect
@@ -46,10 +50,11 @@ require (
4650
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
4751
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
4852
github.com/mattn/go-isatty v0.0.20 // indirect
53+
github.com/mattn/go-sqlite3 v1.14.22 // indirect
4954
github.com/mfridman/interpolate v0.0.2 // indirect
5055
github.com/ncruces/go-strftime v0.1.9 // indirect
5156
github.com/pkg/errors v0.9.1 // indirect
52-
github.com/pmezard/go-difflib v1.0.0 // indirect
57+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5358
github.com/pressly/goose/v3 v3.21.1 // indirect
5459
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
5560
github.com/rogpeppe/go-internal v1.12.0 // indirect
@@ -60,6 +65,7 @@ require (
6065
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
6166
go.uber.org/multierr v1.11.0 // indirect
6267
golang.org/x/crypto v0.26.0 // indirect
68+
golang.org/x/net v0.28.0 // indirect
6369
golang.org/x/sync v0.8.0 // indirect
6470
golang.org/x/sys v0.24.0 // indirect
6571
golang.org/x/text v0.17.0 // indirect

go.sum

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lV
4646
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
4747
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4848
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
49-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5049
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
50+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
51+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5152
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
5253
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
5354
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
@@ -117,8 +118,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
117118
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
118119
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
119120
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
120-
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
121-
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
121+
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b h1:RMpPgZTSApbPf7xaVel+QkoGPRLFLrwFO89uDUHEGf0=
122+
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
122123
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
123124
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
124125
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -236,8 +237,9 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
236237
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
237238
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
238239
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
239-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
240240
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
241+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
242+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
241243
github.com/pressly/goose/v3 v3.21.1 h1:5SSAKKWej8LVVzNLuT6KIvP1eFDuPvxa+B6H0w78buQ=
242244
github.com/pressly/goose/v3 v3.21.1/go.mod h1:sqthmzV8PitchEkjecFJII//l43dLOCzfWh8pHEe+vE=
243245
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -333,8 +335,8 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
333335
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
334336
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
335337
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
336-
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
337-
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
338+
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
339+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
338340
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
339341
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
340342
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -445,6 +447,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
445447
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
446448
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
447449
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
450+
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
451+
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
448452
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
449453
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
450454
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 commit comments

Comments
 (0)