Skip to content

Commit

Permalink
Merge pull request #78 from go-jet/develop
Browse files Browse the repository at this point in the history
Merge develop to master for 2.5.0 release
  • Loading branch information
go-jet authored May 21, 2021
2 parents fdde2ab + caa8193 commit f0bf2c3
Show file tree
Hide file tree
Showing 80 changed files with 2,898 additions and 454 deletions.
36 changes: 11 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ jobs:
build-postgres-and-mysql:
docker:
# specify the version
- image: circleci/golang:1.11
- image: circleci/golang:1.13

- image: circleci/postgres:10.8-alpine
environment: # environment variables for primary container
POSTGRES_USER: jet
POSTGRES_PASSWORD: jet
POSTGRES_DB: jetdb

- image: circleci/mysql:8.0
- image: circleci/mysql:8.0.16
command: [--default-authentication-plugin=mysql_native_password]
environment:
MYSQL_ROOT_PASSWORD: jet
Expand All @@ -41,17 +41,9 @@ jobs:
- run:
name: Install dependencies
command: |
go get github.com/google/uuid
go get github.com/lib/pq
go get github.com/go-sql-driver/mysql
go get github.com/pkg/profile
go get github.com/stretchr/testify/assert
go get github.com/google/go-cmp/cmp
go get github.com/davecgh/go-spew/spew
cd /go/src/github.com/go-jet/jet
go get github.com/jstemmer/go-junit-report
go install github.com/go-jet/jet/cmd/jet
go build -o /home/circleci/.local/bin/jet ./cmd/jet/
- run:
name: Waiting for Postgres to be ready
Expand Down Expand Up @@ -85,6 +77,7 @@ jobs:
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
- run:
name: Init Postgres database
Expand All @@ -95,7 +88,7 @@ jobs:
- run: mkdir -p $TEST_RESULTS
- run: go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/jet/mysql/...,github.com/go-jet/jet/qrm/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml
- run: MY_SQL_SOURCE=MySQL go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/jet/mysql/...,github.com/go-jet/jet/qrm/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml

- run:
name: Upload code coverage
Expand All @@ -110,7 +103,7 @@ jobs:
build-mariadb:
docker:
# specify the version
- image: circleci/golang:1.11
- image: circleci/golang:1.13

- image: circleci/mariadb:10.3
command: [--default-authentication-plugin=mysql_native_password]
Expand Down Expand Up @@ -138,17 +131,9 @@ jobs:
- run:
name: Install dependencies
command: |
go get github.com/google/uuid
go get github.com/lib/pq
go get github.com/go-sql-driver/mysql
go get github.com/pkg/profile
go get github.com/stretchr/testify/assert
go get github.com/google/go-cmp/cmp
go get github.com/davecgh/go-spew/spew
cd /go/src/github.com/go-jet/jet
go get github.com/jstemmer/go-junit-report
go install github.com/go-jet/jet/cmd/jet
go build -o /home/circleci/.local/bin/jet ./cmd/jet/
- run:
name: Install MySQL CLI;
Expand All @@ -161,6 +146,7 @@ jobs:
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
- run:
name: Init MariaDB database
Expand All @@ -172,7 +158,7 @@ jobs:
- run:
name: Run MariaDB tests
command: |
go test -v ./tests/mysql/ -source=MariaDB
MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/
workflows:
version: 2
Expand Down
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,33 @@ To install Jet package, you need to install Go and set your Go workspace first.

### Installation

Use the bellow command to add jet as a dependency into `go.mod` project:
Use the command bellow to add jet as a dependency into `go.mod` project:
```sh
$ go get -u github.com/go-jet/jet/v2
```

Use the bellow command to add jet as a dependency into `GOPATH` project:
Jet generator can be install in the following ways:

1) Install jet generator to GOPATH/bin folder:
```sh
$ go get -u github.com/go-jet/jet
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
```
*Make sure GOPATH/bin folder is added to the PATH environment variable.*

Install jet generator to GOPATH bin folder. This will allow generating jet files from the command line.
2) Install jet generator to specific folder:

```sh
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
git clone https://github.com/go-jet/jet.git
cd jet && go build -o dir_path ./cmd/jet
```
*Make sure `dir_path` folder is added to the PATH environment variable.*

*Make sure GOPATH bin folder is added to the PATH environment variable.*
3) (Go1.16+) Install jet generator using go install:
```sh
go install github.com/go-jet/jet/v2/cmd/jet@latest
```
*Jet generator is installed to the directory named by the GOBIN environment variable,
which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set.*

### Quick Start
For this quick start example we will use PostgreSQL sample _'dvd rental'_ database. Full database dump can be found in [./tests/testdata/init/postgres/dvds.sql](./tests/testdata/init/postgres/dvds.sql).
Expand Down Expand Up @@ -519,26 +528,17 @@ The biggest benefit is speed. Speed is improved in 3 major areas:

##### Speed of development

Writing SQL queries is faster and easier, because the developers have help of SQL code completion and SQL type safety directly from Go.
Writing SQL queries is faster and easier as the developers have help of SQL code completion and SQL type safety directly from Go.
Automatic scan to arbitrary structure removes a lot of headache and boilerplate code needed to structure database query result.

##### Speed of execution

While ORM libraries can introduce significant performance penalties due to number of round-trips to the database,
Jet will always perform much better, because of the single database call.

Common web and database server usually are not on the same physical machine, and there is some latency between them.
Latency can vary from 5ms to 50+ms. In majority of cases query executed on database is simple query lasting no more than 1ms.
In those cases web server handler execution time is directly proportional to latency between server and database.
This is not such a big problem if handler calls database couple of times, but what if web server is using ORM to retrieve data from database.
ORM sometimes can access the database once for every object needed. Now lets say latency is 30ms and there are 100
different objects required from the database. This handler will last 3 seconds !!!.

With Jet, handler time lost on latency between server and database is constant. Because we can write complex query and
return result in one database call. Handler execution will be only proportional to the number of rows returned from database.
ORM example replaced with jet will take just 30ms + 'result scan time' = 31ms (rough estimate).
Jet will always perform better as developers can write complex query and retrieve result with a single database call.
Thus handler time lost on latency between server and database can be constant. Handler execution will be proportional
only to the query complexity and the number of rows returned from database.

With Jet you can even join the whole database and store the whole structured result in one database call.
With Jet it is even possible to join the whole database and store the whole structured result in one database call.
This is exactly what is being done in one of the tests: [TestJoinEverything](/tests/postgres/chinook_db_test.go#L40).
The whole test database is joined and query result(~10,000 rows) is stored in a structured variable in less than 0.7s.

Expand Down Expand Up @@ -570,12 +570,13 @@ To run the tests, additional dependencies are required:
- `github.com/pkg/profile`
- `github.com/stretchr/testify`
- `github.com/google/go-cmp`
- `github.com/jackc/pgx/v4`

## Versioning

[SemVer](http://semver.org/) is used for versioning. For the versions available, take a look at the [releases](https://github.com/go-jet/jet/releases).

## License

Copyright 2019-2020 Goran Bjelanovic
Copyright 2019-2021 Goran Bjelanovic
Licensed under the Apache License, Version 2.0.
2 changes: 1 addition & 1 deletion cmd/jet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {

flag.Usage = func() {
_, _ = fmt.Fprint(os.Stdout, `
Jet generator 2.3.0
Jet generator 2.5.0
Usage:
-source string
Expand Down
23 changes: 13 additions & 10 deletions examples/quick-start/.gen/jetdb/dvds/table/actor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions examples/quick-start/.gen/jetdb/dvds/table/category.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions examples/quick-start/.gen/jetdb/dvds/table/film.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions examples/quick-start/.gen/jetdb/dvds/table/film_actor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0bf2c3

Please sign in to comment.