Consider the following code:
func TestUsqlPostgresOptionsFail(t *testing.T) {
db, _ := sql.Open("postgres", "postgres://martin:<pass>@localhost:5432/northwind")
reader := postgres.NewReader()(db,infos.WithDataTypeFormatter(dataTypeFormatter)).(metadata.BasicReader)
tableSet, err := reader.Tables(metadata.Filter{Schema: "public", Catalog: "northwind"})
assert.NoError(t, err)
assert.NotEmpty(t, tableSet)
}
Here I would like to add a custom data type formatter to the postgres metadata reader.
This fails with:
panic: interface conversion: metadata.Reader is *metadata.LoggingReader, not *informationschema.InformationSchema
From reading the offending code:
func NewReader() func(drivers.DB, ...metadata.ReaderOption) metadata.Reader {
return func(db drivers.DB, opts ...metadata.ReaderOption) metadata.Reader {
newIS := infos.New(
infos.WithIndexes(false),
infos.WithCustomClauses(map[infos.ClauseName]string{
infos.ColumnsColumnSize: "COALESCE(character_maximum_length, numeric_precision, datetime_precision, interval_precision, 0)",
infos.FunctionColumnsColumnSize: "COALESCE(character_maximum_length, numeric_precision, datetime_precision, interval_precision, 0)",
}),
infos.WithSystemSchemas([]string{"pg_catalog", "pg_toast", "information_schema"}),
infos.WithCurrentSchema("CURRENT_SCHEMA"),
infos.WithDataTypeFormatter(dataTypeFormatter))
return metadata.NewPluginReader(
newIS(db, opts...),
&metaReader{
LoggingReader: metadata.NewLoggingReader(db, opts...),
},
)
}
}
it is clear that the opts... are assigned twice. Last time to an incompatible reader (LoggingReader).
Maybe also consider putting
in uppercase to facilitate extension.
Consider the following code:
Here I would like to add a custom data type formatter to the postgres metadata reader.
This fails with:
panic: interface conversion: metadata.Reader is *metadata.LoggingReader, not *informationschema.InformationSchemaFrom reading the offending code:
it is clear that the
opts...are assigned twice. Last time to an incompatible reader (LoggingReader).Maybe also consider putting
in uppercase to facilitate extension.