fix(bun): read extra fields from file

This commit is contained in:
Hermes Agent
2026-07-09 06:02:01 +02:00
parent 47b77763cb
commit 764d00c249
2 changed files with 30 additions and 6 deletions
+21 -2
View File
@@ -67,9 +67,10 @@ relspec convert --from json --from-path schema.json \
--to bun --to-path models/ --package models
# Inject computed/scan-only fields that are not present in the database schema
# (extra-fields.json contains the JSON array shown below)
relspec convert --from dbml --from-path schema.dbml \
--to bun --to-path models.go --package models \
--extra-fields '[{"target_table":"projects","name":"ThoughtCount","type":"sql_types.SqlInt64","bun_tag":"thought_count,scanonly","json_tag":"thought_count"}]'
--extra-fields extra-fields.json
```
## Generated Code Examples
@@ -189,11 +190,14 @@ options := &writers.WriterOptions{
#### Extra fields
Use `Metadata["extra_fields"]` (or the CLI `--extra-fields` flag) to inject
Use `Metadata["extra_fields"]` (or the CLI `--extra-fields <path>` flag) to inject
custom fields into generated Bun models without editing generated files. This is
intended for computed columns and scan-only query fields that Bun must scan into
but that are not real database table columns.
The CLI flag expects a path to a JSON file, not inline JSON. This avoids shell
quoting problems with struct tags and complex type names.
Each entry supports:
| Field | Required | Description |
@@ -224,6 +228,21 @@ options := &writers.WriterOptions{
}
```
Example `extra-fields.json`:
```json
[
{
"target_table": "projects",
"name": "ThoughtCount",
"type": "sql_types.SqlInt64",
"bun_tag": "thought_count,scanonly",
"json_tag": "thought_count",
"comment": "Computed by ResolveSpec queries"
}
]
```
## Notes
- Model names are derived from table names (singularized, PascalCase)