diff --git a/examples/quick-start/quick-start.go b/examples/quick-start/quick-start.go index cabbb5c..b10906b 100644 --- a/examples/quick-start/quick-start.go +++ b/examples/quick-start/quick-start.go @@ -16,16 +16,16 @@ import ( ) const ( - Host = "localhost" - Port = 5432 - User = "jet" - Password = "jet" - DBName = "jetdb" + host = "localhost" + port = 5432 + user = "jet" + password = "jet" + dbName = "jetdb" ) func main() { // Connect to database - var connectString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", Host, Port, User, Password, DBName) + var connectString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbName) db, err := sql.Open("postgres", connectString) panicOnError(err) diff --git a/internal/jet/column.go b/internal/jet/column.go index 3e4c373..8707247 100644 --- a/internal/jet/column.go +++ b/internal/jet/column.go @@ -98,6 +98,8 @@ func (c columnImpl) serialize(statement StatementType, out *SqlBuilder, options //------------------------------------------------------// +// IColumnList is used to store list of columns for later reuse as single projection or +// column list for UPDATE and INSERT statement. type IColumnList interface { Projection Column @@ -105,6 +107,7 @@ type IColumnList interface { columns() []ColumnExpression } +// ColumnList function returns list of columns that be used as projection or column list for UPDATE and INSERT statement. func ColumnList(columns ...ColumnExpression) IColumnList { return columnListImpl(columns) } diff --git a/internal/jet/date_expression.go b/internal/jet/date_expression.go index 0c2b0ed..357e8a5 100644 --- a/internal/jet/date_expression.go +++ b/internal/jet/date_expression.go @@ -1,6 +1,6 @@ package jet -// DateExpression is interface for all SQL date expressions. +// DateExpression is interface for date types type DateExpression interface { Expression diff --git a/internal/jet/literal_expression.go b/internal/jet/literal_expression.go index 5516572..fc8117b 100644 --- a/internal/jet/literal_expression.go +++ b/internal/jet/literal_expression.go @@ -60,7 +60,7 @@ type integerLiteralExpression struct { integerInterfaceImpl } -// Int is constructor for integer expressions literals. +// Int creates new integer literal func Int(value int64) IntegerExpression { numLiteral := &integerLiteralExpression{} @@ -94,7 +94,7 @@ type floatLiteral struct { literalExpressionImpl } -// Float creates new float literal expression +// Float creates new float literal func Float(value float64) FloatExpression { floatLiteral := floatLiteral{} floatLiteral.literalExpressionImpl = *literal(value) @@ -139,6 +139,7 @@ func Time(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression return timeLiteral } +// TimeT creates new time literal expression from time.Time object func TimeT(t time.Time) TimeExpression { timeLiteral := &timeLiteral{} timeLiteral.literalExpressionImpl = *literal(t) @@ -165,6 +166,7 @@ func Timez(hour, minute, second int, nanoseconds time.Duration, timezone string) return TimezExp(literal(timeStr)) } +// TimezT creates new time with time zone literal expression from time.Time object func TimezT(t time.Time) TimezExpression { timeLiteral := &timezLiteral{} timeLiteral.literalExpressionImpl = *literal(t) @@ -190,6 +192,7 @@ func Timestamp(year int, month time.Month, day, hour, minute, second int, nanose return timestamp } +// TimestampT creates new timestamp literal expression from time.Time object func TimestampT(t time.Time) TimestampExpression { timestamp := ×tampLiteral{} timestamp.literalExpressionImpl = *literal(t) @@ -204,7 +207,7 @@ type timestampzLiteral struct { literalExpressionImpl } -// Timestamp creates new timestamp literal expression +// Timestampz creates new timestamp with time zone literal expression func Timestampz(year int, month time.Month, day, hour, minute, second int, nanoseconds time.Duration, timezone string) TimestampzExpression { timestamp := ×tampzLiteral{} timeStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second) @@ -216,6 +219,7 @@ func Timestampz(year int, month time.Month, day, hour, minute, second int, nanos return timestamp } +// TimestampzT creates new timestamp literal expression from time.Time object func TimestampzT(t time.Time) TimestampzExpression { timestamp := ×tampzLiteral{} timestamp.literalExpressionImpl = *literal(t) @@ -230,7 +234,7 @@ type dateLiteral struct { literalExpressionImpl } -//Date creates new date expression +// Date creates new date literal expression func Date(year int, month time.Month, day int) DateExpression { dateLiteral := &dateLiteral{} @@ -241,6 +245,7 @@ func Date(year int, month time.Month, day int) DateExpression { return dateLiteral } +// DateT creates new date literal expression from time.Time object func DateT(t time.Time) DateExpression { dateLiteral := &dateLiteral{} dateLiteral.literalExpressionImpl = *literal(t) diff --git a/internal/jet/timez_expression.go b/internal/jet/timez_expression.go index 20c3d6d..0189d3d 100644 --- a/internal/jet/timez_expression.go +++ b/internal/jet/timez_expression.go @@ -1,6 +1,6 @@ package jet -// TimezExpression interface 'time with time zone' +// TimezExpression interface for 'time with time zone' types type TimezExpression interface { Expression diff --git a/postgres/cast.go b/postgres/cast.go index f3e7ee0..e9ec209 100644 --- a/postgres/cast.go +++ b/postgres/cast.go @@ -46,6 +46,7 @@ type castImpl struct { jet.Cast } +// CAST function converts a expr (of any type) into latter specified datatype. func CAST(expr Expression) cast { castImpl := &castImpl{} @@ -54,14 +55,17 @@ func CAST(expr Expression) cast { return castImpl } +// Cast expression as castType func (b *castImpl) AS(castType string) Expression { return b.Cast.AS(castType) } +// Cast expression as bool type func (b *castImpl) AS_BOOL() BoolExpression { return BoolExp(b.AS("boolean")) } +// Cast expression as smallint type func (b *castImpl) AS_SMALLINT() IntegerExpression { return IntExp(b.AS("smallint")) } diff --git a/postgres/clauses.go b/postgres/clauses.go index b616ad5..f3cf9bd 100644 --- a/postgres/clauses.go +++ b/postgres/clauses.go @@ -4,11 +4,11 @@ import ( "github.com/go-jet/jet/internal/jet" ) -type ClauseReturning struct { +type clauseReturning struct { Projections []jet.Projection } -func (r *ClauseReturning) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) { +func (r *clauseReturning) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) { if len(r.Projections) == 0 { return } diff --git a/postgres/columns.go b/postgres/columns.go index fb6722a..d02d05c 100644 --- a/postgres/columns.go +++ b/postgres/columns.go @@ -2,44 +2,67 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// Column is common column interface for all types of columns. 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 +// 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 +// 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 +// StringColumn creates named string column. var StringColumn = jet.StringColumn +// ColumnInteger is interface for SQL smallint, integer, bigint columns. 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 +// FloatColumn creates named float column. var FloatColumn = jet.FloatColumn +// ColumnDate is interface of SQL date columns. type ColumnDate jet.ColumnDate +// DateColumn creates named date column. var DateColumn = jet.DateColumn +// ColumnTime is interface for SQL time column. 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 +// TimezColumn creates named time with time zone column. var TimezColumn = jet.TimezColumn +// ColumnTimestamp is interface of SQL timestamp columns. 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 +// TimestampzColumn creates named timestamp with time zone column. var TimestampzColumn = jet.TimestampzColumn diff --git a/postgres/delete_statement.go b/postgres/delete_statement.go index 5808dd5..7f636ce 100644 --- a/postgres/delete_statement.go +++ b/postgres/delete_statement.go @@ -2,6 +2,7 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// DeleteStatement is interface for PostgreSQL DELETE statement type DeleteStatement interface { Statement @@ -15,7 +16,7 @@ type deleteStatementImpl struct { Delete jet.ClauseStatementBegin Where jet.ClauseWhere - Returning ClauseReturning + Returning clauseReturning } func newDeleteStatement(table WritableTable) DeleteStatement { diff --git a/postgres/dialect.go b/postgres/dialect.go index 8de68b8..0ba8c2c 100644 --- a/postgres/dialect.go +++ b/postgres/dialect.go @@ -5,9 +5,10 @@ import ( "strconv" ) -var Dialect = NewDialect() +// Dialect is implementation of postgres dialect for SQL Builder serialisation. +var Dialect = newDialect() -func NewDialect() jet.Dialect { +func newDialect() jet.Dialect { operatorSerializeOverrides := map[string]jet.SerializeOverride{} operatorSerializeOverrides[jet.StringRegexpLikeOperator] = postgres_REGEXP_LIKE_operator diff --git a/postgres/expressions.go b/postgres/expressions.go index 0333a0d..3148ea1 100644 --- a/postgres/expressions.go +++ b/postgres/expressions.go @@ -2,36 +2,85 @@ package postgres 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 +// BoolExpression interface type BoolExpression jet.BoolExpression +// StringExpression interface type StringExpression jet.StringExpression +// IntegerExpression interface type IntegerExpression jet.IntegerExpression +//FloatExpression is interface type FloatExpression jet.FloatExpression +// TimeExpression interface type TimeExpression jet.TimeExpression +// TimezExpression interface for 'time with time zone' types type TimezExpression jet.TimezExpression +// DateExpression is interface for date types type DateExpression jet.DateExpression +// TimestampExpression interface type TimestampExpression jet.TimestampExpression +// TimestampzExpression interface type TimestampzExpression jet.TimestampzExpression +// BoolExp is bool expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as bool expression. +// Does not add sql cast to generated sql builder output. var BoolExp = jet.BoolExp + +// IntExp is int expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as int expression. +// Does not add sql cast to generated sql builder output. var IntExp = jet.IntExp + +// FloatExp is date expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as float expression. +// Does not add sql cast to generated sql builder output. var FloatExp = jet.FloatExp + +// TimeExp is time expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as time expression. +// Does not add sql cast to generated sql builder output. var TimeExp = jet.TimeExp + +// StringExp is string expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as string expression. +// Does not add sql cast to generated sql builder output. var StringExp = jet.StringExp + +// TimezExp is time with time zone expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as time with time zone expression. +// Does not add sql cast to generated sql builder output. var TimezExp = jet.TimezExp + +// DateExp is date expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as date expression. +// Does not add sql cast to generated sql builder output. var DateExp = jet.DateExp + +// TimestampExp is timestamp expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as timestamp expression. +// Does not add sql cast to generated sql builder output. var TimestampExp = jet.TimestampExp + +// TimestampzExp is timestamp with time zone expression wrapper around arbitrary expression. +// Allows go compiler to see any expression as timestamp with time zone expression. +// Does not add sql cast to generated sql builder output. var TimestampzExp = jet.TimestampzExp +// Raw can be used for any unsupported functions, operators or expressions. +// For example: Raw("current_database()") var Raw = jet.Raw +// NewEnumValue creates new named enum value var NewEnumValue = jet.NewEnumValue diff --git a/postgres/functions.go b/postgres/functions.go index fafb16a..18a637f 100644 --- a/postgres/functions.go +++ b/postgres/functions.go @@ -2,108 +2,260 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// ROW is construct one table row from list of expressions. var ROW = jet.ROW // ------------------ Mathematical functions ---------------// +// ABSf calculates absolute value from float expression var ABSf = jet.ABSf + +// ABSi calculates absolute value from int expression var ABSi = jet.ABSi + +// POW calculates power of base with exponent var POW = jet.POW + +// POWER calculates power of base with exponent var POWER = jet.POWER + +// SQRT calculates square root of numeric expression var SQRT = jet.SQRT + +// CBRT calculates cube root of numeric expression var CBRT = jet.CBRT + +// CEIL calculates ceil of float expression var CEIL = jet.CEIL + +// FLOOR calculates floor of float expression var FLOOR = jet.FLOOR + +// ROUND calculates round of a float expressions with optional precision var ROUND = jet.ROUND + +// SIGN returns sign of float expression var SIGN = jet.SIGN + +// TRUNC calculates trunc of float expression with optional precision var TRUNC = jet.TRUNC + +// LN calculates natural algorithm of float expression var LN = jet.LN + +// LOG calculates logarithm of float expression var LOG = jet.LOG // ----------------- Aggregate functions -------------------// +// AVG is aggregate function used to calculate avg value from numeric expression var AVG = jet.AVG + +// BIT_AND is aggregate function used to calculates the bitwise AND of all non-null input values, or null if none. var BIT_AND = jet.BIT_AND + +// BIT_OR is aggregate function used to calculates the bitwise OR of all non-null input values, or null if none. var BIT_OR = jet.BIT_OR + +// BOOL_AND is aggregate function. Returns true if all input values are true, otherwise false var BOOL_AND = jet.BOOL_AND + +// BOOL_OR is aggregate function. Returns true if at least one input value is true, otherwise false var BOOL_OR = jet.BOOL_OR + +// COUNT is aggregate function. Returns number of input rows for which the value of expression is not null. var COUNT = jet.COUNT + +// EVERY is aggregate function. Returns true if all input values are true, otherwise false var EVERY = jet.EVERY + +// MAXf is aggregate function. Returns maximum value of float expression across all input values var MAXf = jet.MAXf + +// MAXi is aggregate function. Returns maximum value of int expression across all input values var MAXi = jet.MAXi + +// MINf is aggregate function. Returns minimum value of float expression across all input values var MINf = jet.MINf + +// MINi is aggregate function. Returns minimum value of int expression across all input values var MINi = jet.MINi + +// SUMf is aggregate function. Returns sum of expression across all float expressions var SUMf = jet.SUMf + +// SUMi is aggregate function. Returns sum of expression across all integer expression. var SUMi = jet.SUMi //--------------------- String functions ------------------// +// BIT_LENGTH returns number of bits in string expression var BIT_LENGTH = jet.BIT_LENGTH + +// CHAR_LENGTH returns number of characters in string expression var CHAR_LENGTH = jet.CHAR_LENGTH + +// OCTET_LENGTH returns number of bytes in string expression var OCTET_LENGTH = jet.OCTET_LENGTH + +// LOWER returns string expression in lower case var LOWER = jet.LOWER + +// UPPER returns string expression in upper case var UPPER = jet.UPPER + +// BTRIM removes the longest string consisting only of characters +// in characters (a space by default) from the start and end of string var BTRIM = jet.BTRIM + +// LTRIM removes the longest string containing only characters +// from characters (a space by default) from the start of string var LTRIM = jet.LTRIM + +// RTRIM removes the longest string containing only characters +// from characters (a space by default) from the end of string var RTRIM = jet.RTRIM + +// CHR returns character with the given code. var CHR = jet.CHR +// CONCAT adds two or more expressions together var CONCAT = func(expressions ...Expression) StringExpression { return jet.CONCAT(explicitLiteralCasts(expressions...)...) } +// CONCAT_WS adds two or more expressions together with a separator. func CONCAT_WS(separator Expression, expressions ...Expression) StringExpression { return jet.CONCAT_WS(explicitLiteralCast(separator), explicitLiteralCasts(expressions...)...) } +// CONVERT converts string to dest_encoding. The original encoding is +// specified by src_encoding. The string must be valid in this encoding. var CONVERT = jet.CONVERT + +// CONVERT_FROM converts string to the database encoding. The original +// encoding is specified by src_encoding. The string must be valid in this encoding. var CONVERT_FROM = jet.CONVERT_FROM + +// CONVERT_TO converts string to dest_encoding. var CONVERT_TO = jet.CONVERT_TO + +// ENCODE encodes binary data into a textual representation. +// Supported formats are: base64, hex, escape. escape converts zero bytes and +// high-bit-set bytes to octal sequences (\nnn) and doubles backslashes. var ENCODE = jet.ENCODE + +// DECODE decodes binary data from textual representation in string. +// Options for format are same as in encode. var DECODE = jet.DECODE +// FORMAT formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places, then it returns the result as a string. func FORMAT(formatStr StringExpression, formatArgs ...Expression) StringExpression { return jet.FORMAT(formatStr, explicitLiteralCasts(formatArgs...)...) } +// INITCAP converts the first letter of each word to upper case +// and the rest to lower case. Words are sequences of alphanumeric +// characters separated by non-alphanumeric characters. var INITCAP = jet.INITCAP + +// LEFT returns first n characters in the string. +// When n is negative, return all but last |n| characters. var LEFT = jet.LEFT + +// RIGHT returns last n characters in the string. +// When n is negative, return all but first |n| characters. var RIGHT = jet.RIGHT + +// LENGTH returns number of characters in string with a given encoding var LENGTH = jet.LENGTH + +// LPAD fills up the string to length length by prepending the characters +// fill (a space by default). If the string is already longer than length +// then it is truncated (on the right). var LPAD = jet.LPAD + +// RPAD fills up the string to length length by appending the characters +// fill (a space by default). If the string is already longer than length then it is truncated. var RPAD = jet.RPAD + +// MD5 calculates the MD5 hash of string, returning the result in hexadecimal var MD5 = jet.MD5 + +// REPEAT repeats string the specified number of times var REPEAT = jet.REPEAT + +// REPLACE replaces all occurrences in string of substring from with substring to var REPLACE = jet.REPLACE + +// REVERSE returns reversed string. var REVERSE = jet.REVERSE + +// STRPOS returns location of specified substring (same as position(substring in string), +// but note the reversed argument order) var STRPOS = jet.STRPOS + +// SUBSTR extracts substring var SUBSTR = jet.SUBSTR + +// TO_ASCII convert string to ASCII from another encoding var TO_ASCII = jet.TO_ASCII + +// TO_HEX converts number to its equivalent hexadecimal representation var TO_HEX = jet.TO_HEX //----------Data Type Formatting Functions ----------------------// +// TO_CHAR converts expression to string with format var TO_CHAR = jet.TO_CHAR + +// TO_DATE converts string to date using format var TO_DATE = jet.TO_DATE + +// TO_NUMBER converts string to numeric using format var TO_NUMBER = jet.TO_NUMBER + +// TO_TIMESTAMP converts string to time stamp with time zone using format var TO_TIMESTAMP = jet.TO_TIMESTAMP //----------------- Date/Time Functions and Operators ------------// +// CURRENT_DATE returns current date var CURRENT_DATE = jet.CURRENT_DATE + +// CURRENT_TIME returns current time with time zone var CURRENT_TIME = jet.CURRENT_TIME + +// CURRENT_TIMESTAMP returns current timestamp with time zone var CURRENT_TIMESTAMP = jet.CURRENT_TIMESTAMP + +// LOCALTIME returns local time of day using optional precision var LOCALTIME = jet.LOCALTIME + +// LOCALTIMESTAMP returns current date and time using optional precision var LOCALTIMESTAMP = jet.LOCALTIMESTAMP + +// NOW returns current date and time var NOW = jet.NOW // --------------- Conditional Expressions Functions -------------// +// COALESCE function returns the first of its arguments that is not null. var COALESCE = jet.COALESCE + +// NULLIF function returns a null value if value1 equals value2; otherwise it returns value1. var NULLIF = jet.NULLIF + +// GREATEST selects the largest value from a list of expressions var GREATEST = jet.GREATEST + +// LEAST selects the smallest value from a list of expressions var LEAST = jet.LEAST + +// EXISTS checks for existence of the rows in subQuery var EXISTS = jet.EXISTS + +// CASE create CASE operator with optional list of expressions var CASE = jet.CASE func explicitLiteralCasts(expressions ...Expression) []jet.Expression { diff --git a/postgres/insert_statement.go b/postgres/insert_statement.go index f43c3a1..f75dbea 100644 --- a/postgres/insert_statement.go +++ b/postgres/insert_statement.go @@ -35,7 +35,7 @@ type insertStatementImpl struct { Insert jet.ClauseInsert ValuesQuery jet.ClauseValuesQuery - Returning ClauseReturning + Returning clauseReturning } func (i *insertStatementImpl) VALUES(value interface{}, values ...interface{}) InsertStatement { diff --git a/postgres/literal.go b/postgres/literal.go index 4defa62..bf05acd 100644 --- a/postgres/literal.go +++ b/postgres/literal.go @@ -5,41 +5,69 @@ import ( "time" ) +// Bool creates new bool literal expression var Bool = jet.Bool + +// Int creates new integer literal expression var Int = jet.Int + +// Float creates new float literal expression var Float = jet.Float + +// String creates new string literal expression var String = jet.String +// Bytea craates new bytea literal expression var Bytea = func(value string) StringExpression { return CAST(jet.String(value)).AS_BYTEA() } + +// Date creates new date literal expression var Date = func(year int, month time.Month, day int) DateExpression { return CAST(jet.Date(year, month, day)).AS_DATE() } + +// DateT creates new date literal expression from time.Time object var DateT = func(t time.Time) DateExpression { return CAST(jet.DateT(t)).AS_DATE() } + +// Time creates new time literal expression var Time = func(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression { return CAST(jet.Time(hour, minute, second, nanoseconds...)).AS_TIME() } + +// TimeT creates new time literal expression from time.Time object var TimeT = func(t time.Time) TimeExpression { return CAST(jet.TimeT(t)).AS_TIME() } + +// Timez creates new time with time zone literal expression var Timez = func(hour, minute, second int, milliseconds time.Duration, timezone string) TimezExpression { return CAST(jet.Timez(hour, minute, second, milliseconds, timezone)).AS_TIMEZ() } + +// TimezT creates new time with time zone literal expression from time.Time object var TimezT = func(t time.Time) TimezExpression { return CAST(jet.TimezT(t)).AS_TIMEZ() } + +// Timestamp creates new timestamp literal expression var Timestamp = func(year int, month time.Month, day, hour, minute, second int, milliseconds ...time.Duration) TimestampExpression { return CAST(jet.Timestamp(year, month, day, hour, minute, second, milliseconds...)).AS_TIMESTAMP() } + +// TimestampT creates new timestamp literal expression from time.Time object var TimestampT = func(t time.Time) TimestampExpression { - return CAST(jet.TimestampzT(t)).AS_TIMESTAMP() + return CAST(jet.TimestampT(t)).AS_TIMESTAMP() } + +// Timestampz creates new timestamp with time zone literal expression var Timestampz = func(year int, month time.Month, day, hour, minute, second int, milliseconds time.Duration, timezone string) TimestampzExpression { return CAST(jet.Timestampz(year, month, day, hour, minute, second, milliseconds, timezone)).AS_TIMESTAMPZ() } + +// TimestampzT creates new timestamp literal expression from time.Time object var TimestampzT = func(t time.Time) TimestampzExpression { return CAST(jet.TimestampzT(t)).AS_TIMESTAMPZ() } diff --git a/postgres/lock_statement.go b/postgres/lock_statement.go index f46f2b7..87cad6e 100644 --- a/postgres/lock_statement.go +++ b/postgres/lock_statement.go @@ -2,6 +2,7 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// TableLockMode is a type of possible SQL table lock type TableLockMode string // Lock types for LockStatement. @@ -16,6 +17,7 @@ const ( LOCK_ACCESS_EXCLUSIVE TableLockMode = "ACCESS EXCLUSIVE" ) +// LockStatement is interface for MySQL LOCK tables type LockStatement interface { Statement @@ -23,6 +25,7 @@ type LockStatement interface { NOWAIT() LockStatement } +// LOCK creates LockStatement from list of tables func LOCK(tables ...jet.SerializerTable) LockStatement { newLock := &lockStatementImpl{} newLock.StatementImpl = jet.NewStatementImpl(Dialect, jet.LockStatementType, newLock, diff --git a/postgres/operators.go b/postgres/operators.go index 62ab2fd..30c40c2 100644 --- a/postgres/operators.go +++ b/postgres/operators.go @@ -2,5 +2,8 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// NOT returns negation of bool expression result var NOT = jet.NOT + +// BIT_NOT inverts every bit in integer expression result var BIT_NOT = jet.BIT_NOT diff --git a/postgres/select_statement.go b/postgres/select_statement.go index c34beeb..e922550 100644 --- a/postgres/select_statement.go +++ b/postgres/select_statement.go @@ -2,8 +2,10 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// RowLock is interface for SELECT statement row lock types type RowLock = jet.RowLock +// Row lock types var ( UPDATE = jet.NewSelectLock("UPDATE") NO_KEY_UPDATE = jet.NewSelectLock("NO KEY UPDATE") @@ -11,6 +13,7 @@ var ( KEY_SHARE = jet.NewSelectLock("KEY SHARE") ) +// SelectStatement is interface for PostgreSQL SELECT statement type SelectStatement interface { Statement jet.HasProjections diff --git a/postgres/table.go b/postgres/table.go index 58b7d85..2a4cc83 100644 --- a/postgres/table.go +++ b/postgres/table.go @@ -2,6 +2,13 @@ package postgres import "github.com/go-jet/jet/internal/jet" +// Table is interface for MySQL tables +type Table interface { + readableTable + writableTable + jet.SerializerTable +} + type readableTable interface { // Generates a select query on the current tableName. SELECT(projection Projection, projections ...Projection) SelectStatement @@ -35,18 +42,13 @@ type ReadableTable interface { jet.Serializer } +// WritableTable interface type WritableTable interface { jet.Table writableTable jet.Serializer } -type Table interface { - readableTable - writableTable - jet.SerializerTable -} - type readableTableInterfaceImpl struct { parent ReadableTable } @@ -106,6 +108,7 @@ type table2Impl struct { jet.TableImpl } +// NewTable creates new table with schema Name, table Name and list of columns func NewTable(schemaName, name string, columns ...jet.ColumnExpression) Table { t := &table2Impl{ diff --git a/postgres/types.go b/postgres/types.go index 20e5c4e..036e4f3 100644 --- a/postgres/types.go +++ b/postgres/types.go @@ -2,7 +2,10 @@ 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 + +// 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 { diff --git a/postgres/update_statement.go b/postgres/update_statement.go index f313e85..4fff979 100644 --- a/postgres/update_statement.go +++ b/postgres/update_statement.go @@ -19,9 +19,9 @@ type updateStatementImpl struct { jet.StatementImpl Update jet.ClauseUpdate - Set ClauseSet + Set clauseSet Where jet.ClauseWhere - Returning ClauseReturning + Returning clauseReturning } func newUpdateStatement(table WritableTable, columns []jet.Column) UpdateStatement { @@ -56,12 +56,12 @@ func (u *updateStatementImpl) RETURNING(projections ...jet.Projection) UpdateSta return u } -type ClauseSet struct { +type clauseSet struct { Columns []jet.Column Values []jet.Serializer } -func (s *ClauseSet) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) { +func (s *clauseSet) Serialize(statementType jet.StatementType, out *jet.SqlBuilder) { out.NewLine() out.WriteString("SET")