Package 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, MariaDB and SQLite. Future releases will add support for additional databases.
Use the command bellow to add jet as a dependency into go.mod project:
Jet generator can be installed in one of the following ways:
(Go1.16+) Install jet generator using go install:
go install github.com/go-jet/jet/v2/cmd/jet@latest
Install jet generator to GOPATH/bin folder:
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
Install jet generator into specific folder:
git clone https://github.com/go-jet/jet.git
cd jet && go build -o dir_path ./cmd/jet
Make sure that the destination folder is added to the PATH environment variable.
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.
Before we can write SQL queries in Go, we need to import generated SQL builder and model types:
To write postgres SQL queries we import:
Then we can write the SQL query:
Now we can run the statement and store the result into desired destination:
We can print a statement to see SQL query and arguments sent to postgres server:
If we print destination as json, we'll get:
Detail info about all statements, features and use cases can be
found at project wiki page - https://github.com/go-jet/jet/wiki.