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:
| Type | Description | Java Type |
|---|---|---|
| STRING | Text values | String |
| INTEGER | Whole numbers | Integer |
| DECIMAL | Decimal numbers | BigDecimal |
| BOOLEAN | True/false | Boolean |
| DATE | Date only | LocalDate |
| DATE_TIME | Date and time | Instant |
| BLOB | Binary data | byte[] |
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())