codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.52k stars 337 forks source link

Return only column name to client (SDK) #988

Open 0ctanium opened 2 years ago

0ctanium commented 2 years ago

What would you like to be added or enhanced When querying ImmuDB, it return the full column path ( "([database].[table].[column])" ) instead of the column name ( "[column]" ). It would be useful, when returning response to transform column path, used for internal processing just the column name to allow end user to process the data correctly.

Ex: query response in pgsql cli image

Why is this needed When using some packages, in order to parse raw row data into clear objects, the driver need to get column names. For example, when scanning a response using database/sql with sqlx in go. The package will look for the column name. But it wont be able to find anything because it can't parse the full column path. So sqlx returns an error saying it can't find the column name "missing destination name (dbinstance.transactions.transaction_id) in *model.Transaction"

Additional context We started discussing this issue on discord. So if you want te read beginning of that conversation, here is the link: https://discord.com/channels/831257098368319569/831258571664130068/905107567313842246

0ctanium commented 2 years ago

To implement this feature the easiest way is to transform the full column path into its name just before sending the response to client. We also need to take in account the case where two columns have ambigus names. We should throw an error. And then advise the user to use aliases. (like the default behavior of pgsql)

But when returning columns to the end user, we can allow two columns with the same name (like the default behavior of pgsql). And use aliases to differentiate them