Skip to content

Commit 0854667

Browse files
committed
jQuery DataTables API for Go with Gorm
0 parents  commit 0854667

25 files changed

+4246
-0
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root = true
2+
3+
[*]
4+
insert_final_newline = true
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
indent_style = space
8+
indent_size = 2
9+
10+
[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
11+
indent_style = tab
12+
indent_size = 4
13+
14+
[*.md]
15+
indent_size = 2
16+
trim_trailing_whitespace = false
17+
18+
eclint_indent_style = unset
19+
20+
[Dockerfile]
21+
indent_size = 4

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Muhammad Saleh Solahudin (m.saleh.solahudin@gmail.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
all: help
2+
3+
lint:
4+
@echo "Running linter..."
5+
golangci-lint run ./
6+
7+
test:
8+
@echo "Running tests..."
9+
go test ./ -gcflags=all=-l --race -v -short -coverprofile=coverage.out
10+
11+
test-coverage:
12+
@echo "Generating test coverage report..."
13+
go test -coverprofile=coverage.out ./
14+
@echo "Test coverage profile generated: coverage.out"
15+
@echo "Use 'make view-coverage' to view the HTML report."
16+
17+
view-coverage: test-coverage
18+
@echo "Opening test coverage report in browser..."
19+
go tool cover -html=coverage.out
20+
21+
deps:
22+
@echo "Installing dependencies..."
23+
go mod tidy
24+
25+
clean:
26+
@echo "Cleaning up..."
27+
rm -rf coverage.out
28+
29+
help:
30+
@echo "--------------------------------------------------------------"
31+
@echo "Available targets:"
32+
@echo " deps - Install dependencies (run 'go mod tidy')"
33+
@echo " lint - Run linter (requires golangci-lint)"
34+
@echo " test - Run tests with race detection and coverage"
35+
@echo " test-coverage - Generate test coverage report"
36+
@echo " view-coverage - Open test coverage report in browser"
37+
@echo " clean - Remove generated files (coverage.out)"
38+
@echo " help - Show this help message"
39+
@echo "--------------------------------------------------------------"
40+
@echo "Credits: Muhammad Saleh Solahudin <https://github.com/ZihxS>"
41+
@echo "--------------------------------------------------------------"

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# jQuery DataTables API for Go with Gorm
2+
3+
The golang-gorm-datatables package is a Go library which provides support for jQuery DataTables server-side processing using Gorm. It contains functions for generating SQL queries for filtering, sorting and pagination, as well as functions for counting the total and filtered records.
4+
5+
## Requirements
6+
7+
- Go 1.24 or higher
8+
- Gorm 1.26 or higher
9+
10+
## Installation
11+
12+
To install the Request package, run the following command:
13+
14+
```bash
15+
go get github.com/ZihxS/golang-gorm-datatables
16+
```
17+
18+
## Simple Usage
19+
20+
```go
21+
package main
22+
23+
import (
24+
// ...
25+
26+
"github.com/ZihxS/golang-gorm-datatables" // [👉🏼 FOCUS HERE]
27+
28+
// ...
29+
)
30+
31+
func main() {
32+
// ...
33+
34+
type User struct {
35+
ID int
36+
Name string
37+
Age int
38+
}
39+
40+
// ...
41+
42+
// example using mux router
43+
r.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) {
44+
req, err := datatables.ParseRequest(r) // parse the request [👉🏼 FOCUS HERE]
45+
if err != nil {
46+
http.Error(w, fmt.Sprintf("Error processing request: %v", err), http.StatusInternalServerError)
47+
return
48+
}
49+
50+
tx := db.Model(&User{}) // gorm query [👉🏼 FOCUS HERE]
51+
response, err := datatables.New(tx).Req(*req).Make() // make datatables [👉🏼 FOCUS HERE]
52+
if err != nil {
53+
http.Error(w, fmt.Sprintf("Error processing request: %v", err), http.StatusInternalServerError)
54+
return
55+
}
56+
57+
w.Header().Set("Content-Type", "application/json")
58+
_ = json.NewEncoder(w).Encode(response)
59+
})
60+
}
61+
62+
// ...
63+
```
64+
65+
## More Example & Documentation
66+
67+
You can visit this link to see more example and documentation:
68+
- Documentation: ?
69+
- Example on Server Side: ?
70+
- Example on Client Side: ?
71+
72+
## Contributing
73+
74+
Contributions are welcome! If you'd like to contribute to the Request package, please follow these steps:
75+
76+
1. Fork the repository to your own GitHub account.
77+
2. Clone the repository to your local machine.
78+
3. Run `make deps` to install dependencies.
79+
4. Make changes to the code, following the guidelines below.
80+
5. Run `make test` to ensure your changes pass the test suite.
81+
6. Run `make fmt` to ensure your code is formatted correctly.
82+
7. Run `make lint` to ensure your code lint is clean.
83+
8. Commit your changes with a meaningful commit message.
84+
9. Push your changes to your forked repository.
85+
10. Submit a pull request to the original repository.
86+
87+
### Makefile Commands
88+
89+
The Makefile provides several commands to help with development and testing:
90+
91+
* `make deps`: Installs dependencies for the package.
92+
* `make test`: Runs the test suite for the package.
93+
* `make test-coverage`: Runs the test suite with code coverage analysis.
94+
* `make view-coverage`: Opens the test coverage report in your web browser.
95+
* `make fmt`: Formats the code according to the Go standard.
96+
* `make lint`: Runs the linter to check for coding style issues.
97+
* `make build`: Builds the package and its dependencies.
98+
* `make clean`: Removes any build artifacts and temporary files.
99+
100+
### Guidelines
101+
102+
When contributing to the Request package, please follow these guidelines:
103+
104+
* Use the Go standard coding style.
105+
* Write comprehensive tests for any new functionality.
106+
* Keep commits small and focused on a single change.
107+
* Use meaningful commit messages that describe the change.
108+
109+
## License
110+
111+
The Request package is licensed under the MIT License.
112+
113+
## Authors
114+
115+
* [Muhammad Saleh Solahudin](https://github.com/ZihxS)
116+
117+
## Contributors
118+
119+
## Credits
120+
121+
- [DataTables](https://datatables.net)
122+
- [Gorm](https://gorm.io)

0 commit comments

Comments
 (0)