From a2ea1892e52acea3195b34fd08f5375f18ccf8dd Mon Sep 17 00:00:00 2001 From: go-jet Date: Tue, 23 Aug 2022 12:38:16 +0200 Subject: [PATCH] Go fmt. --- doc.go | 30 +++++++++++++++++------------- internal/jet/bool_expression.go | 6 +----- internal/jet/column_list.go | 8 ++++---- internal/jet/float_expression.go | 2 +- internal/jet/integer_expression.go | 3 --- internal/jet/literal_expression.go | 8 ++++---- internal/jet/statement.go | 2 +- internal/jet/string_expression.go | 2 +- mysql/cast.go | 2 +- mysql/functions.go | 3 ++- mysql/interval.go | 7 ++++--- postgres/expressions.go | 2 +- postgres/functions.go | 3 ++- postgres/interval_expression.go | 3 ++- postgres/select_statement.go | 2 +- sqlite/columns.go | 2 +- sqlite/select_statement.go | 2 +- 17 files changed, 44 insertions(+), 43 deletions(-) diff --git a/doc.go b/doc.go index 44a3e893..9f637bb5 100644 --- a/doc.go +++ b/doc.go @@ -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( @@ -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 @@ -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", diff --git a/internal/jet/bool_expression.go b/internal/jet/bool_expression.go index b4015b27..41bdcc44 100644 --- a/internal/jet/bool_expression.go +++ b/internal/jet/bool_expression.go @@ -1,6 +1,6 @@ package jet -//BoolExpression interface +// BoolExpression interface type BoolExpression interface { Expression @@ -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 diff --git a/internal/jet/column_list.go b/internal/jet/column_list.go index 2fdb3588..a4a0b663 100644 --- a/internal/jet/column_list.go +++ b/internal/jet/column_list.go @@ -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, @@ -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{} diff --git a/internal/jet/float_expression.go b/internal/jet/float_expression.go index 3fb30fed..52c97ebc 100644 --- a/internal/jet/float_expression.go +++ b/internal/jet/float_expression.go @@ -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 diff --git a/internal/jet/integer_expression.go b/internal/jet/integer_expression.go index 32d15e04..0bce229b 100644 --- a/internal/jet/integer_expression.go +++ b/internal/jet/integer_expression.go @@ -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 diff --git a/internal/jet/literal_expression.go b/internal/jet/literal_expression.go index 450b0abc..c71cc150 100644 --- a/internal/jet/literal_expression.go +++ b/internal/jet/literal_expression.go @@ -118,7 +118,7 @@ func Uint64(value uint64) IntegerExpression { return intLiteral(value) } -//---------------------------------------------------// +// ---------------------------------------------------// type boolLiteralExpression struct { boolInterfaceImpl literalExpressionImpl @@ -134,7 +134,7 @@ func Bool(value bool) BoolExpression { return &boolLiteralExpression } -//---------------------------------------------------// +// ---------------------------------------------------// type floatLiteral struct { floatInterfaceImpl literalExpressionImpl @@ -160,7 +160,7 @@ func Decimal(value string) FloatExpression { return &floatLiteral } -//---------------------------------------------------// +// ---------------------------------------------------// type stringLiteral struct { stringInterfaceImpl literalExpressionImpl @@ -351,7 +351,7 @@ func (n *nullLiteral) serialize(statement StatementType, out *SQLBuilder, option out.WriteString("NULL") } -//--------------------------------------------------// +// --------------------------------------------------// type starLiteral struct { ExpressionInterfaceImpl } diff --git a/internal/jet/statement.go b/internal/jet/statement.go index 11d8c95f..58c3dfa4 100644 --- a/internal/jet/statement.go +++ b/internal/jet/statement.go @@ -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{}) diff --git a/internal/jet/string_expression.go b/internal/jet/string_expression.go index 4e7efa62..29b24472 100644 --- a/internal/jet/string_expression.go +++ b/internal/jet/string_expression.go @@ -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)) } diff --git a/mysql/cast.go b/mysql/cast.go index 5a3e481e..83a0578b 100644 --- a/mysql/cast.go +++ b/mysql/cast.go @@ -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")) } diff --git a/mysql/functions.go b/mysql/functions.go index 24cd73cb..e2e67766 100644 --- a/mysql/functions.go +++ b/mysql/functions.go @@ -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)) } diff --git a/mysql/interval.go b/mysql/interval.go index ea246329..23dcd36e 100644 --- a/mysql/interval.go +++ b/mysql/interval.go @@ -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 { diff --git a/postgres/expressions.go b/postgres/expressions.go index c5c20653..60b0ee7b 100644 --- a/postgres/expressions.go +++ b/postgres/expressions.go @@ -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 diff --git a/postgres/functions.go b/postgres/functions.go index 7cc03353..5b07b452 100644 --- a/postgres/functions.go +++ b/postgres/functions.go @@ -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)) } diff --git a/postgres/interval_expression.go b/postgres/interval_expression.go index d1c47887..323aa315 100644 --- a/postgres/interval_expression.go +++ b/postgres/interval_expression.go @@ -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 { diff --git a/postgres/select_statement.go b/postgres/select_statement.go index ff553fb6..d44d6aad 100644 --- a/postgres/select_statement.go +++ b/postgres/select_statement.go @@ -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...)) } diff --git a/sqlite/columns.go b/sqlite/columns.go index 88ae4f6b..2941b8d6 100644 --- a/sqlite/columns.go +++ b/sqlite/columns.go @@ -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 diff --git a/sqlite/select_statement.go b/sqlite/select_statement.go index b5a75669..5e92d52e 100644 --- a/sqlite/select_statement.go +++ b/sqlite/select_statement.go @@ -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...)) }