-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
118d136
commit bee745b
Showing
42 changed files
with
3,970 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
go-version: [1.22.x] | ||
|
||
runs-on: ${{ matrix.os }} | ||
env: | ||
MONGO_SERVER_URL: mongodb://localhost:27017 | ||
MONGO_PORT: 27017 | ||
# If test are affected by mongo, then set matrix-os to [ubuntu-latest] | ||
services: | ||
mongo: | ||
image: mongo:7 | ||
ports: | ||
- 27017:27017 | ||
|
||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Get dependencies | ||
run: go mod download | ||
|
||
- name: Build | ||
run: make build | ||
|
||
- name: Test and Coverage | ||
run: make cover | ||
|
||
- uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
path-to-profile: ./tmp/cover.out | ||
|
||
semantic-release: | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
issues: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run semantic-release | ||
if: github.repository == 'bartventer/docstore-gen' && github.event_name == 'push' | ||
run: | | ||
yarn global add semantic-release@17 | ||
semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Temp folder | ||
/tmp | ||
|
||
# Environment variables | ||
.env | ||
|
||
# Devcontainer | ||
.devcontainer | ||
|
||
# Temp directory generated during testing | ||
__temp__* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
PKG_NAME := main | ||
|
||
# Commands | ||
GO := go | ||
GOFMT := gofmt | ||
GOLINT := golint | ||
GOVET := go vet | ||
GOTEST := go test | ||
GOCOVER := go tool cover | ||
TEMP_DIR := ./tmp | ||
COVERAGE_PROFILE := cover.out | ||
BINARY := $(TEMP_DIR)/$(PKG_NAME) | ||
|
||
# Flags | ||
GOFLAGS := -v | ||
GOFMTFLAGS := -s | ||
GOLINTFLAGS := -set_exit_status | ||
GOVETFLAGS := -all | ||
GOTESTFLAGS := -v | ||
GOCOVERFLAGS := -html | ||
|
||
.PHONY: all | ||
all: build test | ||
|
||
.PHONY: fmt | ||
fmt: | ||
$(GOFMT) $(GOFMTFLAGS) -w . | ||
|
||
.PHONY: lint | ||
lint: | ||
$(GOLINT) $(GOLINTFLAGS) ./... | ||
|
||
.PHONY: vet | ||
vet: | ||
$(GOVET) $(GOVETFLAGS) ./... | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(TEMP_DIR) | ||
|
||
.PHONY: build | ||
build: vet | ||
$(GO) build $(GOFLAGS) -o $(BINARY) | ||
|
||
.PHONY: test | ||
test: | ||
$(GOTEST) $(GOTESTFLAGS) ./... | ||
|
||
.PHONY: cover | ||
cover: | ||
mkdir -p $(TEMP_DIR) | ||
$(GOTEST) $(GOTESTFLAGS) -coverprofile=$(COVERAGE_PROFILE) -outputdir=$(TEMP_DIR) `go list ./... | grep -v ./internal | grep -v ./examples` | ||
$(GOCOVER) $(GOCOVERFLAGS) $(TEMP_DIR)/$(COVERAGE_PROFILE) | ||
|
||
|
||
.PHONY: help | ||
help: | ||
@echo "Usage: make <target>" | ||
@echo "Targets:" | ||
@echo " all - build and test" | ||
@echo " fmt - format source code" | ||
@echo " lint - lint source code" | ||
@echo " vet - vet source code" | ||
@echo " clean - clean up" | ||
@echo " build - build binary" | ||
@echo " test - run tests" | ||
@echo " cover - run tests with coverage" | ||
@echo " help - show this help message" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Docstore Query Gen | ||
|
||
Friendly & Safer [GO CDK Docstore](https://gocloud.dev/howto/docstore/) Query Generation, inspired by [go-gorm/gen](https://github.com/go-gorm/gen). | ||
|
||
[![Go Reference](https://pkg.go.dev/badge/github.com/bartventer/docstore-gen.svg)](https://pkg.go.dev/github.com/bartventer/docstore-gen) | ||
[![Release](https://img.shields.io/github/release/bartventer/docstore-gen.svg)](https://github.com/bartventer/docstore-gen/releases/latest) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/bartventer/docstore-gen)](https://goreportcard.com/report/github.com/bartventer/docstore-gen) | ||
[![Coverage Status](https://coveralls.io/repos/github/bartventer/docstore-gen/badge.svg?branch=master)](https://coveralls.io/github/bartventer/docstore-gen?branch=master) | ||
[![Build](https://github.com/bartventer/docstore-gen/actions/workflows/go.yml/badge.svg)](https://github.com/bartventer/docstore-gen/actions/workflows/go.yml) | ||
![GitHub issues](https://img.shields.io/github/issues/bartventer/docstore-gen) | ||
[![License](https://img.shields.io/github/license/bartventer/docstore-gen.svg)](LICENSE) | ||
|
||
## Overview | ||
|
||
- Idiomatic & Reusable API from Dynamic Query | ||
- 100% Type-safe DAO API without `interface{}` | ||
- Struct to Query follows Docstore conventions | ||
- Designed to be used with the [Go CDK Docstore](https://gocloud.dev/howto/docstore/) | ||
- Docstore under the hood, supports all features that Docstore querying supports | ||
|
||
## Getting Started | ||
|
||
* Docstore Query Gen Guides; see [examples](https://github.com/bartventer/docstore-gen/blob/master/examples/README.md) | ||
* Docstore Guides [https://gocloud.dev/howto/docstore/](https://gocloud.dev/howto/docstore/) | ||
|
||
## Maintainers | ||
|
||
[@bartventer](https://github.com/bartventer) | ||
|
||
## Contributing | ||
|
||
All contributions are welcome! Open a pull request to request a feature or submit a bug report. | ||
|
||
## License | ||
|
||
Released under the [MIT License](https://github.com/bartventer/docstore-gen/blob/master/License) | ||
|
||
## Acknowledgements | ||
|
||
This project makes use of code from the [go-gorm/gen](https://github.com/go-gorm/gen) project. We thank the authors of go-gorm/gen for their work and for making their code available for reuse. | ||
|
||
Additionally, this project is built upon the [Go CDK Docstore](https://gocloud.dev/howto/docstore/) and we appreciate the work of the Go Cloud Development Kit team. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package docstoregen | ||
|
||
import "log/slog" | ||
|
||
// Config represents the configuration options for generating query code. | ||
type Config struct { | ||
OutPath string // OutPath specifies the path where the query code will be generated. Example: "/path/to/project/pkg/query" | ||
OutFile string // OutFile specifies the name of the query code file. The default value is "gen.go". | ||
queryPkgName string // queryPkgName specifies the name of the package where the query code will be generated. | ||
importPkgPaths []string // importPkgPaths specifies the import paths of the packages that the generated query code will import. | ||
LoggerHandler slog.Handler // LoggerHandler specifies the handler for the logger used by the generator. Example: slog.NewJSONHandler(os.Stdout, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Package docstoregen provides a code generator for the go-cloud.dev/docstore package. | ||
// | ||
// The generator creates a query code file for the go-cloud.dev/docstore package. | ||
// | ||
// The generator's basic configuration is defined in the Config struct. | ||
// | ||
// The generator's main function is Execute, which generates the query code file. | ||
package docstoregen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# examples | ||
|
||
This directory contains examples of `docstore-gen`. | ||
|
||
## Usage | ||
|
||
```zsh | ||
./generate.sh | ||
``` | ||
|
||
This script will generate the`docstore-gen` examples, you can find the generated files in the `out` directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
docstoregen "github.com/bartventer/docstore-gen" | ||
"github.com/bartventer/docstore-gen/examples/cmd/models" | ||
) | ||
|
||
func main() { | ||
g := docstoregen.NewGenerator(docstoregen.Config{ | ||
OutPath: "../out/query", | ||
OutFile: "gen.go", | ||
}) | ||
|
||
g.ApplyInterface(&models.User{}) | ||
|
||
g.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package models | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
// User is a model for the users table | ||
type User struct { | ||
ID string `docstore:"id"` | ||
Name string `docstore:"name"` | ||
Age uint `docstore:"age"` | ||
DateJoiend time.Time `docstore:"date_joined"` | ||
IsAdmin bool `docstore:"is_admin"` | ||
Preferences json.RawMessage `docstore:"preferences"` | ||
Expenditure float64 `docstore:"expenditure"` | ||
} | ||
|
||
// TableName returns the table name for the model | ||
func (User) TableName() string { return "users" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/zsh | ||
|
||
PROJECT_DIR=$(dirname "$0") | ||
GENERATE_DIR="$PROJECT_DIR/cmd" | ||
|
||
cd "$GENERATE_DIR" || exit | ||
|
||
echo "Start Generating" | ||
go run . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/bartventer/docstore-gen/examples/out/query" | ||
) | ||
|
||
func main() { | ||
// start your project here | ||
fmt.Println("hello world") | ||
defer fmt.Println("bye~") | ||
|
||
query.Initialize() | ||
|
||
user := query.User | ||
fmt.Println(user.DateJoiend.Lt(time.Now().AddDate(0, 0, -1))) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package field | ||
|
||
// Bool bool type field | ||
type Bool struct{ expr } | ||
|
||
var _ simpleExpression[bool] = new(Bool) | ||
|
||
// Eq checks if the field is equal to the provided bool value | ||
func (field Bool) Eq(value bool) Expr { | ||
return expr{e: Eq{Column: field.col, Value: value}} | ||
} |
Oops, something went wrong.