-
Notifications
You must be signed in to change notification settings - Fork 149
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
Sql metadata converter #862
Conversation
@ezwelty |
Also, I think we can have similar converter for CKAN using https://github.com/frictionlessdata/frictionless-ckan-mapper |
@ezwelty |
@roll Glad you like it. But I wonder if I should also extract a new method Playing around, I notice that:
And I believe the column type conversions would be improved by:
Should I start (a) separate issue for these, and (b) address them in separate pull requests or in this current pull request? |
@ezwelty Feel free to fix it in the PR or create an issue; any would be helpful 👍 |
I'm partially available this and next week so I'm cc @alexkreidler if he has ideas on this one (it will require some diving in) |
- Use CHAR(n) when minLength and maxLength are equal. - Otherwise, use VARCHAR(n) if maxLength is present. - Add LENGTH checks when needed: - For minLength and maxLength in SQLite, which does not enforce by default. - For minLength when not equal to maxLength.
@roll Swinging back around to this old pull request.
I think a fix might look like this:
Thoughts? from .plugins.sql import SqlConverter
# ...
def to_sql_metadata(self, *, sadialect=None, dialect=None):
"""Convert package to SQLAlchemy MetaData
Parameters:
sadialect (any): SQLAlchemy dialect.
For example, `sqlalchemy.dialects.postgresql.dialect()`.
See https://docs.sqlalchemy.org/en/latest/dialects.
dialect (dict): SQL dialect. The following attributes are relevant:
- namespace (str): SQL schema name for all tables.
See https://docs.sqlalchemy.org/en/latest/core/metadata.html#specifying-the-schema-name.
- prefix (str): prefix for all table names
Returns:
sqlalchemy.MetaData
"""
converter = SqlConverter(sadialect=sadialect, dialect=dialect)
return converter.package_to_sql_metadata(self) |
Hi @ezwelty! Since the PR had been introduced we add a new concept called Manager (i.e. CkanManager/GithubManager/etc) which has to highly simplify the code of the old legacy Storage API (to replace the Storage API). If this work is not urgent I would suggest us to wait the migration from SqlStorage to SqlManager (we will be on soon) and I guess it will resolve this issue too because it will be way easier to re-use the needed code. WDYT? |
@roll I think that sounds great and I'm fine with waiting until the migration to Manager is completed. |
Hi @ezwelty, I'm releasing |
@roll I agree that this looks much cleaner. A few comments on the API:
import sqlalchemy as sa
dialect: str = 'postgresql'
dialect_obj = sa.dialects.registry.load(dialect)
|
Thanks @ezwelty! I'll be incorporating your feedback soon. Also, sorry I missed the bug fixes from this PR, I'll transfer them too |
I've created a new issue for further work - #1365 |
Thanks a lot @ezwelty, I'm releasing Although I changed every other mapping after your suggestions, I kept |
I extracted the existing
frictionless
<>sqlalchemy
metadata conversion ofplugins.sql.SqlStorage
(which requires a database connection) into a public API which does not require a database connection. All tests pass, including those for postgresql and mysql.This draft creates a new
SqlConverter
class which requires as optional inputs asqlalchemy.Dialect
and aplugins.sql.SqlDialect
. Example usage below:Please preserve this line to notify @roll (lead of this repository)