turicas / rows

A common, beautiful interface to tabular data, no matter the format
GNU Lesser General Public License v3.0
869 stars 134 forks source link

Create option to pass custom fields #328

Open turicas opened 5 years ago

turicas commented 5 years ago

Sometimes the use of CLI is not possible since we need to use custom fields. It'd awesome to have a way to define custom Field classes and pass the related Python file with the definitions to the CLI so it'll use it when importing/exporting data.

The use case could be something like:

class BrazilianDecimalField(rows.fields.DecimalField): name = "brazilian-decimal"

@classmethod
def deserialize(cls, value):
    return super().deserialize(value.replace(".", "").replace(",", "."))

- I create a file `my-file.csv` with some data, including numbers formatted in Brazilian;
- I create a file `my-schema.csv` using `brazilian-decimal` as `field_type` for a column;
- I run `rows pgimport --fields-context=custom_fields my-file.csv $POSTGRESQL_URI my_table`.