Skip to content

Commit

Permalink
Merge pull request #42 from go-jet/develop
Browse files Browse the repository at this point in the history
Add support for go.mod (v2.4.0)
  • Loading branch information
go-jet authored Jun 28, 2020
2 parents fdeef56 + 5881b5d commit fdde2ab
Show file tree
Hide file tree
Showing 104 changed files with 275 additions and 231 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
[![codecov](https://codecov.io/gh/go-jet/jet/branch/master/graph/badge.svg)](https://codecov.io/gh/go-jet/jet)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-jet/jet)](https://goreportcard.com/report/github.com/go-jet/jet)
[![Documentation](https://godoc.org/github.com/go-jet/jet?status.svg)](http://godoc.org/github.com/go-jet/jet)
[![GitHub release](https://img.shields.io/github/release/go-jet/jet.svg)](https://github.com/go-jet/jet/releases)
[![GitHub release](https://img.shields.io/github/release/go-jet/jet.svg)](https://github.com/go-jet/jet/v2/releases)
[![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)

Jet is a framework for writing type-safe SQL queries in Go, with ability to easily
convert database query result into desired arbitrary object structure.
Jet is a complete solution for efficient and high performance database access, consisting of type-safe SQL builder
with code generation and automatic query result data mapping.
Jet currently supports `PostgreSQL`, `MySQL` and `MariaDB`. Future releases will add support for additional databases.

![jet](https://github.com/go-jet/jet/wiki/image/jet.png)
Jet is the easiest and the fastest way to write complex SQL queries and map database query result
Jet is the easiest and the fastest way to write complex type-safe SQL queries as a Go code and map database query result
into complex object composition. __It is not an ORM.__

## Motivation
Expand Down Expand Up @@ -58,22 +58,28 @@ https://medium.com/@go.jet/jet-5f3667efa0cc

To install Jet package, you need to install Go and set your Go workspace first.

[Go](https://golang.org/) **version 1.8+ is required**
[Go](https://golang.org/) **version 1.9+ is required**

### Installation

Use the bellow command to install jet
Use the bellow command 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:

```sh
$ go get -u github.com/go-jet/jet
```

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

```sh
go install github.com/go-jet/jet/cmd/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.
*Make sure GOPATH bin folder is added to the PATH environment variable.*

### 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 All @@ -85,7 +91,7 @@ connection parameters and root destination folder path for generated files.\
Assuming we are running local postgres database, with user `jetuser`, user password `jetpass`, database `jetdb` and
schema `dvds` we will use this command:
```sh
jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=./gen
jet -source=PostgreSQL -host=localhost -port=5432 -user=jetuser -password=jetpass -dbname=jetdb -schema=dvds -path=./.gen
```
```sh
Connecting to postgres database: host=localhost port=5432 user=jetuser password=jetpass dbname=jetdb sslmode=disable
Expand Down Expand Up @@ -144,10 +150,10 @@ First we need to import jet and generated files from previous step:
import (
// dot import so go code would resemble as much as native SQL
// dot import is not mandatory
. "github.com/go-jet/jet/examples/quick-start/.gen/jetdb/dvds/table"
. "github.com/go-jet/jet/postgres"
. "github.com/go-jet/jet/v2/examples/quick-start/.gen/jetdb/dvds/table"
. "github.com/go-jet/jet/v2/postgres"

"github.com/go-jet/jet/examples/quick-start/gen/jetdb/dvds/model"
"github.com/go-jet/jet/v2/examples/quick-start/gen/jetdb/dvds/model"
)
```
Lets say we want to retrieve the list of all _actors_ that acted in _films_ longer than 180 minutes, _film language_ is 'English'
Expand Down
8 changes: 4 additions & 4 deletions cmd/jet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"flag"
"fmt"
mysqlgen "github.com/go-jet/jet/generator/mysql"
postgresgen "github.com/go-jet/jet/generator/postgres"
"github.com/go-jet/jet/mysql"
"github.com/go-jet/jet/postgres"
mysqlgen "github.com/go-jet/jet/v2/generator/mysql"
postgresgen "github.com/go-jet/jet/v2/generator/postgres"
"github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/postgres"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"os"
Expand Down
13 changes: 8 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ result into desired arbitrary object structure.
Installation
Use the bellow command to install jet
Use the bellow command to add jet as a dependency into go.mod project:
$ go get github.com/go-jet/jet/v2
Use the bellow command to add jet as a dependency into GOPATH project:
$ go get -u github.com/go-jet/jet
Install jet generator to GOPATH bin folder. This will allow generating jet files from the command line.
go install github.com/go-jet/jet/cmd/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.
Make sure GOPATH bin folder is added to the PATH environment variable.
Usage
Expand All @@ -26,10 +29,10 @@ Then next step is to import generated SQL Builder and Model files and write SQL
import "some_path/.gen/jetdb/dvds/model"
To write SQL queries for PostgreSQL import:
. "github.com/go-jet/jet/postgres"
. "github.com/go-jet/jet/v2/postgres"
To write SQL queries for MySQL and MariaDB import:
. "github.com/go-jet/jet/mysql"
. "github.com/go-jet/jet/v2/mysql"
*Dot import is used so that Go code resemble as much as native SQL. Dot import is not mandatory.
Write SQL:
Expand Down
2 changes: 1 addition & 1 deletion examples/quick-start/.gen/jetdb/dvds/enum/mpaa_rating.go

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

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.

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

2 changes: 1 addition & 1 deletion examples/quick-start/.gen/jetdb/dvds/table/language.go

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

2 changes: 1 addition & 1 deletion examples/quick-start/.gen/jetdb/dvds/view/actor_info.go

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

2 changes: 1 addition & 1 deletion examples/quick-start/.gen/jetdb/dvds/view/customer_list.go

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

2 changes: 1 addition & 1 deletion examples/quick-start/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Jet generated files of interest are in `./gen` folder.
with a difference of redirecting json output to files(`dest.json` and `dest2.json`) rather then to a
standard output.

`./gen`, `dest.json` and `dest2.json` - added to git for presentation purposes.
`./gen`, `dest.json` and `dest2.json` - added into git for presentation purposes.
6 changes: 3 additions & 3 deletions examples/quick-start/quick-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

// dot import so that jet go code would resemble as much as native SQL
// dot import is not mandatory
. "github.com/go-jet/jet/examples/quick-start/.gen/jetdb/dvds/table"
. "github.com/go-jet/jet/postgres"
. "github.com/go-jet/jet/v2/examples/quick-start/.gen/jetdb/dvds/table"
. "github.com/go-jet/jet/v2/postgres"

"github.com/go-jet/jet/examples/quick-start/.gen/jetdb/dvds/model"
"github.com/go-jet/jet/v2/examples/quick-start/.gen/jetdb/dvds/model"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/metadata/column_meta_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metadata
import (
"database/sql"
"fmt"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/internal/utils"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion generator/internal/metadata/schema_meta_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metadata
import (
"database/sql"
"fmt"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/internal/utils"
)

// SchemaMetaData struct
Expand Down
2 changes: 1 addition & 1 deletion generator/internal/metadata/table_meta_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package metadata

import (
"database/sql"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/internal/utils"
"strings"
)

Expand Down
6 changes: 3 additions & 3 deletions generator/internal/template/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package template
import (
"bytes"
"fmt"
"github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/internal/jet"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/generator/internal/metadata"
"github.com/go-jet/jet/v2/internal/jet"
"github.com/go-jet/jet/v2/internal/utils"
"path/filepath"
"text/template"
)
Expand Down
6 changes: 3 additions & 3 deletions generator/internal/template/templates.go

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

8 changes: 4 additions & 4 deletions generator/mysql/mysql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package mysql
import (
"database/sql"
"fmt"
"github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/generator/internal/template"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/mysql"
"github.com/go-jet/jet/v2/generator/internal/metadata"
"github.com/go-jet/jet/v2/generator/internal/template"
"github.com/go-jet/jet/v2/internal/utils"
"github.com/go-jet/jet/v2/mysql"
"path"
)

Expand Down
4 changes: 2 additions & 2 deletions generator/mysql/query_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package mysql

import (
"database/sql"
"github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/generator/internal/metadata"
"github.com/go-jet/jet/v2/internal/utils"
"strings"
)

Expand Down
8 changes: 4 additions & 4 deletions generator/postgres/postgres_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package postgres
import (
"database/sql"
"fmt"
"github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/generator/internal/template"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/postgres"
"github.com/go-jet/jet/v2/generator/internal/metadata"
"github.com/go-jet/jet/v2/generator/internal/template"
"github.com/go-jet/jet/v2/internal/utils"
"github.com/go-jet/jet/v2/postgres"
"path"
"strconv"
)
Expand Down
4 changes: 2 additions & 2 deletions generator/postgres/query_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package postgres

import (
"database/sql"
"github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/generator/internal/metadata"
"github.com/go-jet/jet/v2/internal/utils"
)

// postgresQuerySet is dialect query set for PostgreSQL
Expand Down
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/go-jet/jet/v2

go 1.11

require (
github.com/go-sql-driver/mysql v1.5.0
github.com/google/go-cmp v0.5.0
github.com/google/uuid v1.1.1
github.com/lib/pq v1.7.0
github.com/pkg/profile v1.5.0
github.com/stretchr/testify v1.6.1
)
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-jet/jet v1.0.0 h1:ENxUe/6lH82qLykIGAdZIlskZrpTeNfxjHz4VHtkVmA=
github.com/go-jet/jet v2.3.0+incompatible h1:Yg7JSERDC0f9x3dHUBMA2cxe9/qC6qlozDDO/s38USU=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY=
github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pkg/profile v1.5.0 h1:042Buzk+NhDI+DeSAA62RwJL8VAuZUMQZUjCsRz1Mug=
github.com/pkg/profile v1.5.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion internal/jet/clause.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jet

import (
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/v2/internal/utils"
)

// Clause interface
Expand Down
Loading

0 comments on commit fdde2ab

Please sign in to comment.