Skip to content

Commit

Permalink
Go fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
go-jet committed Aug 23, 2022
1 parent 4e1ff65 commit a2ea189
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 43 deletions.
30 changes: 17 additions & 13 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,45 @@ Package jet is a complete solution for efficient and high performance database a
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.
Installation
# Installation
Use the command bellow to add jet as a dependency into go.mod project:
$ go get -u github.com/go-jet/jet/v2
Jet generator can be installed in one of the following ways:
1) (Go1.16+) Install jet generator using go install:
go install github.com/go-jet/jet/v2/cmd/jet@latest
1. (Go1.16+) Install jet generator using go install:
go install github.com/go-jet/jet/v2/cmd/jet@latest
2) Install jet generator to GOPATH/bin folder:
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
2. Install jet generator to GOPATH/bin folder:
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
3) Install jet generator into specific folder:
git clone https://github.com/go-jet/jet.git
cd jet && go build -o dir_path ./cmd/jet
3. 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.
Usage
# 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 -dsn=postgresql://user:pass@localhost:5432/jetdb -schema=dvds -path=./.gen
Before we can write SQL queries in Go, we need to import generated SQL builder and model types:
import . "some_path/.gen/jetdb/dvds/table"
import "some_path/.gen/jetdb/dvds/model"
To write postgres SQL queries we import:
. "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.
Then we can write the SQL query:
// sub-query
rRatingFilms :=
SELECT(
Expand Down Expand Up @@ -72,6 +73,7 @@ Then we can write the SQL query:
)
Now we can run the statement and store the result into desired destination:
var dest []struct {
model.Film
Expand All @@ -81,9 +83,11 @@ Now we can run the statement and store the result into desired destination:
err := stmt.Query(db, &dest)
We can print a statement to see SQL query and arguments sent to postgres server:
fmt.Println(stmt.Sql())
Output:
SELECT "rFilms"."film.film_id" AS "film.film_id",
"rFilms"."film.title" AS "film.title",
"rFilms"."film.rating" AS "film.rating",
Expand Down
6 changes: 1 addition & 5 deletions internal/jet/bool_expression.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jet

//BoolExpression interface
// BoolExpression interface
type BoolExpression interface {
Expression

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

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

//---------------------------------------------------//
func newPrefixBoolOperatorExpression(expression Expression, operator string) BoolExpression {
return BoolExp(newPrefixOperatorExpression(expression, operator))
}

//---------------------------------------------------//
func newPostfixBoolOperatorExpression(expression Expression, operator string) BoolExpression {
return BoolExp(newPostfixOperatorExpression(expression, operator))
}

//---------------------------------------------------//
type boolExpressionWrapper struct {
boolInterfaceImpl
Expression
Expand Down
8 changes: 4 additions & 4 deletions internal/jet/column_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package jet
type ColumnList []ColumnExpression

// SET creates column assigment for each column in column list. expression should be created by ROW function
// Link.UPDATE().
// SET(Link.MutableColumns.SET(ROW(String("github.com"), Bool(false))).
// WHERE(Link.ID.EQ(Int(0)))
//
// Link.UPDATE().
// SET(Link.MutableColumns.SET(ROW(String("github.com"), Bool(false))).
// WHERE(Link.ID.EQ(Int(0)))
func (cl ColumnList) SET(expression Expression) ColumnAssigment {
return columnAssigmentImpl{
column: cl,
Expand All @@ -16,8 +16,8 @@ func (cl ColumnList) SET(expression Expression) ColumnAssigment {
}

// Except will create new column list in which columns contained in list of excluded column names are removed
// Address.AllColumns.Except(Address.PostalCode, Address.Phone)
//
// Address.AllColumns.Except(Address.PostalCode, Address.Phone)
func (cl ColumnList) Except(excludedColumns ...Column) ColumnList {
excludedColumnList := UnwidColumnList(excludedColumns)
excludedColumnNames := map[string]bool{}
Expand Down
2 changes: 1 addition & 1 deletion internal/jet/float_expression.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jet

//FloatExpression is interface for SQL float columns
// FloatExpression is interface for SQL float columns
type FloatExpression interface {
Expression
numericExpression
Expand Down
3 changes: 0 additions & 3 deletions internal/jet/integer_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,14 @@ func (i *integerInterfaceImpl) BIT_SHIFT_RIGHT(intExpression IntegerExpression)
return newBinaryIntegerOperatorExpression(i.parent, intExpression, ">>")
}

//---------------------------------------------------//
func newBinaryIntegerOperatorExpression(lhs, rhs IntegerExpression, operator string) IntegerExpression {
return IntExp(NewBinaryOperatorExpression(lhs, rhs, operator))
}

//---------------------------------------------------//
func newPrefixIntegerOperatorExpression(expression IntegerExpression, operator string) IntegerExpression {
return IntExp(newPrefixOperatorExpression(expression, operator))
}

//---------------------------------------------------//
type integerExpressionWrapper struct {
integerInterfaceImpl

Expand Down
8 changes: 4 additions & 4 deletions internal/jet/literal_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func Uint64(value uint64) IntegerExpression {
return intLiteral(value)
}

//---------------------------------------------------//
// ---------------------------------------------------//
type boolLiteralExpression struct {
boolInterfaceImpl
literalExpressionImpl
Expand All @@ -134,7 +134,7 @@ func Bool(value bool) BoolExpression {
return &boolLiteralExpression
}

//---------------------------------------------------//
// ---------------------------------------------------//
type floatLiteral struct {
floatInterfaceImpl
literalExpressionImpl
Expand All @@ -160,7 +160,7 @@ func Decimal(value string) FloatExpression {
return &floatLiteral
}

//---------------------------------------------------//
// ---------------------------------------------------//
type stringLiteral struct {
stringInterfaceImpl
literalExpressionImpl
Expand Down Expand Up @@ -351,7 +351,7 @@ func (n *nullLiteral) serialize(statement StatementType, out *SQLBuilder, option
out.WriteString("NULL")
}

//--------------------------------------------------//
// --------------------------------------------------//
type starLiteral struct {
ExpressionInterfaceImpl
}
Expand Down
2 changes: 1 addition & 1 deletion internal/jet/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"
)

//Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)
// Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)
type Statement interface {
// Sql returns parametrized sql query with list of arguments.
Sql() (query string, args []interface{})
Expand Down
2 changes: 1 addition & 1 deletion internal/jet/string_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *stringInterfaceImpl) NOT_REGEXP_LIKE(pattern StringExpression, caseSens
return newBinaryBoolOperatorExpression(s.parent, pattern, StringNotRegexpLikeOperator, Bool(len(caseSensitive) > 0 && caseSensitive[0]))
}

//---------------------------------------------------//
// ---------------------------------------------------//
func newBinaryStringOperatorExpression(lhs, rhs Expression, operator string) StringExpression {
return StringExp(NewBinaryOperatorExpression(lhs, rhs, operator))
}
Expand Down
2 changes: 1 addition & 1 deletion mysql/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *castImpl) AS_CHAR(length ...int) StringExpression {
return StringExp(c.AS("CHAR"))
}

// AS_DATE casts expression AS DATE type
// AS_DATE casts expression AS DATE type
func (c *castImpl) AS_DATE() DateExpression {
return DateExp(c.AS("DATE"))
}
Expand Down
3 changes: 2 additions & 1 deletion mysql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ var REGEXP_LIKE = jet.REGEXP_LIKE
//----------------- Date/Time Functions and Operators ------------//

// EXTRACT function retrieves subfields such as year or hour from date/time values
// EXTRACT(DAY, User.CreatedAt)
//
// EXTRACT(DAY, User.CreatedAt)
func EXTRACT(field unitType, from Expression) IntegerExpression {
return IntExp(jet.EXTRACT(string(field), from))
}
Expand Down
7 changes: 4 additions & 3 deletions mysql/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ const (
type Interval = jet.Interval

// INTERVAL creates new temporal interval.
// In a case of MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR unit type
// value parameter has to be a number.
//
// In a case of MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR unit type
// value parameter has to be a number.
// INTERVAL(1, DAY)
// In a case of other unit types, value should be string with appropriate format.
// In a case of other unit types, value should be string with appropriate format.
// INTERVAL("10:08:50", HOUR_SECOND)
func INTERVAL(value interface{}, unitType unitType) Interval {
switch unitType {
Expand Down
2 changes: 1 addition & 1 deletion postgres/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type NumericExpression = jet.NumericExpression
// IntegerExpression interface
type IntegerExpression = jet.IntegerExpression

//FloatExpression is interface
// FloatExpression is interface
type FloatExpression = jet.FloatExpression

// TimeExpression interface
Expand Down
3 changes: 2 additions & 1 deletion postgres/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ const (
)

// EXTRACT function retrieves subfields such as year or hour from date/time values
// EXTRACT(DAY, User.CreatedAt)
//
// EXTRACT(DAY, User.CreatedAt)
func EXTRACT(field unit, from Expression) FloatExpression {
return FloatExp(jet.EXTRACT(unitToString(field), from))
}
Expand Down
3 changes: 2 additions & 1 deletion postgres/interval_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ type intervalExpression struct {
}

// INTERVAL creates new interval expression from the list of quantity-unit pairs.
// INTERVAL(1, DAY, 3, MINUTE)
//
// INTERVAL(1, DAY, 3, MINUTE)
func INTERVAL(quantityAndUnit ...quantityAndUnit) IntervalExpression {
quantityAndUnitLen := len(quantityAndUnit)
if quantityAndUnitLen == 0 || quantityAndUnitLen%2 != 0 {
Expand Down
2 changes: 1 addition & 1 deletion postgres/select_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type SelectStatement interface {
AsTable(alias string) SelectTable
}

//SELECT creates new SelectStatement with list of projections
// SELECT creates new SelectStatement with list of projections
func SELECT(projection Projection, projections ...Projection) SelectStatement {
return newSelectStatement(nil, append([]Projection{projection}, projections...))
}
Expand Down
2 changes: 1 addition & 1 deletion sqlite/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type ColumnDateTime = jet.ColumnTimestamp
// DateTimeColumn creates named timestamp column
var DateTimeColumn = jet.TimestampColumn

//ColumnTimestamp is interface of SQL timestamp columns.
// ColumnTimestamp is interface of SQL timestamp columns.
type ColumnTimestamp = jet.ColumnTimestamp

// TimestampColumn creates named timestamp column
Expand Down
2 changes: 1 addition & 1 deletion sqlite/select_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type SelectStatement interface {
AsTable(alias string) SelectTable
}

//SELECT creates new SelectStatement with list of projections
// SELECT creates new SelectStatement with list of projections
func SELECT(projection Projection, projections ...Projection) SelectStatement {
return newSelectStatement(nil, append([]Projection{projection}, projections...))
}
Expand Down

0 comments on commit a2ea189

Please sign in to comment.