Building Tables

Define data models and tables in qqq

Overview

Tables are the foundation of qqq applications. They define your data models, fields, relationships, and behaviors.

Defining a Table

Tables in qqq are defined using Java classes with annotations:

Java
@QTableMetaData(name = "order", label = "Orders")
public class OrderTable implements TableMetaDataProducer {
    @Override
    public QTableMetaData produce(QInstance qInstance) {
        return new QTableMetaData()
            .withName("order")
            .withLabel("Orders")
            .withBackendName("rdbms")
            .withPrimaryKeyField("id")
            .withFields(defineFields());
    }
}

Field Types

qqq supports these field types:

TypeDescriptionJava Type
STRINGText valuesString
INTEGERWhole numbersInteger
DECIMALDecimal numbersBigDecimal
BOOLEANTrue/falseBoolean
DATEDate onlyLocalDate
DATE_TIMEDate and timeInstant
BLOBBinary databyte[]

Relationships

Define relationships between tables using associations:

Java
.withAssociation(new Association()
    .withName("lineItems")
    .withAssociatedTableName("orderLineItem")
    .withJoinName("orderLineItemJoin"))

Validation

Add field-level validation:

Java
new QFieldMetaData("email", QFieldType.STRING)
    .withIsRequired(true)
    .withMaxLength(255)
    .withFieldBehavior(new EmailFieldBehavior())

Next Steps

  • Building Processes - Add business logic
  • qctl Commands - Generate table scaffolding
  • Powered by qqq