Rename of types and errors.

This commit is contained in:
go-jet 2019-07-08 13:00:44 +02:00
parent 18bbf1b5fb
commit 63f2d04651
30 changed files with 142 additions and 238 deletions

View file

@ -13,7 +13,7 @@ Jet sql builder supports following expression types:
_This list might be extended with feature Jet releases._
### Literal type
### Literal Types
For every expression type there is a method to create one expression literal type .
Literal type examples:
@ -32,7 +32,7 @@ jet.NULL
jet.STAR (alias for *)
```
### Column types
### Column Types
Every sql builder table column belongs to one expression type. There are following column types:
```
jet.ColumnBool
@ -62,7 +62,7 @@ jet.Int(11).LIKE(jet.Float(22.2)) // integer expressions doesn't have LIKE
```
## Comparision operators
## Comparision Operators
Jet supports following comparison operators for all expression types:
@ -80,7 +80,7 @@ Jet supports following comparison operators for all expression types:
*Left-hand side and right-hand side of operators have to be of the same type*
## Arithmetic operators
## Arithmetic Operators
Following arithmetic operators are supported for integer and float expressions.
If the first argument is float expression, second argument can be integer or float expression.
@ -96,7 +96,7 @@ If the first argument is integer expression second argument can only be integer
| POW | jet.Float(10.01).POW(table.Film.Length) | 10.01 ^ film.length |
## Bit operators
## Bit Operators
Following operators are only available on integer expressions:
@ -110,7 +110,7 @@ Following operators are only available on integer expressions:
| BIT_SHIFT_RIGHT | jet.Int(11).BIT_SHIFT_RIGHT(table.Film.Length) | 11 >> film.length |
## Logical operators
## Logical Operators
Following operators are only available on boolean expressions:
@ -124,7 +124,7 @@ Following operators are only available on boolean expressions:
| IS_NOT_UNKNOWN | table.Staff.Active.IS_NOT_UNKNOWN() | staff.active IS NOT UNKNOWN |
## String operators
## String Operators
Following operators are only available on string expressions:
@ -137,27 +137,56 @@ Following operators are only available on string expressions:
| NOT_SIMILAR_TO | table.Film.Name.NOT_SIMILAR_TO(String("%Wind%")) | staff.active NOT SIMILAR TO %Wind% |
## SQL Cast operators
## SQL Cast Operators
Cast operators allow expressions to be casted to some other database type.
SQL builder expression type changes accordingly to database type.
| Method | Example | Generated sql |
| ------------------------------ | -------------------------------------------|---------------------------- |
| TO_BOOL | table.Film.Description.TO_BOOL() | film.description::boolean |
| TO_SMALLINT | table.Film.Description.TO_SMALLINT() | film.description::smallint |
| TO_INTEGER | table.Film.Description.TO_INTEGER() | film.description::integer |
| TO_BIGINT | table.Film.Description.TO_BIGINT() | film.description::bigint |
| TO_NUMERIC | table.Film.Description.TO_NUMERIC(10, 6) | film.description::numeric(10,6) |
| TO_REAL | table.Film.Description.TO_REAL() | film.description::real |
| TO_DOUBLE | table.Film.Description.TO_DOUBLE() | film.description::double |
| TO_TEXT | table.Film.Description.TO_TEXT() | film.description::text |
| TO_DATE | table.Film.Description.TO_DATE() | film.description::date |
| TO_TIME | table.Film.Description.TO_TIME() | film.description::time |
| TO_TIMEZ | table.Film.Description.TO_TIMEZ() | film.description::timez |
| TO_TIMESTAMP | table.Film.Description.TO_TIMESTAMP() | film.description::timestamp |
| TO_TIMESTAMPZ | table.Film.Description.TO_TIMESTAMPZ() | film.description::timestampz |
| Method | Example | Generated sql |
| ------------------------------ | ----------------------------------------------- | --------------------------------------------- |
| CAST(exp).AS_BOOL() | CAST(table.Film.Description).AS_BOOL() | film.description::boolean |
| CAST(exp).AS_SMALLINT() | CAST(table.Film.Description).AS_SMALLINT() | film.description::smallint |
| CAST(exp).AS_INTEGER() | CAST(table.Film.Description).AS_INTEGER() | film.description::integer |
| CAST(exp).AS_BIGINT() | CAST(table.Film.Description).AS_BIGINT() | film.description::bigint |
| CAST(exp).AS_NUMERIC() | CAST(table.Film.Description).AS_NUMERIC(10, 6) | film.description::numeric(10,6) |
| CAST(exp).AS_REAL() | CAST(table.Film.Description).AS_REAL() | film.description::real |
| CAST(exp).AS_DOUBLE() | CAST(table.Film.Description).AS_DOUBLE() | film.description::double |
| CAST(exp).AS_TEXT() | CAST(table.Film.Description).AS_TEXT() | film.description::text |
| CAST(exp).AS_DATE() | CAST(table.Film.Description).AS_DATE() | film.description::date |
| CAST(exp).AS_TIME() | CAST(table.Film.Description).AS_TIME() | film.description::time without time zone |
| CAST(exp).AS_TIMEZ() | CAST(table.Film.Description).AS_TIMEZ() | film.description::time with time zone |
| CAST(exp).AS_TIMESTAMP() | CAST(table.Film.Description).AS_TIMESTAMP() | film.description::timestamp without time zone |
| CAST(exp).AS_TIMESTAMPZ() | CAST(table.Film.Description).AS_TIMESTAMPZ() | film.description::timestamp with time zone |
## SQL builder cast
## SQL Builder Cast Wrapper
TODO:
For some expressions sql builder can't deduce expression type directly. For instance scalar sub-query:
```
( SELECT(MAXf(Film.RentalRate)).
FROM(Film) ).LT(Float(11.1))
```
This expression would not compile, because sub-query, although calculates one scalar float value, it is not a float expression.
To fix this sub-query can be cast to some float type, or just wrapped as float expression:
```
FloatExp( SELECT(MAXf(Film.RentalRate)).
FROM(Film) ).LT(Float(11.1))
```
There are wrappers for all supported types:
```
- BoolExp(exp)
- IntExp(exp)
- FloatExp(exp)
- StringExp(exp)
- DateExp(exp)
- TimeExp(exp)
- TimezExp(exp)
- TimestampExp(exp)
- TimestampzExp(exp)
```
**Cast wrapper does NOT inject cast operator to generated SQL.**
## RAW Operator
There is a RAW operator expression, that accepts raw sql as a string. It can be used for any unsupported functions, operators or expressions.
For example:
```RAW("current_database()")``` _can be cast or wrapped, as needed._