Data Model

Data models a.k.a domain models are the set of entities of your application and also their relations. In Dirigible, we also use the term data structures, which is more related to the actual artifact - the data descriptor.

Let’s create the first model entity of the BookStore sample - the books table.

Develop

  1. Select the DataStructures sub-folder of a project and open the pop-up menu using right-click.
  2. From the menu, choose New -> Data Structure.

    New DataStructures Menu

    The first page of this wizard lets you choose among several artifacts related to the domain model. In this case, you need a table to store the books metadata, such as ISBN, Title, Author, etc.

  3. Choose Database Table and click Next.
  4. Use the Add/Remove buttons to create the actual table layout.

    New DataStructures Wizard 2

    1
    2
    3
    4
    5
    6
    7
    8
    9
     BOOK_ID                 INTEGER         not null    primaryKey
     BOOK_ISBN               CHAR        13  not null
     BOOK_TITLE              VARCHAR     200 not null
     BOOK_AUTHOR             VARCHAR     100 not null
     BOOK_EDITOR             VARCHAR     100
     BOOK_PUBLISHER          VARCHAR     100
     BOOK_FORMAT             VARCHAR     100
     BOOK_PUBLICATION_DATE   DATE
     BOOK_PRICE              DOUBLE          not null
    

    New DataStructures Wizard 3

  5. After adding all colums click Next.
  6. Enter the table’s name and click Finish.

    New DataStructures Wizard 4

  7. The table descriptor should be generated based on your input, and the file itself should be opened in the editor’s area.

    New DataStructures Content

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
         {
           "tableName": "BOOKS",
           "columns": 
             [
               {
                 "name": "BOOK_ID",
                 "type": "INTEGER",
                 "length": "0",
                 "notNull": "true",
                 "primaryKey": "true",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_ISBN",
                 "type": "CHAR",
                 "length": "13",
                 "notNull": "true",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_TITLE",
                 "type": "VARCHAR",
                 "length": "200",
                 "notNull": "true",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_AUTHOR",
                 "type": "VARCHAR",
                 "length": "100",
                 "notNull": "true",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_EDITOR",
                 "type": "VARCHAR",
                 "length": "100",
                 "notNull": "false",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_PUBLISHER",
                 "type": "VARCHAR",
                 "length": "100",
                 "notNull": "false",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_FORMAT",
                 "type": "VARCHAR",
                 "length": "100",
                 "notNull": "false",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_PUBLICATION_DATE",
                 "type": "DATE",
                 "length": "0",
                 "notNull": "false",
                 "primaryKey": "false",
                 "defaultValue": ""
               }, {
                 "name": "BOOK_PRICE",
                 "type": "DOUBLE",
                 "length": "0",
                 "notNull": "true",
                 "primaryKey": "false",
                 "defaultValue": ""
               }
             ]
         }
    	
    

    For more information about data structure types and their descriptors, see Data Structures. Now, you have to create the real database artifact in the underlying database.

  8. Choose the Publish action from the project’s popup menu.

    New DataStructures Publish

    Once you have published the project successfully, you can go to the Database perspective to double check the table definition.

Discover

To discover all available database tables, you can go to the Database Perspective.

  1. From the main menu, go to Window -> Show Perspective -> Database.
  2. Open the database schema node and find the BOOKS table.
  3. Right-click and choose Open Table Definition. This will open the Table Definition Viewer.

    Table Definition

Edit