Skip to content

Commit 24857bc

Browse files
authored
Merge pull request #180 from go-jet/develop
Release v.2.9.0
2 parents 38b6caf + 59f9df9 commit 24857bc

Some content is hidden

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

41 files changed

+692
-183
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
[![CircleCI](https://circleci.com/gh/go-jet/jet/tree/master.svg?style=svg&circle-token=97f255c6a4a3ab6590ea2e9195eb3ebf9f97b4a7)](https://circleci.com/gh/go-jet/jet/tree/develop)
44
[![codecov](https://codecov.io/gh/go-jet/jet/branch/master/graph/badge.svg)](https://codecov.io/gh/go-jet/jet)
5-
[![Go Report Card](https://goreportcard.com/badge/github.com/go-jet/jet)](https://goreportcard.com/report/github.com/go-jet/jet)
6-
[![Documentation](https://godoc.org/github.com/go-jet/jet?status.svg)](http://godoc.org/github.com/go-jet/jet)
7-
[![GitHub release](https://img.shields.io/github/release/go-jet/jet.svg)](https://github.com/go-jet/jet/v2/releases)
8-
[![Gitter](https://badges.gitter.im/go-jet/community.svg)](https://gitter.im/go-jet/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/go-jet/jet)](https://goreportcard.com/report/github.com/go-jet/jet/v2)
6+
[![Documentation](https://godoc.org/github.com/go-jet/jet?status.svg)](http://godoc.org/github.com/go-jet/jet/v2)
7+
[![GitHub release](https://img.shields.io/github/release/go-jet/jet.svg)](https://github.com/go-jet/jet/releases)
98

109
Jet is a complete solution for efficient and high performance database access, consisting of type-safe SQL builder
1110
with code generation and automatic query result data mapping.

doc.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,45 @@ Package jet is a complete solution for efficient and high performance database a
33
with code generation and automatic query result data mapping.
44
Jet currently supports PostgreSQL, MySQL, MariaDB and SQLite. Future releases will add support for additional databases.
55
6-
7-
Installation
8-
6+
# Installation
97
108
Use the command bellow to add jet as a dependency into go.mod project:
9+
1110
$ go get -u github.com/go-jet/jet/v2
1211
1312
Jet generator can be installed in one of the following ways:
1413
15-
1) (Go1.16+) Install jet generator using go install:
16-
go install github.com/go-jet/jet/v2/cmd/jet@latest
14+
1. (Go1.16+) Install jet generator using go install:
15+
go install github.com/go-jet/jet/v2/cmd/jet@latest
1716
18-
2) Install jet generator to GOPATH/bin folder:
19-
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
17+
2. Install jet generator to GOPATH/bin folder:
18+
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
2019
21-
3) Install jet generator into specific folder:
22-
git clone https://github.com/go-jet/jet.git
23-
cd jet && go build -o dir_path ./cmd/jet
20+
3. Install jet generator into specific folder:
21+
git clone https://github.com/go-jet/jet.git
22+
cd jet && go build -o dir_path ./cmd/jet
2423
2524
Make sure that the destination folder is added to the PATH environment variable.
2625
27-
28-
Usage
29-
26+
# Usage
3027
3128
Jet requires already defined database schema(with tables, enums etc), so that jet generator can generate SQL Builder
3229
and Model files. File generation is very fast, and can be added as every pre-build step.
3330
Sample command:
31+
3432
jet -dsn=postgresql://user:pass@localhost:5432/jetdb -schema=dvds -path=./.gen
3533
3634
Before we can write SQL queries in Go, we need to import generated SQL builder and model types:
35+
3736
import . "some_path/.gen/jetdb/dvds/table"
3837
import "some_path/.gen/jetdb/dvds/model"
3938
4039
To write postgres SQL queries we import:
40+
4141
. "github.com/go-jet/jet/v2/postgres" // Dot import is used so that Go code resemble as much as native SQL. It is not mandatory.
4242
4343
Then we can write the SQL query:
44+
4445
// sub-query
4546
rRatingFilms :=
4647
SELECT(
@@ -72,6 +73,7 @@ Then we can write the SQL query:
7273
)
7374
7475
Now we can run the statement and store the result into desired destination:
76+
7577
var dest []struct {
7678
model.Film
7779
@@ -81,9 +83,11 @@ Now we can run the statement and store the result into desired destination:
8183
err := stmt.Query(db, &dest)
8284
8385
We can print a statement to see SQL query and arguments sent to postgres server:
86+
8487
fmt.Println(stmt.Sql())
8588
8689
Output:
90+
8791
SELECT "rFilms"."film.film_id" AS "film.film_id",
8892
"rFilms"."film.title" AS "film.title",
8993
"rFilms"."film.rating" AS "film.rating",

generator/template/file_templates.go

Lines changed: 2 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator/template/process.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,29 @@ func processTableSQLBuilder(fileTypes, dirPath string,
120120

121121
for _, tableMetaData := range tablesMetaData {
122122

123-
var tableSQLBuilderTemplate TableSQLBuilder
123+
var tableSQLBuilder TableSQLBuilder
124124

125125
if fileTypes == "view" {
126-
tableSQLBuilderTemplate = sqlBuilderTemplate.View(tableMetaData)
126+
tableSQLBuilder = sqlBuilderTemplate.View(tableMetaData)
127127
} else {
128-
tableSQLBuilderTemplate = sqlBuilderTemplate.Table(tableMetaData)
128+
tableSQLBuilder = sqlBuilderTemplate.Table(tableMetaData)
129129
}
130130

131-
if tableSQLBuilderTemplate.Skip {
131+
if tableSQLBuilder.Skip {
132132
continue
133133
}
134134

135-
tableSQLBuilderPath := path.Join(dirPath, tableSQLBuilderTemplate.Path)
135+
tableSQLBuilderPath := path.Join(dirPath, tableSQLBuilder.Path)
136136

137137
err := utils.EnsureDirPath(tableSQLBuilderPath)
138138
throw.OnError(err)
139139

140140
text, err := generateTemplate(
141-
autoGenWarningTemplate+getTableSQLBuilderTemplate(dialect),
141+
autoGenWarningTemplate+tableSQLBuilderTemplate,
142142
tableMetaData,
143143
template.FuncMap{
144144
"package": func() string {
145-
return tableSQLBuilderTemplate.PackageName()
145+
return tableSQLBuilder.PackageName()
146146
},
147147
"dialect": func() jet.Dialect {
148148
return dialect
@@ -151,29 +151,33 @@ func processTableSQLBuilder(fileTypes, dirPath string,
151151
return schemaMetaData.Name
152152
},
153153
"tableTemplate": func() TableSQLBuilder {
154-
return tableSQLBuilderTemplate
154+
return tableSQLBuilder
155155
},
156156
"structImplName": func() string { // postgres only
157-
structName := tableSQLBuilderTemplate.TypeName
157+
structName := tableSQLBuilder.TypeName
158158
return string(strings.ToLower(structName)[0]) + structName[1:]
159159
},
160160
"columnField": func(columnMetaData metadata.Column) TableSQLBuilderColumn {
161-
return tableSQLBuilderTemplate.Column(columnMetaData)
161+
return tableSQLBuilder.Column(columnMetaData)
162+
},
163+
"toUpper": strings.ToUpper,
164+
"insertedRowAlias": func() string {
165+
return insertedRowAlias(dialect)
162166
},
163167
})
164168
throw.OnError(err)
165169

166-
err = utils.SaveGoFile(tableSQLBuilderPath, tableSQLBuilderTemplate.FileName, text)
170+
err = utils.SaveGoFile(tableSQLBuilderPath, tableSQLBuilder.FileName, text)
167171
throw.OnError(err)
168172
}
169173
}
170174

171-
func getTableSQLBuilderTemplate(dialect jet.Dialect) string {
172-
if dialect.Name() == "PostgreSQL" || dialect.Name() == "SQLite" {
173-
return tableSQLBuilderTemplateWithEXCLUDED
175+
func insertedRowAlias(dialect jet.Dialect) string {
176+
if dialect.Name() == "MySQL" {
177+
return "new"
174178
}
175179

176-
return tableSQLBuilderTemplate
180+
return "excluded"
177181
}
178182

179183
func processTableModels(fileTypes, modelDirPath string, tablesMetaData []metadata.Table, modelTemplate Model) {

internal/jet/bool_expression.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package jet
22

3-
//BoolExpression interface
3+
// BoolExpression interface
44
type BoolExpression interface {
55
Expression
66

@@ -84,22 +84,18 @@ func (b *boolInterfaceImpl) IS_NOT_UNKNOWN() BoolExpression {
8484
return newPostfixBoolOperatorExpression(b.parent, "IS NOT UNKNOWN")
8585
}
8686

87-
//---------------------------------------------------//
8887
func newBinaryBoolOperatorExpression(lhs, rhs Expression, operator string, additionalParams ...Expression) BoolExpression {
8988
return BoolExp(NewBinaryOperatorExpression(lhs, rhs, operator, additionalParams...))
9089
}
9190

92-
//---------------------------------------------------//
9391
func newPrefixBoolOperatorExpression(expression Expression, operator string) BoolExpression {
9492
return BoolExp(newPrefixOperatorExpression(expression, operator))
9593
}
9694

97-
//---------------------------------------------------//
9895
func newPostfixBoolOperatorExpression(expression Expression, operator string) BoolExpression {
9996
return BoolExp(newPostfixOperatorExpression(expression, operator))
10097
}
10198

102-
//---------------------------------------------------//
10399
type boolExpressionWrapper struct {
104100
boolInterfaceImpl
105101
Expression

0 commit comments

Comments
 (0)