^ Tag <dto-class...
| 1 |
<dto-class name="Product" ref="products"/> <!-- DTO --> <dto-class name="sa-Product" ref="products"/> <!-- Model --> |
The value of 'ref' specifies the name of a data table or view. |
| 2 |
<dto-class name="ProductDetails" ref="product_details.sql"/> <dto-class name="ProductDetails" ref="select * from product_details(?)"/> |
The value of 'ref' specifies an SQL statement that returns a ResultSet. |
| 3 |
<dto-class name="Pair" ref="">
<field type="int64" column="id"/>
<field type="string" column="name"/>
</dto-class> |
The value of 'ref' is empty. All the fields must be defined manually. |
Notes for (1) and (2):
- The code generator obtains information about DTO fields from JDBC metadata.
-
This is how to redefine auto-detected field types:
<dto-class name="Order" ref="get_orders.sql"> <field type="int64" column="positions_count"/> </dto-class> -
This is how to add more fields to the auto-detected set:
<dto-class name="Product" ref="products"> <field type="int64" column="amount_of_sales"/> <field type="float64" column="sum_of_sales"/> </dto-class> -
Use type="-" to exclude fields from the auto-detected set:
<dto-class name="sa-TaskLI" ref="tasks"> <field column="t_comments" type="-"/> </dto-class>
The attributes "pk" and "auto" cover the awkward cases of the CRUD scenario: 1) the data table has no primary key (PK); 2) auto-generated, auto-incremented, or serial columns cannot be detected.
<dto-class name="Group" ref="groups" pk="g_id" auto="g_id"/>
- The value '*' for 'pk' instructs the code generator to detect the PK via JDBC. If it doesn't work, you may need pk="g_id".
- The value '*' for 'auto' instructs the code generator to detect auto-columns via JDBC. If it doesn't work, you may need auto="g_id".
- The defaults are '*' for both 'pk' and 'auto'.
- Auto-columns are not included in the generated INSERT statement. If 'groups' consists of ['id', 'no', 'name'] and 'id' is an auto-column, the generated SQL is 'insert into groups (no, name) values (?, ?)'.
- An empty value for 'auto' instructs the code generator to ignore auto-columns while building the SQL. With auto="", the generated SQL is 'insert into groups (id, no, name) values (?, ?, ?)'.
Try the plug-in GUI > tab 'DTO' > local toolbar > 'Fields Definition Assistant'.
^ Tag <header...
This is how to specify comments, code-docs, and options for the entire DTO class:
<dto-class name="sa-TaskLI" ref="tasks">
<header><![CDATA[ """
Task list item
"""
__table_args__ = {'extend_existing': True}]]></header>
</dto-class>
class TaskLi(Base):
"""
Task list item
"""
__table_args__ = {'extend_existing': True}
__tablename__ = 'tasks'
t_id = Column('t_id', Integer, primary_key=True, autoincrement=True)
p_id = Column('p_id', Integer)
t_date = Column('t_date', DateTime)
t_subject = Column('t_subject', String(256))
t_priority = Column('t_priority', Integer)
^ Tag <custom...
(Go only, so far)
<dto-class name="gorm-Department" ref="departments" auto="id">
<custom>
{base} app/dbal/thread:thread.BaseModel
ID // PK
InstitutionID // FK column
Institution Institution `gorm:"foreignKey:InstitutionID"` // FK
</custom>
</dto-class>
import (
"github.com/google/uuid"
"app/dbal/thread"
)
type Department struct {
thread.BaseModel
ID uuid.UUID `json:"id" gorm:"column:id;primary_key;type:uuid;default:gen_random_uuid()"` // PK
Name string `json:"name" gorm:"column:name"`
InstitutionID uuid.UUID `json:"institution_id" gorm:"column:institution_id;type:uuid"` // FK column
Institution Institution `gorm:"foreignKey:InstitutionID"` // FK
}