From b646dd2c9952f8d270ba8106b57bb6ca644b0306 Mon Sep 17 00:00:00 2001 From: go-jet Date: Thu, 26 Sep 2019 11:44:46 +0200 Subject: [PATCH] Use type aliasing to forward types from internal/jet. --- mysql/columns.go | 20 ++++++++++---------- mysql/expressions.go | 18 +++++++++--------- mysql/select_statement.go | 2 +- mysql/types.go | 14 ++------------ postgres/columns.go | 22 +++++++++++----------- postgres/expressions.go | 20 ++++++++++---------- postgres/select_statement.go | 2 +- postgres/types.go | 14 ++------------ tests/postgres/delete_test.go | 4 +++- 9 files changed, 49 insertions(+), 67 deletions(-) diff --git a/mysql/columns.go b/mysql/columns.go index 7b05b1d..64537aa 100644 --- a/mysql/columns.go +++ b/mysql/columns.go @@ -3,59 +3,59 @@ package mysql import "github.com/go-jet/jet/internal/jet" // Column is common column interface for all types of columns. -type Column jet.ColumnExpression +type Column = jet.ColumnExpression // IColumnList is used to store list of columns for later reuse as projection or column list for UPDATE and INSERT statement. -type IColumnList jet.IColumnList +type IColumnList = jet.IColumnList // ColumnList function returns list of columns that be used as projection or column list for UPDATE and INSERT statement. var ColumnList = jet.ColumnList // ColumnBool is interface for SQL boolean columns. -type ColumnBool jet.ColumnBool +type ColumnBool = jet.ColumnBool // BoolColumn creates named bool column. var BoolColumn = jet.BoolColumn // ColumnString is interface for SQL text, character, character varying // bytea, uuid columns and enums types. -type ColumnString jet.ColumnString +type ColumnString = jet.ColumnString // StringColumn creates named string column. var StringColumn = jet.StringColumn // ColumnInteger is interface for SQL smallint, integer, bigint columns. -type ColumnInteger jet.ColumnInteger +type ColumnInteger = jet.ColumnInteger // IntegerColumn creates named integer column. var IntegerColumn = jet.IntegerColumn // ColumnFloat is interface for SQL real, numeric, decimal or double precision column. -type ColumnFloat jet.ColumnFloat +type ColumnFloat = jet.ColumnFloat // FloatColumn creates named float column. var FloatColumn = jet.FloatColumn // ColumnTime is interface for SQL time column. -type ColumnTime jet.ColumnTime +type ColumnTime = jet.ColumnTime // TimeColumn creates named time column var TimeColumn = jet.TimeColumn // ColumnDate is interface of SQL date columns. -type ColumnDate jet.ColumnDate +type ColumnDate = jet.ColumnDate // DateColumn creates named date column. var DateColumn = jet.DateColumn // ColumnDateTime is interface of SQL timestamp columns. -type ColumnDateTime jet.ColumnTimestamp +type ColumnDateTime = jet.ColumnTimestamp // DateTimeColumn creates named timestamp column var DateTimeColumn = jet.TimestampColumn // ColumnTimestamp is interface of SQL timestamp columns. -type ColumnTimestamp jet.ColumnTimestamp +type ColumnTimestamp = jet.ColumnTimestamp // TimestampColumn creates named timestamp column var TimestampColumn = jet.TimestampColumn diff --git a/mysql/expressions.go b/mysql/expressions.go index b4b7838..6d9cea7 100644 --- a/mysql/expressions.go +++ b/mysql/expressions.go @@ -4,31 +4,31 @@ import "github.com/go-jet/jet/internal/jet" // Expression is common interface for all expressions. // Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions. -type Expression jet.Expression +type Expression = jet.Expression // BoolExpression interface -type BoolExpression jet.BoolExpression +type BoolExpression = jet.BoolExpression // StringExpression interface -type StringExpression jet.StringExpression +type StringExpression = jet.StringExpression // IntegerExpression interface -type IntegerExpression jet.IntegerExpression +type IntegerExpression = jet.IntegerExpression // FloatExpression interface -type FloatExpression jet.FloatExpression +type FloatExpression = jet.FloatExpression // TimeExpression interface -type TimeExpression jet.TimeExpression +type TimeExpression = jet.TimeExpression // DateExpression interface -type DateExpression jet.DateExpression +type DateExpression = jet.DateExpression // DateTimeExpression interface -type DateTimeExpression jet.TimestampExpression +type DateTimeExpression = jet.TimestampExpression // TimestampExpression interface -type TimestampExpression jet.TimestampExpression +type TimestampExpression = jet.TimestampExpression // BoolExp is bool expression wrapper around arbitrary expression. // Allows go compiler to see any expression as bool expression. diff --git a/mysql/select_statement.go b/mysql/select_statement.go index 3347888..720ae57 100644 --- a/mysql/select_statement.go +++ b/mysql/select_statement.go @@ -69,7 +69,7 @@ func newSelectStatement(table ReadableTable, projections []Projection) SelectSta &newSelect.From, &newSelect.Where, &newSelect.GroupBy, &newSelect.Having, &newSelect.Window, &newSelect.OrderBy, &newSelect.Limit, &newSelect.Offset, &newSelect.For, &newSelect.ShareLock) - newSelect.Select.Projections = toJetProjectionList(projections) + newSelect.Select.Projections = projections newSelect.From.Table = table newSelect.Limit.Count = -1 newSelect.Offset.Count = -1 diff --git a/mysql/types.go b/mysql/types.go index bcc8fcb..2902e72 100644 --- a/mysql/types.go +++ b/mysql/types.go @@ -3,17 +3,7 @@ package mysql import "github.com/go-jet/jet/internal/jet" // Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK) -type Statement jet.Statement +type Statement = jet.Statement // Projection is interface for all projection types. Types that can be part of, for instance SELECT clause. -type Projection jet.Projection - -func toJetProjectionList(projections []Projection) []jet.Projection { - ret := []jet.Projection{} - - for _, projection := range projections { - ret = append(ret, projection) - } - - return ret -} +type Projection = jet.Projection diff --git a/postgres/columns.go b/postgres/columns.go index d02d05c..a9c4879 100644 --- a/postgres/columns.go +++ b/postgres/columns.go @@ -3,66 +3,66 @@ package postgres import "github.com/go-jet/jet/internal/jet" // Column is common column interface for all types of columns. -type Column jet.ColumnExpression +type Column = jet.ColumnExpression // IColumnList is used to store list of columns for later reuse as single projection or // column list for UPDATE and INSERT statement. -type IColumnList jet.IColumnList +type IColumnList = jet.IColumnList // ColumnList function returns list of columns that be used as projection or column list for UPDATE and INSERT statement. var ColumnList = jet.ColumnList // ColumnBool is interface for SQL boolean columns. -type ColumnBool jet.ColumnBool +type ColumnBool = jet.ColumnBool // BoolColumn creates named bool column. var BoolColumn = jet.BoolColumn // ColumnString is interface for SQL text, character, character varying // bytea, uuid columns and enums types. -type ColumnString jet.ColumnString +type ColumnString = jet.ColumnString // StringColumn creates named string column. var StringColumn = jet.StringColumn // ColumnInteger is interface for SQL smallint, integer, bigint columns. -type ColumnInteger jet.ColumnInteger +type ColumnInteger = jet.ColumnInteger // IntegerColumn creates named integer column. var IntegerColumn = jet.IntegerColumn // ColumnFloat is interface for SQL real, numeric, decimal or double precision column. -type ColumnFloat jet.ColumnFloat +type ColumnFloat = jet.ColumnFloat // FloatColumn creates named float column. var FloatColumn = jet.FloatColumn // ColumnDate is interface of SQL date columns. -type ColumnDate jet.ColumnDate +type ColumnDate = jet.ColumnDate // DateColumn creates named date column. var DateColumn = jet.DateColumn // ColumnTime is interface for SQL time column. -type ColumnTime jet.ColumnTime +type ColumnTime = jet.ColumnTime // TimeColumn creates named time column var TimeColumn = jet.TimeColumn // ColumnTimez is interface of SQL time with time zone columns. -type ColumnTimez jet.ColumnTimez +type ColumnTimez = jet.ColumnTimez // TimezColumn creates named time with time zone column. var TimezColumn = jet.TimezColumn // ColumnTimestamp is interface of SQL timestamp columns. -type ColumnTimestamp jet.ColumnTimestamp +type ColumnTimestamp = jet.ColumnTimestamp // TimestampColumn creates named timestamp column var TimestampColumn = jet.TimestampColumn // ColumnTimestampz is interface of SQL timestamp with timezone columns. -type ColumnTimestampz jet.ColumnTimestampz +type ColumnTimestampz = jet.ColumnTimestampz // TimestampzColumn creates named timestamp with time zone column. var TimestampzColumn = jet.TimestampzColumn diff --git a/postgres/expressions.go b/postgres/expressions.go index 3148ea1..0383eee 100644 --- a/postgres/expressions.go +++ b/postgres/expressions.go @@ -4,34 +4,34 @@ import "github.com/go-jet/jet/internal/jet" // Expression is common interface for all expressions. // Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions. -type Expression jet.Expression +type Expression = jet.Expression // BoolExpression interface -type BoolExpression jet.BoolExpression +type BoolExpression = jet.BoolExpression // StringExpression interface -type StringExpression jet.StringExpression +type StringExpression = jet.StringExpression // IntegerExpression interface -type IntegerExpression jet.IntegerExpression +type IntegerExpression = jet.IntegerExpression //FloatExpression is interface -type FloatExpression jet.FloatExpression +type FloatExpression = jet.FloatExpression // TimeExpression interface -type TimeExpression jet.TimeExpression +type TimeExpression = jet.TimeExpression // TimezExpression interface for 'time with time zone' types -type TimezExpression jet.TimezExpression +type TimezExpression = jet.TimezExpression // DateExpression is interface for date types -type DateExpression jet.DateExpression +type DateExpression = jet.DateExpression // TimestampExpression interface -type TimestampExpression jet.TimestampExpression +type TimestampExpression = jet.TimestampExpression // TimestampzExpression interface -type TimestampzExpression jet.TimestampzExpression +type TimestampzExpression = jet.TimestampzExpression // BoolExp is bool expression wrapper around arbitrary expression. // Allows go compiler to see any expression as bool expression. diff --git a/postgres/select_statement.go b/postgres/select_statement.go index e4aeb37..c001a57 100644 --- a/postgres/select_statement.go +++ b/postgres/select_statement.go @@ -75,7 +75,7 @@ func newSelectStatement(table ReadableTable, projections []Projection) SelectSta &newSelect.From, &newSelect.Where, &newSelect.GroupBy, &newSelect.Having, &newSelect.Window, &newSelect.OrderBy, &newSelect.Limit, &newSelect.Offset, &newSelect.For) - newSelect.Select.Projections = toJetProjectionList(projections) + newSelect.Select.Projections = projections newSelect.From.Table = table newSelect.Limit.Count = -1 newSelect.Offset.Count = -1 diff --git a/postgres/types.go b/postgres/types.go index 036e4f3..215cceb 100644 --- a/postgres/types.go +++ b/postgres/types.go @@ -3,17 +3,7 @@ package postgres import "github.com/go-jet/jet/internal/jet" // Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK) -type Statement jet.Statement +type Statement = jet.Statement // Projection is interface for all projection types. Types that can be part of, for instance SELECT clause. -type Projection jet.Projection - -func toJetProjectionList(projections []Projection) []jet.Projection { - ret := []jet.Projection{} - - for _, projection := range projections { - ret = append(ret, projection) - } - - return ret -} +type Projection = jet.Projection diff --git a/tests/postgres/delete_test.go b/tests/postgres/delete_test.go index f8d264a..352a788 100644 --- a/tests/postgres/delete_test.go +++ b/tests/postgres/delete_test.go @@ -85,9 +85,11 @@ func TestDeleteQueryContext(t *testing.T) { func TestDeleteExecContext(t *testing.T) { initForDeleteTest(t) + list := []Expression{String("Gmail"), String("Outlook")} + deleteStmt := Link. DELETE(). - WHERE(Link.Name.IN(String("Gmail"), String("Outlook"))) + WHERE(Link.Name.IN(list...)) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) defer cancel()