Type size and precision
Type size
The "size" is often required for SQL types like:
CHAR(size)
VARCHAR(size)
VARCHAR2(size)
NVARCHAR(size)
BINARY(size)
VARBINARY(size)
This is how the size value is determined:
if the attribute has a "@DbType" annotation this database type will be used "as is" regardless of the target database Example:
name : string {
@DbType('VARCHAR(20)')
}
the SQL type will beVARCHAR(20)
else if the attribute has a "@Size" annotation this value will be used Example:
name : string {
@Size(20)
}
the SQL type will be -VARCHAR(20)
for PostgreSQL -VARCHAR2(20)
for Oracleelse if the attribute has a "@MaxLen" annotation this value will be used Example:
name : string {
@MaxLen(12)
}
the SQL type will be -VARCHAR(12)
for PostgreSQL -VARCHAR2(12)
for Oracleelse if the size is not mandatory ("%s") for the SQL type then the type is generated without size, for example: -
VARCHAR
for PostgreSQLelse size is mandatory ("%S") and cannot be determined: an error is thrown
Reminder: "@DbSize(xx)" annotation is deprecated (do not use it)
Type precision
The "precision" is often required (or indispensable) for SQL types like:
NUMERIC(precision)
NUMBER(precision)
DECIMAL(precision)
FLOAT(precision)
The "precision" defines the number of digits for a decimal type, it can contains a "scale" (number of digits after the decimal).
Examples:
"10" : precision = 10 digits
"8,2" : precision = 8 digits with 2 digits after the decimal (scale = 2)
This is how the precision value is determined:
if the attribute has a "@DbType" annotation this database type will be used "as is" regardless of the target database Example:
weight : decimal {
@DbType('DECIMAL(5,2)')
}
the SQL type will beDECIMAL(5,2)
else if the attribute has a "@Size" annotation this value will be used Example:
weight: decimal {
@Size(8,5)
}
the SQL type will be - numeric(8,5) for PostgreSQL - NUMBER(8,5) for Oracleelse if the attribute has a "@MaxLen" annotation this value will be used Example:
weight : decimal {
@MaxLen(12)
}
the SQL type will be -numeric(12)
for PostgreSQL -NUMBER(12)
for Oracleelse if the precision is not mandatory ("%p") for the SQL type then the type is generated without precision, for example: -
numeric
for PostgreSQL -NUMBER
for Oracleelse precision is mandatory ("%P") and cannot be determined: an error is thrown
Reminder: "@DbSize(xx)" annotation is deprecated (do not use it)
Last updated