jet/postgres/columns.go

134 lines
4.3 KiB
Go
Raw Normal View History

2019-07-27 10:40:30 +02:00
package postgres
import (
2020-06-27 18:48:19 +02:00
"github.com/go-jet/jet/v2/internal/jet"
)
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// Column is common column interface for all types of columns.
type Column = jet.ColumnExpression
2019-08-17 14:49:35 +02:00
// ColumnList function returns list of columns that be used as projection or column list for UPDATE and INSERT statement.
type ColumnList = jet.ColumnList
2019-08-17 14:49:35 +02:00
// ColumnBool is interface for SQL boolean columns.
type ColumnBool = jet.ColumnBool
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// BoolColumn creates named bool column.
2019-07-27 10:40:30 +02:00
var BoolColumn = jet.BoolColumn
2019-08-17 14:49:35 +02:00
// ColumnString is interface for SQL text, character, character varying
// bytea, uuid columns and enums types.
type ColumnString = jet.ColumnString
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// StringColumn creates named string column.
2019-07-27 10:40:30 +02:00
var StringColumn = jet.StringColumn
2019-08-17 14:49:35 +02:00
// ColumnInteger is interface for SQL smallint, integer, bigint columns.
type ColumnInteger = jet.ColumnInteger
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// IntegerColumn creates named integer column.
2019-07-27 10:40:30 +02:00
var IntegerColumn = jet.IntegerColumn
2019-08-17 14:49:35 +02:00
// ColumnFloat is interface for SQL real, numeric, decimal or double precision column.
type ColumnFloat = jet.ColumnFloat
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// FloatColumn creates named float column.
2019-07-27 10:40:30 +02:00
var FloatColumn = jet.FloatColumn
2019-08-03 14:10:47 +02:00
2019-08-17 14:49:35 +02:00
// ColumnDate is interface of SQL date columns.
type ColumnDate = jet.ColumnDate
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// DateColumn creates named date column.
2019-07-27 10:40:30 +02:00
var DateColumn = jet.DateColumn
2019-08-17 14:49:35 +02:00
// ColumnTime is interface for SQL time column.
type ColumnTime = jet.ColumnTime
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// TimeColumn creates named time column
2019-07-31 18:43:54 +02:00
var TimeColumn = jet.TimeColumn
2019-08-03 14:10:47 +02:00
2019-08-17 14:49:35 +02:00
// ColumnTimez is interface of SQL time with time zone columns.
type ColumnTimez = jet.ColumnTimez
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// TimezColumn creates named time with time zone column.
2019-07-27 10:40:30 +02:00
var TimezColumn = jet.TimezColumn
2019-08-17 14:49:35 +02:00
// ColumnTimestamp is interface of SQL timestamp columns.
type ColumnTimestamp = jet.ColumnTimestamp
2019-07-31 18:43:54 +02:00
2019-08-17 14:49:35 +02:00
// TimestampColumn creates named timestamp column
2019-07-31 18:43:54 +02:00
var TimestampColumn = jet.TimestampColumn
2019-08-03 14:10:47 +02:00
2019-08-17 14:49:35 +02:00
// ColumnTimestampz is interface of SQL timestamp with timezone columns.
type ColumnTimestampz = jet.ColumnTimestampz
2019-07-27 10:40:30 +02:00
2019-08-17 14:49:35 +02:00
// TimestampzColumn creates named timestamp with time zone column.
2019-07-27 10:40:30 +02:00
var TimestampzColumn = jet.TimestampzColumn
// ColumnDateRange is interface of SQL date range column
type ColumnDateRange = jet.ColumnRange[DateExpression]
// DateRangeColumn creates named range with range column
var DateRangeColumn = jet.RangeColumn[DateExpression]
// ColumnNumericRange is interface of SQL numeric range column
type ColumnNumericRange = jet.ColumnRange[NumericExpression]
// NumericRangeColumn creates named range with range column
var NumericRangeColumn = jet.RangeColumn[NumericExpression]
// ColumnTimestampRange is interface of SQL timestamp range column
type ColumnTimestampRange = jet.ColumnRange[TimestampExpression]
// TimestampRangeColumn creates named range with range column
var TimestampRangeColumn = jet.RangeColumn[TimestampExpression]
// ColumnTimestampzRange is interface of SQL timestamp range column
type ColumnTimestampzRange = jet.ColumnRange[TimestampzExpression]
// TimestampzRangeColumn creates named range with range column
var TimestampzRangeColumn = jet.RangeColumn[TimestampzExpression]
// ColumnInt4Range is interface of SQL int4 range column
type ColumnInt4Range jet.ColumnRange[jet.Int4Expression]
// Int4RangeColumn creates named range with range column
var Int4RangeColumn = jet.RangeColumn[jet.Int4Expression]
// ColumnInt8Range is interface of SQL int8 range column
type ColumnInt8Range jet.ColumnRange[jet.Int8Expression]
// Int8RangeColumn creates named range with range column
var Int8RangeColumn = jet.RangeColumn[jet.Int8Expression]
//------------------------------------------------------//
// ColumnInterval is interface of PostgreSQL interval columns.
type ColumnInterval interface {
IntervalExpression
jet.Column
From(subQuery SelectTable) ColumnInterval
}
type intervalColumnImpl struct {
jet.ColumnExpressionImpl
intervalInterfaceImpl
}
func (i *intervalColumnImpl) From(subQuery SelectTable) ColumnInterval {
newIntervalColumn := IntervalColumn(i.Name())
jet.SetTableName(newIntervalColumn, i.TableName())
jet.SetSubQuery(newIntervalColumn, subQuery)
return newIntervalColumn
}
// IntervalColumn creates named interval column.
func IntervalColumn(name string) ColumnInterval {
intervalColumn := &intervalColumnImpl{}
intervalColumn.ColumnExpressionImpl = jet.NewColumnImpl(name, "", intervalColumn)
intervalColumn.intervalInterfaceImpl.parent = intervalColumn
return intervalColumn
}