Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting indexes in the sqlmodel tables automatically #105

Closed
nsheff opened this issue Oct 27, 2023 · 2 comments
Closed

Setting indexes in the sqlmodel tables automatically #105

nsheff opened this issue Oct 27, 2023 · 2 comments
Labels
enhancement New feature or request priority-low
Milestone

Comments

@nsheff
Copy link
Contributor

nsheff commented Oct 27, 2023

In databio/bbconf#19 I raised a point about how we were selecting based on a non-identifier column, and how this therefore needed an index.

I had to manually add the index in the postgres server, which isn't ideal... it would be better if any necessary indexes could be specified in the json schema.

I'd recommend adding an index: true parameter option, and then when we read the schema, automatically setting the indexes on those columns.

@nsheff nsheff added enhancement New feature or request priority-low labels Oct 27, 2023
@nsheff nsheff modified the milestone: v0.7.0 Oct 27, 2023
@donaldcampbelljr
Copy link
Contributor

Currently, id is the primary key:

 Field(default=None, primary_key=True),

For indexing other definitions, I believe the syntax is:

 Field(default=None, index=True)

So parsed_schema should be able to add this if it is detected in the output schema. Should happen here:

def _make_field_definitions(self, data: Dict[str, Any], require_type: bool):
# TODO: default to string if no type key?
# TODO: parse "required" ?
defs = {}
for name, subdata in data.items():
try:
typename = subdata[SCHEMA_TYPE_KEY]
except KeyError:
if require_type:
_LOGGER.error(f"'{SCHEMA_TYPE_KEY}' is required for each schema element")
raise
else:
data_type = str
else:
data_type = self._get_data_type(typename)
if data_type == CLASSES_BY_TYPE["object"] or data_type == CLASSES_BY_TYPE["array"]:
defs[name] = (
data_type,
Field(sa_column=Column(JSONB), default=null()),
)
else:
defs[name] = (
# Optional[subdata[SCHEMA_TYPE_KEY]],
# subdata[SCHEMA_TYPE_KEY],
# Optional[str],
# CLASSES_BY_TYPE[subdata[SCHEMA_TYPE_KEY]],
data_type,
Field(default=subdata.get("default")),
)
return defs

@donaldcampbelljr
Copy link
Contributor

This functionality was added in v0.8.0. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority-low
Projects
None yet
Development

No branches or pull requests

2 participants