Update doc.go and README.md.
This commit is contained in:
parent
c7fae18a3d
commit
b7363a554b
2 changed files with 76 additions and 7 deletions
10
README.md
10
README.md
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
|
||||
Jet is a framework for writing type-safe SQL queries in Go, with ability to easily
|
||||
convert database query result to desired arbitrary structure.
|
||||
Jet currently supports `PostgreSQL`, `MySQL` and `MariaDB`. Support for additional databases will be added in future jet releases.
|
||||
convert database query result into desired arbitrary object structure.
|
||||
Jet currently supports `PostgreSQL`, `MySQL` and `MariaDB`. Future releases will add support for additional databases.
|
||||
|
||||

|
||||
Jet is the easiest and fastest way to write complex SQL queries and map database query result
|
||||
|
|
@ -286,7 +286,7 @@ var dest []struct {
|
|||
```
|
||||
Because one actor can act in multiple films, `Films` field is a slice, and because each film belongs to one language
|
||||
`Langauge` field is just a single model struct.
|
||||
_*There is no limitation of how big or nested destination structure can be._
|
||||
_*There is no limitation of how big or nested destination can be._
|
||||
|
||||
Now lets execute a above statement on open database connection (or transaction) db and store result into `dest`.
|
||||
|
||||
|
|
@ -540,8 +540,8 @@ Without Jet these bugs will have to be either caught by some test or by manual t
|
|||
|
||||
## Dependencies
|
||||
At the moment Jet dependence only of:
|
||||
- `github.com/lib/pq` _(Used by jet generator to read information about database schema from PostgreSQL)_
|
||||
- `github.com/go-sql-driver/mysql` _(Used by jet generator to read information about database from MySQL and MariaDB)_
|
||||
- `github.com/lib/pq` _(Used by jet generator to read information about database schema from `PostgreSQL`)_
|
||||
- `github.com/go-sql-driver/mysql` _(Used by jet generator to read information about database from `MySQL` and `MariaDB`)_
|
||||
- `github.com/google/uuid` _(Used in data model files and for debug purposes)_
|
||||
|
||||
To run the tests, additional dependencies are required:
|
||||
|
|
|
|||
73
doc.go
73
doc.go
|
|
@ -1,5 +1,74 @@
|
|||
/*
|
||||
Package jet is a framework for writing type-safe SQL queries for PostgreSQL in Go, with ability
|
||||
to easily convert database query result to desired arbitrary structure.
|
||||
Package 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.
|
||||
|
||||
|
||||
Installation
|
||||
|
||||
|
||||
Use the bellow command to install jet
|
||||
$ 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
|
||||
|
||||
*Make sure GOPATH bin folder is added to the PATH environment variable.
|
||||
|
||||
Usage
|
||||
|
||||
Jet requires already defined database schema(with tables, enums etc), so that jet generator can generate SQL Builder
|
||||
and Model files. File generation is very fast, and can be added as every pre-build step.
|
||||
Sample command:
|
||||
jet -source=PostgreSQL -host=localhost -port=5432 -user=jet -password=pass -dbname=jetdb -schema=dvds -path=./gen
|
||||
|
||||
Then next step is to import generated SQL Builder and Model files and write SQL queries in Go:
|
||||
import . "some_path/.gen/jetdb/dvds/table"
|
||||
import "some_path/.gen/jetdb/dvds/model"
|
||||
|
||||
To write SQL queries for PostgreSQL import:
|
||||
. "github.com/go-jet/jet/postgres"
|
||||
|
||||
To write SQL queries for MySQL and MariaDB import:
|
||||
. "github.com/go-jet/jet/mysql"
|
||||
*Dot import is used so that Go code resemble as much as native SQL. Dot import is not mandatory.
|
||||
|
||||
Write SQL:
|
||||
// sub-query
|
||||
rRatingFilms := SELECT(
|
||||
Film.FilmID,
|
||||
Film.Title,
|
||||
Film.Rating,
|
||||
).
|
||||
FROM(Film).
|
||||
WHERE(Film.Rating.EQ(enum.FilmRating.R)).
|
||||
AsTable("rFilms")
|
||||
|
||||
// export column from sub-query
|
||||
rFilmID := Film.FilmID.From(rRatingFilms)
|
||||
|
||||
// main-query
|
||||
query := SELECT(
|
||||
Actor.AllColumns,
|
||||
FilmActor.AllColumns,
|
||||
rRatingFilms.AllColumns(),
|
||||
).
|
||||
FROM(
|
||||
rRatingFilms.
|
||||
INNER_JOIN(FilmActor, FilmActor.FilmID.EQ(rFilmID)).
|
||||
INNER_JOIN(Actor, Actor.ActorID.EQ(FilmActor.ActorID)
|
||||
).
|
||||
ORDER_BY(rFilmID, Actor.ActorID)
|
||||
|
||||
Store result into desired destination:
|
||||
var dest []struct {
|
||||
model.Film
|
||||
|
||||
Actors []model.Actor
|
||||
}
|
||||
|
||||
err := query.Query(db, &dest)
|
||||
|
||||
Detail info about all features and use cases can be
|
||||
found at project wiki page - https://github.com/go-jet/jet/wiki.
|
||||
*/
|
||||
package jet
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue