Skip to content

Support type overrides in addition to column overrides#8

Merged
MerlinVeritas merged 3 commits intomainfrom
feature/type-overrides
Feb 24, 2026
Merged

Support type overrides in addition to column overrides#8
MerlinVeritas merged 3 commits intomainfrom
feature/type-overrides

Conversation

@MerlinVeritas
Copy link
Collaborator

tableName := col.Table.Name
if col.Table.Schema != "" && col.Table.Schema != req.Catalog.DefaultSchema {
tableName = col.Table.Schema + "." + tableName
if len(conf.Overrides) > 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core change starts here. append ?w=1 to the URL for easier review


This will:
1. Override the column `payload` in `some_table` to use the type `Payload`
2. Override any column with the database type `jsonb` to use the type `Payload`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allenap lmk if this is what you want

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is cool.

Later on I also want to eliminate the use of Any, e.g. default to object instead. Having overrides means folks can choose a better type (or choose Any 🤦).

@MerlinVeritas MerlinVeritas merged commit dba6e76 into main Feb 24, 2026
5 checks passed
@MerlinVeritas MerlinVeritas deleted the feature/type-overrides branch February 24, 2026 20:30
overrides:
- column: "books.payload"
py_import: "my_lib.models"
py_type: "BookPayload"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does BookPayload need to be a pydantic model too? Or, how does deserialization/serialization happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on whether emit_pydantic_models is true I guess? Would need to test

dec.DisallowUnknownFields()
if err := dec.Decode(&conf); err != nil {
msg := strings.TrimPrefix(err.Error(), "json: ")
return Config{}, fmt.Errorf("invalid plugin options: %s", msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a Go question: why return Config{} here instead of nothing? A caller could accidentally use an empty configuration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the function returns Config instead of *Config, we can't return nil here. It's quite idiomatic to do it this way, as the caller is expected to always check err before continuing.


// Look for a matching override
// Then look for a matching db_type override
columnType := strings.ToLower(sdk.DataType(col.Type))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need ToLower since it's being compared with EqualFold later on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, now that you point out.


This will:
1. Override the column `payload` in `some_table` to use the type `Payload`
2. Override any column with the database type `jsonb` to use the type `Payload`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is cool.

Later on I also want to eliminate the use of Any, e.g. default to object instead. Having overrides means folks can choose a better type (or choose Any 🤦).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants