Telosys doc
WebsiteTwitterLinkedInNews
  • Telosys documentation
  • Telosys CLI
    • Installation on Linux
    • Installation on Windows
    • CLI configuration
    • CLI commands
    • Getting started
  • Telosys with VSCode
    • Extension installation
    • VSCode settings
    • Telosys terminal in VSCode
    • Telosys editor configuration
  • Telosys with JetBrains IDE
  • Project configuration
  • Project variables
  • Project databases
  • Models and entities
    • Model structure
    • Entity
    • Attribute / Link
    • Annotations
    • Tags
    • Examples
    • Model creation
    • Model installation
    • Models management
  • Bundles of templates
    • Bundle structure
    • Bundle creation
    • Bundles installation
    • Bundles management
    • Velocity language
    • Velocity directives
    • Velocity object types
    • Telosys directives
    • Telosys variables
    • Telosys objects
    • Code snippets
  • Code generation
    • "gen" command
    • "genb" command
  • Target languages
    • C++
    • C#
    • Golang
    • Java
    • JavaScript
    • Kotlin
    • PHP
    • Python
    • Scala
    • TypeScript
  • Target databases (SQL)
    • Predefined rules
    • Specific rules
    • Type size and precision
  • Telosys with Git
    • GitHub usage
    • Install with Git
    • Publish with Git
  • Support the project
  • How to contribute
  • Sponsors
  • IDE and editors
  • Telosys 3 Eclipse plugin
    • Eclipse plugin installation
    • Eclipse customization
    • Telosys 3 database model
Powered by GitBook
On this page
  • Type size
  • Type precision
  1. Target databases (SQL)

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:

  1. 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 be VARCHAR(20)

  2. 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 Oracle

  3. else 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 Oracle

  4. else if the size is not mandatory ("%s") for the SQL type then the type is generated without size, for example: - VARCHAR for PostgreSQL

  5. else 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:

  1. 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 be DECIMAL(5,2)

  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 Oracle

  3. else 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 Oracle

  4. else 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 Oracle

  5. else precision is mandatory ("%P") and cannot be determined: an error is thrown

Reminder: "@DbSize(xx)" annotation is deprecated (do not use it)

PreviousSpecific rulesNextTelosys with Git

Last updated 2 years ago